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 


Persisting variables?

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

Joined: 06 Jan 2023
Posts: 8

PostPosted: Fri Jan 06, 2023 12:49 pm    Post subject: Persisting variables? Reply with quote

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
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 140

Joined: 06 Jul 2014
Posts: 4293

PostPosted: Fri Jan 06, 2023 1:08 pm    Post subject: Reply with quote

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
View user's profile Send private message
GoatSmegma
How do I cheat?
Reputation: 0

Joined: 06 Jan 2023
Posts: 8

PostPosted: Fri Jan 06, 2023 1:37 pm    Post subject: Reply with quote

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
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 140

Joined: 06 Jul 2014
Posts: 4293

PostPosted: Fri Jan 06, 2023 3:29 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine 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