|
Cheat Engine The Official Site of Cheat Engine
|
View previous topic :: View next topic |
Author |
Message |
bknight2602 Grandmaster Cheater Reputation: 0
Joined: 08 Oct 2012 Posts: 577
|
Posted: Sat Apr 04, 2015 1:11 pm Post subject: Unexpected behavior of LUA (maybe) |
|
|
OK, I'm doing a recalculation of addresses on a new table/game and ran into two problems. I'm attempting to EXCLUDE the "Gold" address as the game puts the data very near the start of memory and at this time doesn't seem to change.
THIS DID NOT WORK, AS THE GOLD ADDRESS WAS UPDATED.
Code: |
for j=0, addresslist_getCount(AL)-1 do
print("Record number " .. j + 1 .." has a description of " .. memoryrecord_getDescription(addresslist_getMemoryRecordByID(AL, j)))
if memoryrecord_getDescription(addresslist_getMemoryRecordByID(AL, j)) ~= "Gold" then
local mr = addresslist_getMemoryRecord(AL, j)
local newAddress = memoryrecord_getAddress(mr) + correction
memoryrecord_setAddress(mr,string.format('%x', newAddress))
end--if addresslist_getMemoryRecordByDescription(AL, j) ~= "Gold" then
end -- loop 'for j' end |
THIS WORKS, AS THE GOLD ADDRESS WAS NOT CHANGED.
Code: |
for j=0, addresslist_getCount(AL)-1 do
memrec1 = addresslist_getMemoryRecordByID(AL, j)
memrec2 = memoryrecord_getDescription(memrec1)
print("Record number " .. j + 1 .." has a description of " .. memrec2)
if memrec2 ~= "Gold" then
local mr = addresslist_getMemoryRecord(AL, j)
local newAddress = memoryrecord_getAddress(mr) + correction
memoryrecord_setAddress(mr,string.format('%x', newAddress))
end--if memrec2 ~= "Gold" then
end -- loop 'for j' end |
Why the difference in the two?
Secondly the table has some addresses from a previous session, that aren't in the current session and the for loop j never finished as there was a "Access error". I remember an error bypass that DB shoed me long ago, but this dealt with a scan, this seems different.
Is there a onError jump to next step in LUA or CE?
|
|
Back to top |
|
|
Zanzer I post too much Reputation: 126
Joined: 09 Jun 2013 Posts: 3278
|
Posted: Sat Apr 04, 2015 1:31 pm Post subject: |
|
|
Do your memoryrecord_getDescription() or addresslist_getMemoryRecordByID() functions return multiple values?
Error handling: http://www.lua.org/pil/8.4.html
|
|
Back to top |
|
|
mgr.inz.Player I post too much Reputation: 218
Joined: 07 Nov 2008 Posts: 4438 Location: W kraju nad Wisla. UTC+01:00
|
Posted: Sat Apr 04, 2015 1:35 pm Post subject: |
|
|
Quote: | Secondly the table has some addresses from a previous session, that aren't in the current session and the for loop j never finished as there was a "Access error". |
Don't iterate on IDs. Iterate on indexes.
Secondly, try changing your code to something more readable.
Example:
instead of this
Code: | memrec2 = memoryrecord_getDescription(memrec1) |
use this
Code: | memrec2 = memrec1.Description |
_________________
|
|
Back to top |
|
|
bknight2602 Grandmaster Cheater Reputation: 0
Joined: 08 Oct 2012 Posts: 577
|
Posted: Sat Apr 04, 2015 1:58 pm Post subject: |
|
|
mgr.inz.Player wrote: | Quote: | Secondly the table has some addresses from a previous session, that aren't in the current session and the for loop j never finished as there was a "Access error". |
Don't iterate on IDs. Iterate on indexes.
Secondly, try changing your code to something more readable.
Example:
instead of this
Code: | memrec2 = memoryrecord_getDescription(memrec1) |
use this
Code: | memrec2 = memrec1.Description |
|
Old dogs need a lot of time/practice to learn new steps, besides I don't know all of those short cuts let alone all the "old" language and steps.
I'm not understanding the iterate on index, you mean like this?
addresslist_getMemoryRecord(addresslist, index)
Zanzer wrote: | Do your memoryrecord_getDescription() or addresslist_getMemoryRecordByID() functions return multiple values?
Error handling: http://www.lua.org/pil/8.4.html |
No multiple of values up until error message. Thanks for the link, I need to study usage on that one for a bit.
|
|
Back to top |
|
|
mgr.inz.Player I post too much Reputation: 218
Joined: 07 Nov 2008 Posts: 4438 Location: W kraju nad Wisla. UTC+01:00
|
Posted: Sat Apr 04, 2015 2:47 pm Post subject: |
|
|
The first piece can be written like this ("new" language + cleaning + index instead of ID):
Code: | for j=0, AL.getCount()-1 do
local mr = AL[j]
print("Record number " .. j+1 .." has a description of " .. mr.Description)
if mr.Description ~= "Gold" then
mr.Address = string.format('%x', ('0x'..mr.Address) + correction)
end
end |
the second
Code: | for j=0, AL.getCount()-1 do
local mr = AL[j]
local desc = mr.Description
print("Record number " .. j+1 .." has a description of " .. desc)
if desc ~= "Gold" then
mr.Address = string.format('%x', ('0x'..mr.Address) + correction)
end
end |
After cleaning, we see that both are doing the same thing.
EDIT:
ahhh. I forgot that mr.Address returns string and
memoryrecord_getAddress(mr) returns a number
I applied necessary changes.
Because you iterated on IDs.
As an example: there ate memrec with IDs: 0,1,2,3,4,7,8,9
AL.getCount() will give you 8. Using "for x=0, AL.getCount()-1 do" won't reach memrec with ID9
Also, you will get other errors, because there's no memrec with ID=5 and ID=6
_________________
|
|
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
|
|