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 


Sleep without pausing entire form?

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

Joined: 09 Aug 2018
Posts: 5

PostPosted: Wed Jun 19, 2019 9:52 am    Post subject: Sleep without pausing entire form? Reply with quote

I'm trying to make my trainer auto close with a label displaying how long it has left to close, as well as an option to exit before the time is up.

However, when I sleep(1000) 30 times, it waits 30 seconds and closes. But it prevents the user to click the exit button sooner and locks all the controls.

Here's what I have tried so far;
Code:
for loop = 1, 30 do
    sleep(1000)
    label.Caption = 30 - loop
end
Code:
local start, time = getTickCount()
for loop = 1, 30 do
    time = getTickCount() - start
    while time < 1000 do
        time = getTickCount() - start
        sleep(1)
    end
end
Code:
label.Caption = "Closes in 30 seconds."
sleep(30000)


If it's impossible, that's ok.
Back to top
View user's profile Send private message
Lynxz Gaming
Expert Cheater
Reputation: 4

Joined: 01 Jul 2017
Posts: 208
Location: help

PostPosted: Wed Jun 19, 2019 10:08 am    Post subject: Re: Sleep without pausing entire form? Reply with quote

zw443 wrote:
I'm trying to make my trainer auto close with a label displaying how long it has left to close, as well as an option to exit before the time is up.

However, when I sleep(1000) 30 times, it waits 30 seconds and closes. But it prevents the user to click the exit button sooner and locks all the controls.

Here's what I have tried so far;
Code:
for loop = 1, 30 do
    sleep(1000)
    label.Caption = 30 - loop
end
Code:
local start, time = getTickCount()
for loop = 1, 30 do
    time = getTickCount() - start
    while time < 1000 do
        time = getTickCount() - start
        sleep(1)
    end
end
Code:
label.Caption = "Closes in 30 seconds."
sleep(30000)


If it's impossible, that's ok.

try with createNativeThread

Code:
createNativeThread(function()
for loop = 1, 30 do
    sleep(1000)
    label.Caption = 30 - loop
end
end)


Code:
createNativeThread(function()
local start, time = getTickCount()
for loop = 1, 30 do
    time = getTickCount() - start
    while time < 1000 do
        time = getTickCount() - start
        sleep(1)
    end
end
end)


Code:
createNativeThread(function()
label.Caption = "Closes in 30 seconds."
sleep(30000)
end)

_________________
my english is bad
discord : rynx#9828
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
zw443
How do I cheat?
Reputation: 0

Joined: 09 Aug 2018
Posts: 5

PostPosted: Wed Jun 19, 2019 10:14 am    Post subject: Reply with quote

Thank you so much!
This works as I want it to. Very Happy
Back to top
View user's profile Send private message
daspamer
Grandmaster Cheater Supreme
Reputation: 54

Joined: 13 Sep 2011
Posts: 1588

PostPosted: Thu Jun 20, 2019 1:32 pm    Post subject: Reply with quote

Using threads for a simple task is overkill and huge waste of resources, why use a loop when you could just use a simple timer?

Code:
form = createForm();
label = createLabel(form);

-- create timer;
t = createTimer(label);
t.Interval = 100;                         -- 10 times/sec;

local getCaption = function(t) return ('%d seconds until shutdown'):format(t); end;

-- start timestamp, timeout time in seconds
local start,timeout = os.clock(),30;
label.Caption = getCaption(timeout);          -- set starting caption

t.onTimer = function (sender)
   local ts = timeout - (os.clock()-start)//1; -- round down; returns float so we use string.format
   label.Caption = getCaption(ts);            -- update caption;
   if (ts <= 0) then      -- condition met, shut down;
      print('shut down');
      label.destroy();    -- destroying the label will also destroy this timer;
      -- sender.destroy() -- alternative destroy this timer;
      -- closeCE();       -- shut down;
   end
end

_________________
I'm rusty and getting older, help me re-learn lua.
Back to top
View user's profile Send private message Visit poster's website
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