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 


Timer Destroy()... or not quite... [Closed]

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
paul44
Expert Cheater
Reputation: 2

Joined: 20 Jul 2017
Posts: 152

PostPosted: Tue Mar 23, 2021 1:11 pm    Post subject: Timer Destroy()... or not quite... [Closed] Reply with quote

I'm currently running a timer (every 3s), which does some householding and kicks in other scripts if needed.
One of those scripts actually starts another timer; to manage a freeroam feature in the game.
My problem: when one ends 'FreeRoam', that particular timer does not seem to get destroyed?!

Some info here: [ https://imgur.com/a/BG7GAQE ]
The first image shows what kicks in when the user activates 'Free Roam'
a) upon activation, the feature works fine (prints 'here5' & 'here1')
b) however, upon deactivation 'here3' kicks in... and continues to execute this part of the routine. Re-enabling 'Freeroam' will no longer work from thereon...

I assumed - executing 'tmer.destroy()' that Lua/CE would "ignore" that object thereafter (winds up in garbage collection?), and any request to 'tmer' object would give a 'nil' error... Which happens the 1st time when activating the feature; hence that included test.
It seems though that CE still has access to 'tmer.Enabled'?!

So my question is: any solution/ workaround, or better approach to tackle this

ps: print(tmer) gives me the object_address; so still in memory.
ps2: the script has been changed already 4-5 times to find some form of workaround
ps3: while trying to adjust the script, I get from time to time 'access violation' error. I assume this is because the "main" timer got that script/timer/whatnot locked.
another error I get at some point: duplicate name


Last edited by paul44 on Wed Mar 24, 2021 1:23 pm; edited 1 time in total
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 458

Joined: 09 May 2003
Posts: 25296
Location: The netherlands

PostPosted: Tue Mar 23, 2021 4:01 pm    Post subject: Reply with quote

Code:

tmer.destroy()
tmer.enabled=false


You try to access the enabled property of a destroyed object. That's not going to work as the memory may have been overwritten already

when you destroy an object you should set it to nil to make sure you don't access invalid memory
e.g:
Code:

tmer.destroy()
tmer=nil


and then everywhere that accesses tmer check if tmer is nil and if so, skip that code, or recreate it if you feel like it

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
paul44
Expert Cheater
Reputation: 2

Joined: 20 Jul 2017
Posts: 152

PostPosted: Wed Mar 24, 2021 3:12 am    Post subject: my logic... Reply with quote

it is so logic, I should have come up with that solution myself... which is why I never consider myself a programmer.
anyways: I'll do the proper checking this evening, and close topic accordingly...

thx
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