|
Cheat Engine The Official Site of Cheat Engine
|
View previous topic :: View next topic |
Author |
Message |
GoatSmegma How do I cheat? Reputation: 0
Joined: 06 Jan 2023 Posts: 8
|
Posted: Fri Jan 06, 2023 12:49 pm Post subject: Persisting variables? |
|
|
Sup gamers,
I was trying to make some fancy noclip fly around thing, Ive done it multiple times before, but this time I wanted it to be extra fancy, so I used LUA, I had some sphaghetti here and there but managed to get it working, it was pretty late, then it started jittering back and forth, I just saved everything and closed it all, next day the script threw an error, pointing to this spectacle:
Code: | newPos = yPos + posOffset
yPos = readFloat(yPointer) |
I never declared yPos, but it gets used, it worked like this the day before, my only theory is that I had yPos at one point properly declared before use, but when I did some de spaghetti it then most likely slipped down like this, but CheatEngine had yPos still "correctly" loaded somewhere in its memory or so.
Now my questions: why's that? Is there something similar I should watch out for?
|
|
Back to top |
|
|
ParkourPenguin I post too much Reputation: 140
Joined: 06 Jul 2014 Posts: 4293
|
Posted: Fri Jan 06, 2023 1:08 pm Post subject: |
|
|
They're called global variables. Generally speaking, they're considered bad practice for this reason. It makes code hard to understand and therefore hard to develop, debug, maintain, etc.
(obviously they have their uses, but local variables should be used most often)
_________________
I don't know where I'm going, but I'll figure it out when I get there. |
|
Back to top |
|
|
GoatSmegma How do I cheat? Reputation: 0
Joined: 06 Jan 2023 Posts: 8
|
Posted: Fri Jan 06, 2023 1:37 pm Post subject: |
|
|
whoops LUA.. I forgot that I had to add "local" infront of it, but still, do global variables act like this? like declare global variable, stuff an value into it, change the code so it will use said variable before even declaring it and it will still just "work"? remarkebly in one way..
|
|
Back to top |
|
|
ParkourPenguin I post too much Reputation: 140
Joined: 06 Jul 2014 Posts: 4293
|
Posted: Fri Jan 06, 2023 3:29 pm Post subject: |
|
|
Executing any Lua code won't destroy the Lua state. Globals will persist.
_________________
I don't know where I'm going, but I'll figure it out when I get there. |
|
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
|
|