View previous topic :: View next topic |
Author |
Message |
User100 Newbie cheater Reputation: 0
Joined: 10 Nov 2018 Posts: 14
|
Posted: Thu Jan 20, 2022 6:42 am Post subject: Updating the GUI during tight loops |
|
|
How can I update my GUI elements while I'm running some demanding stuff?
I tried sleeps, threads, but the GUI is only updated once everything is over.
e.g. something like this here, where the only output I see is the "end2":
Code: | CETrainer_CELabel1.Caption = "start1"
local thread = createThread(function(timer)
for i=1,100 do
if i%10==0 then CETrainer_CELabel1.Caption = i end
Sleep(100)
end
end)
CETrainer_CELabel1.Caption = "end1"
Sleep(500)
CETrainer_CELabel1.Caption = "start2"
for i=1,100 do
if i%10==0 then CETrainer_CELabel1.Caption = i end
Sleep(100)
end
CETrainer_CELabel1.Caption = "end2" |
|
|
Back to top |
|
|
Dark Byte Site Admin Reputation: 457
Joined: 09 May 2003 Posts: 25262 Location: The netherlands
|
Posted: Thu Jan 20, 2022 6:47 am Post subject: |
|
|
get rid of that Sleep(500), it runs in the gui thread
use a timer instead
_________________
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 |
|
|
User100 Newbie cheater Reputation: 0
Joined: 10 Nov 2018 Posts: 14
|
Posted: Thu Jan 20, 2022 6:54 am Post subject: |
|
|
Even without the middle Sleep, I don't get any GUI output.
I originally started with just one of those blocks, and later added the threaded alternative, but no matter what, the GUI is never updated (until it's all over).
Also, the sleeps in the example are just to have a simple demo code.
In my real code I'm doing a few dozen memory scans, and I would like to update the GUI in-between, but am having the same issue, that the GUI is never updated until the code's done.
|
|
Back to top |
|
|
Dark Byte Site Admin Reputation: 457
Joined: 09 May 2003 Posts: 25262 Location: The netherlands
|
Posted: Thu Jan 20, 2022 6:58 am Post subject: |
|
|
Code: |
if f then f.destroy() f=nil end
f=createForm()
l1=createLabel(f)
l2=createLabel(f)
l1.Caption='status1';
l2.Caption='status2';
l1.Top=0
l2.Top=l1.Height
createThread(function()
local i
for i=1,10 do
synchronize(function()
l1.Caption='status1='..i
end)
sleep(100+math.random(1000))
end
end)
createThread(function()
local j
for j=1,100 do
synchronize(function()
l2.Caption='status2='..j
end)
sleep(10+math.random(10))
end
end)
|
or write the status to variables and use a timer to update the GUI
Code: |
if f then f.destroy() f=nil end
f=createForm()
l1=createLabel(f)
l2=createLabel(f)
l1.Caption='status1';
l2.Caption='status2';
l1.Top=0
l2.Top=l1.Height
status1='not started yet'
status2=status1
createThread(function()
local i
for i=1,10 do
status1='1='..i
sleep(100+math.random(1000))
end
status1='done 1'
end)
createThread(function()
local j
for j=1,100 do
status2='2='..j
sleep(10+math.random(10))
end
status2='done 2'
end)
st=createTimer()
st.Interval=32
st.OnTimer=function()
l1.Caption='status1='..status1
l2.Caption='status2='..status2
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 |
|
|
User100 Newbie cheater Reputation: 0
Joined: 10 Nov 2018 Posts: 14
|
Posted: Thu Jan 20, 2022 7:47 am Post subject: |
|
|
Thanks for the in-depth help!
I tried the timer method, and that did the job!
Much appreciated!
|
|
Back to top |
|
|
|