| View previous topic :: View next topic |
| Author |
Message |
Autem Expert Cheater
Reputation: 1
Joined: 30 Jan 2023 Posts: 155
|
Posted: Sun Oct 29, 2023 8:29 pm Post subject: Can't get timers to pause/stop when desired. Please help. |
|
|
I've been trying many different variations and nothing works to make these timers take a break when they don't need to keep running. For example the bottom timer (t3) should stop once rrMusic value is over 1000 but it doesn't stop. I've tried...
t3.Enabled=false but it does nothing
destroying the timer and it does nothing
setting t3 to a longer interval and that also does nothing Then later in the script I'd obviously want to re-enable them when I'm ready for them.
Similarly, the same problem is happening with the timer named t. It keeps printing the test print repeatedly even though it should print it once and then stop until the next time that conditional is met for rrMusic (which should not have been for a while because that earlier timer was supposed to have been taking a break by that stage in the script)
What am I doing wrong? I thought Enabled=true/false literally was to toggle the timers on/off?
| Code: | [ENABLE]
{$lua}
if syntaxcheck then return end
function Music()
if tonumber(getAddressList().getMemoryRecordByDescription('rrMusic').Value)>1000 then
t3.Enabled=false --TRYING to somehow stop/pause t3 here, but it never stops
local t=createTimer()
t.Interval=1000
t.OnTimer=function()
print("test print")
writeBytes('sportk2_x64.exe+38929B8', 0)
t.destroy() --TRYING to stop t from performing more than once but it never stops
local t2=createTimer()
t2.Interval=6000
t2.OnTimer=function()
writeBytes('sportk2_x64.exe+38929B8', originalVal)
t2.destroy()
end
end
t3.Interval=1000
end
end
originalVal=readBytes('sportk2_x64.exe+38929B8')
t3=createTimer()
t3.OnTimer=Music
t3.Interval=1000 --every second I want to check if rrMusic's value is over 1000
[DISABLE]
{$lua}
t3.destroy() |
|
|
| Back to top |
|
 |
Famine Cheater
Reputation: 0
Joined: 23 Oct 2023 Posts: 27 Location: A club where people wee on each other.
|
Posted: Sun Oct 29, 2023 9:08 pm Post subject: |
|
|
Here is a corrected version of your script:
| Code: | [ENABLE]
{$lua}
if syntaxcheck then return end
local t -- Declare t outside of the function
function Music()
if tonumber(getAddressList().getMemoryRecordByDescription('rrMusic').Value) > 1000 then
if t then
t.destroy() -- Destroy the existing timer if it exists
end
t = createTimer()
t.Interval = 1000
t.OnTimer = function()
print("test print")
writeBytes('sportk2_x64.exe+38929B8', 0)
t.destroy() -- Destroy the timer after running once
end
end
end
local originalVal = readBytes('sportk2_x64.exe+38929B8')
local t3 = createTimer()
t3.OnTimer = Music
t3.Interval = 1000 -- Every second, check if rrMusic's value is over 1000
[DISABLE]
{$lua}
if t then
t.destroy() -- Destroy the timer when disabling the script
end
t3.destroy()
|
In this corrected script:
t is declared as a local variable outside the Music function so that you can access it in the DISABLE block as well. When Music is called, it first checks if t exists and destroys it if it does before creating a new timer.
In the DISABLE block, it checks if t exists and destroys it to prevent any lingering timers when the script is disabled.
With these changes, the timers should work as intended, and the t3 timer will check the value of rrMusic every second, creating and destroying t as needed based on the condition.
_________________
| LeFiXER wrote: | You probably should read the replies to make sure someone else hasn't already mentioned what you are about to say. It gives the impression that you are ignorant of other members in this community.
|
|
|
| Back to top |
|
 |
Dark Byte Site Admin
Reputation: 471
Joined: 09 May 2003 Posts: 25819 Location: The netherlands
|
Posted: Mon Oct 30, 2023 12:29 am Post subject: |
|
|
the disable block is a separate script so won't have access to the local variables of the enable block
Try restarting CE, perhaps you have a timer from a previous attempt still setting t, t2 and t3 overriding the new timers so when they run the wring timer gets disabled
_________________
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 |
|
 |
Autem Expert Cheater
Reputation: 1
Joined: 30 Jan 2023 Posts: 155
|
Posted: Mon Oct 30, 2023 2:53 am Post subject: |
|
|
I'm starting to wonder if somehow my version of CE isn't running LUA correctly. It's literally not destroying timers no matter what. Even when written how you write them in your corrected example and making sure they're local, etc...
I also restarted CE and my entire computer.
Once I have run my script one time, then I go into the LUA window and paste this code and am getting the printed warnings (start2, etc) showing up no matter how many times I execute them, so I guess the timers aren't going away:
| Code: | if tx2 then
print("start2")
tx2.destroy() -- Destroy the existing timer if it exists
end
if tx then
print("start3")
tx.destroy() -- Destroy the existing timer if it exists
end
if tw then
print("start4")
tw.destroy() -- Destroy the existing timer if it exists
end
if t3 then
print("start5")
t3.destroy() -- Destroy the existing timer if it exists
end |
I'm on CE 7.5 so I think everything should be working fine. I'm not sure if I'm somehow missing something but it seems like CE's ability to destroy timers is failing at all times for me.
|
|
| Back to top |
|
 |
Dark Byte Site Admin
Reputation: 471
Joined: 09 May 2003 Posts: 25819 Location: The netherlands
|
Posted: Mon Oct 30, 2023 8:33 am Post subject: |
|
|
when testing don't forget to nil the variable after destroy() else it keeps it's pointer
_________________
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 |
|
 |
|