 |
Cheat Engine The Official Site of Cheat Engine
|
View previous topic :: View next topic |
Author |
Message |
Keule Cheater
Reputation: 0
Joined: 08 Aug 2012 Posts: 25
|
Posted: Mon Feb 10, 2014 2:42 am Post subject: Is there a Way to shorten this Code? :/ |
|
|
Hello Community, i want to keep this Code very short, maybe via a Loop, but i dont know how to apply it 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.
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 |
|
 |
AltairPL Newbie cheater
Reputation: 2
Joined: 25 Jan 2014 Posts: 24
|
Posted: Mon Feb 10, 2014 3:16 am Post subject: |
|
|
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 |
|
 |
Keule Cheater
Reputation: 0
Joined: 08 Aug 2012 Posts: 25
|
Posted: Mon Feb 10, 2014 3:58 am Post subject: |
|
|
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 |
|
 |
AltairPL Newbie cheater
Reputation: 2
Joined: 25 Jan 2014 Posts: 24
|
Posted: Mon Feb 10, 2014 4:25 am Post subject: |
|
|
I tested this and it works for me
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
change writeInteger line to:
Code: | writeInteger('mod_carid', tonumber(CarID,16)) |
and it should work as intended
|
|
Back to top |
|
 |
Keule Cheater
Reputation: 0
Joined: 08 Aug 2012 Posts: 25
|
Posted: Wed Feb 12, 2014 7:49 am Post subject: |
|
|
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
|
|
Back to top |
|
 |
|
|
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
|
|