View previous topic :: View next topic |
Author |
Message |
paul44 Expert Cheater Reputation: 2
Joined: 20 Jul 2017 Posts: 152
|
Posted: Tue Mar 23, 2021 1:11 pm Post subject: Timer Destroy()... or not quite... [Closed] |
|
|
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 |
|
|
Dark Byte Site Admin Reputation: 458
Joined: 09 May 2003 Posts: 25296 Location: The netherlands
|
Posted: Tue Mar 23, 2021 4:01 pm Post subject: |
|
|
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 |
|
|
paul44 Expert Cheater Reputation: 2
Joined: 20 Jul 2017 Posts: 152
|
Posted: Wed Mar 24, 2021 3:12 am Post subject: my logic... |
|
|
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 |
|
|
|