 |
Cheat Engine The Official Site of Cheat Engine
|
| View previous topic :: View next topic |
| Author |
Message |
mrally2 Cheater
Reputation: 0
Joined: 01 Apr 2020 Posts: 43
|
Posted: Tue Sep 01, 2020 12:06 pm Post subject: Alternative to Sleep() |
|
|
I have 2 or more functions constantly running controlled by a timer that have inside a pointer that points to the same location at a certain moment and its value has to be changed randomly. To avoid conflicts such as function1 changing to a random value and function2 changing right after that value I used sleep() which seems like a workaround but it stops the main thread for x seconds and therefore CE which is a complete mess if I want to access it at that time.
I’ll leave a code snippet to ilustrate better what I pretend to achieve:
| Code: |
--ptr1,ptr2,ptr3 point to the same location depending on the event
function1()
math.randomseed(os.time())
ptr1 = readPointer(...)
if readInteger(ptr1) == 1 then
res1 = math.random(1,3)
writeInteger(ptr1,res1)
end
end
function2()
math.randomseed(os.time())
ptr2 = readPointer(...)
if readInteger(ptr2) == 2 then
res2 = math.random(1,3)
--I need to put here a delay of 5 sec so it delays the change of the value obtained at function1
writeInteger(ptr2,res2)
end
end
function3()
math.randomseed(os.time())
ptr3 = readPointer(...)
if readInteger(ptr3) == 3 then
res3 = math.random(1,3)
--I need to put here a delay of 5 sec so it delays the change of the value obtained at function1
writeInteger(ptr3,res3)
end
end
t1 = createTimer(nil)
timer_onTimer(t1,function1)
timer_setInterval(t1, 2000)
timer_setEnabled(t1, true)
t2 = createTimer(nil)
timer_onTimer(t2,function2)
timer_setInterval(t2, 2010)
timer_setEnabled(t2, true)
t3 = createTimer(nil)
timer_onTimer(t3,function3)
timer_setInterval(t3, 2020)
timer_setEnabled(t3, true)
|
|
|
| Back to top |
|
 |
Dark Byte Site Admin
Reputation: 472
Joined: 09 May 2003 Posts: 25867 Location: The netherlands
|
Posted: Tue Sep 01, 2020 12:57 pm Post subject: |
|
|
you can also disable the other timer and spawn a one-time-run timer that reactivates the disabled one
_________________
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 |
|
 |
mrally2 Cheater
Reputation: 0
Joined: 01 Apr 2020 Posts: 43
|
Posted: Wed Sep 02, 2020 3:29 am Post subject: |
|
|
| Dark Byte wrote: | | you can also disable the other timer and spawn a one-time-run timer that reactivates the disabled one |
By one-time-run timer what do you mean exactly? I didn’t find a pre-made function for lua. I did this to recreate it instead:
| Code: |
-- function2 and function3 remain the same, no changes
function1()
math.randomseed(os.time())
ptr1 = readPointer(...)
if readInteger(ptr1) == 1 then
res1 = math.random(1,3)
timer_setEnabled(t2,false)
timer_setEnabled(t3,false)
local cont = 0
local function onetime()
if cont > 0 then
timer_setEnable(t2,true)
timer_setEnable(t3,true)
timer_setEnable(t,false)
else
cont = cont + 1
end
end
t = createTimer(nil)
timer_onTimer(t,onetime)
timer_setInterval(t, 5000)
timer_setEnabled(t, true)
writeInteger(ptr1,res1)
end
end
|
|
|
| Back to top |
|
 |
Dark Byte Site Admin
Reputation: 472
Joined: 09 May 2003 Posts: 25867 Location: The netherlands
|
Posted: Wed Sep 02, 2020 3:45 am Post subject: |
|
|
ce 7.1:
| Code: |
createTimer(delay, function(...),...):
Creates a timer object that waits the given delay, executes the given function, and then selfdestructs. Tip: Don't use the timer after it has ran
|
so something like:
| Code: |
t2.Enabled=false
t3.Enabled=false
createTimer(5000, function()
t2.Enabled=true
t3.Enabled=true
end)
|
_________________
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 |
|
 |
|
|
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
|
|