Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Is there a Way to shorten this Code? :/

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
Keule
Cheater
Reputation: 0

Joined: 08 Aug 2012
Posts: 25

PostPosted: Mon Feb 10, 2014 2:42 am    Post subject: Is there a Way to shorten this Code? :/ Reply with quote


Hello Community, i want to keep this Code very short, maybe via a Loop, but i dont know how to apply it Sad Please help me...

This is the Example Script:

Code:

if UDF1.boxCarID.ItemIndex = 0 then
writeInteger('mod_carid', 0x0D7A6A98) -- value of CarIDs Tableentry #1
end

if UDF1.boxCarID.ItemIndex = 1 then
writeInteger('mod_carid', 0x2C0BFCF6) -- value of CarIDs Tableentry #2
end

if UDF1.boxCarID.ItemIndex = 2 then
writeInteger('mod_carid', 0x5FBFC531) -- value of CarIDs Tableentry #3
end

CarIDs ={'0D7A6A98','2C0BFCF6','5FBFC531'}


I can tell you, that the Strings in the "UDF1.boxCarID" are sorted in alphabetical Order, the Values in Table "CarIDs" are sorted by me for each ItemIndex too. Wink

So basically what i want is, that if the ItemIndex is -1, then write 0 to 'mod_carid', if ItemIndex is 0 then write the first Tableentry to 'mod_carid', if ItemIndex is 2 then write seconds Tableentry to 'mod_carid' ...and so on...

It will extend until 199 ItemIndexes and 199 TableValues, so this is why i need a Method to write this shorter :/
Hopefully you can help me on that, this is a Method i got by DaSpammer, but it doesnt work, it always prints out that CarID is a nil value...

Code:

function boxCarIDChange(sender)
   CarID = CarIDs[UDF1.boxCarID.ItemIndex+1]
   writeInteger('mod_carid', 0x ..CarID)
   end


Cheers, Keule
Back to top
View user's profile Send private message
AltairPL
Newbie cheater
Reputation: 2

Joined: 25 Jan 2014
Posts: 24

PostPosted: Mon Feb 10, 2014 3:16 am    Post subject: Reply with quote

I'm not sure if this is what you need, but try this:
Code:
function boxCarIDChange(sender)
   CarID = CarIDs[UDF1.boxCarID.ItemIndex+1] or 0
   writeInteger('mod_carid', 0x ..CarID)
end
Back to top
View user's profile Send private message
Keule
Cheater
Reputation: 0

Joined: 08 Aug 2012
Posts: 25

PostPosted: Mon Feb 10, 2014 3:58 am    Post subject: Reply with quote

I tried it, now there is no error, but after choosing a Car from the list, the Value is still '0', but it needs to be '0D7A6A98' after changing from ItemIndex = -1 to ItemIndex = 0, so it doesn't set the new Value.
Back to top
View user's profile Send private message
AltairPL
Newbie cheater
Reputation: 2

Joined: 25 Jan 2014
Posts: 24

PostPosted: Mon Feb 10, 2014 4:25 am    Post subject: Reply with quote

I tested this and it works for me Confused
what exactly is 'mod_carid' - is it symbol or variable name containing address?
- if symbol, it should work, so maybe add somewhere this code to see if it's correct:
Code:
print(getAddress('mod_carid'))

- if it's variable name containing address, drop quotes and it should be ok

EDIT: my testing method was flawed - made a shortcut and it kicked me in the butt Wink
change writeInteger line to:
Code:
writeInteger('mod_carid', tonumber(CarID,16))

and it should work as intended
Back to top
View user's profile Send private message
Keule
Cheater
Reputation: 0

Joined: 08 Aug 2012
Posts: 25

PostPosted: Wed Feb 12, 2014 7:49 am    Post subject: Reply with quote

Thats it:

Code:

function boxCarIDChange(sender)
local CarID = CarIDs[UDF1.boxCarID.ItemIndex+1];
if CarID then writeInteger('mod_carid', '0x' ..CarID)
end
end


Thx for helping Smile
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites