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 


How to read offset in custom lua value?

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
ImmortalZypther
How do I cheat?
Reputation: 0

Joined: 28 Dec 2019
Posts: 7

PostPosted: Tue Jan 03, 2023 12:23 pm    Post subject: How to read offset in custom lua value? Reply with quote

I'm trying to read a value from an offset like this "recettear.exe+41109AA" using my custom lua value, but everything seems to throw a lua panic. What's the proper way to do this?
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 138

Joined: 06 Jul 2014
Posts: 4275

PostPosted: Tue Jan 03, 2023 2:06 pm    Post subject: Reply with quote

You aren't explaining yourself well. Post your code.
_________________
I don't know where I'm going, but I'll figure it out when I get there.
Back to top
View user's profile Send private message
ImmortalZypther
How do I cheat?
Reputation: 0

Joined: 28 Dec 2019
Posts: 7

PostPosted: Tue Jan 03, 2023 2:14 pm    Post subject: Reply with quote

The game I'm attached to is "recettear.exe" and I have a value I can read from "recettear.exe+6F0B570", but I can't use "recettear.exe+6F0B570" in my code without it throwing an error:
Code:
patience=readByte(recettear.exe+0x6F0B570 + customer * 4)

The exact error I'm getting in the Lua Engine is "Error:[string "local syntaxcheck,memrec=......"]:7: attempt to index a nil value (global 'recettear')"
I can make it work if I manually find the proper address with the offset.
Code:
patience=readByte(0x045109AA + customer * 4)

But I want it to calculate the proper address with the offset itself. Is there a way I can find the address of "recettear.exe" so I can use it in that readByte function?
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 138

Joined: 06 Jul 2014
Posts: 4275

PostPosted: Tue Jan 03, 2023 2:36 pm    Post subject: Reply with quote

ImmortalZypther wrote:
Code:
readByte(recettear.exe+0x6F0B570 + customer * 4)
Here, `recettear` is treated as a global variable, and `.exe` is an index operation into a table. If you want it to be treated as a string and let CE parse it, enclose it in single or double quotes.

Doing arithmetic on the address requires you to parse it before passing it to readByte. Assuming `customer` is an integer, this should work:
Code:
readByte(getAddress'recettear.exe+0x6F0B570' + customer * 4)
(a single string or table argument used in a function call can omit the outside parenthesis)

If it still doesn't work, maybe you meant to treat `recettear.exe+0x6F0B570` as a pointer and not an array. Replace getAddress with readPointer

_________________
I don't know where I'm going, but I'll figure it out when I get there.
Back to top
View user's profile Send private message
ImmortalZypther
How do I cheat?
Reputation: 0

Joined: 28 Dec 2019
Posts: 7

PostPosted: Tue Jan 03, 2023 2:40 pm    Post subject: Reply with quote

I could've sworn I've tried that because that syntax looks familiar, but I must've gotten something mixed up in the game's memory from not restarting the game in between all my debugging.

Thank you so much for your quick assistance!
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