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 


Updating the GUI during tight loops

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
User100
Newbie cheater
Reputation: 0

Joined: 10 Nov 2018
Posts: 14

PostPosted: Thu Jan 20, 2022 6:42 am    Post subject: Updating the GUI during tight loops Reply with quote

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
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 457

Joined: 09 May 2003
Posts: 25262
Location: The netherlands

PostPosted: Thu Jan 20, 2022 6:47 am    Post subject: Reply with quote

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
View user's profile Send private message MSN Messenger
User100
Newbie cheater
Reputation: 0

Joined: 10 Nov 2018
Posts: 14

PostPosted: Thu Jan 20, 2022 6:54 am    Post subject: Reply with quote

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
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 457

Joined: 09 May 2003
Posts: 25262
Location: The netherlands

PostPosted: Thu Jan 20, 2022 6:58 am    Post subject: Reply with quote

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
View user's profile Send private message MSN Messenger
User100
Newbie cheater
Reputation: 0

Joined: 10 Nov 2018
Posts: 14

PostPosted: Thu Jan 20, 2022 7:47 am    Post subject: Reply with quote

Thanks for the in-depth help!

I tried the timer method, and that did the job!

Much appreciated! Smile
Back to top
View user's profile Send private message
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