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 


large loop - Not responding

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
kucingkembar
Advanced Cheater
Reputation: 0

Joined: 08 Oct 2020
Posts: 71

PostPosted: Sun Apr 10, 2022 4:45 pm    Post subject: large loop - Not responding Reply with quote

hi, sorry for my bad English again

I creating a tile-set map editor,
I have no problem when the map is relatively small like 4x4,
but when I attempt medium or large like 35x35 = 1225 tiles,
the program hangs about 700-800/ 1225 for 3-10 seconds
I tried to add sleep code, but the program run longer and the not responding still happens, any idea?
Code:
k = 0
for i = 0, 35, 1 do
    for j = 0, 35, 1 do
         k = k + 1
         form1.Caption = "Loading " .. k .. " / " .. 35 * 35
         sleep(100)
         --[[
         do creating stuff here
         --]]
    end
end
Back to top
View user's profile Send private message
Csimbi
I post too much
Reputation: 94

Joined: 14 Jul 2007
Posts: 3110

PostPosted: Sun Apr 10, 2022 5:12 pm    Post subject: Reply with quote

The loops look okay.
It must be something in your code deeper down (lots of heavy lifting that take a while?).
You could try running this in a separate thread.
Back to top
View user's profile Send private message
kucingkembar
Advanced Cheater
Reputation: 0

Joined: 08 Oct 2020
Posts: 71

PostPosted: Sun Apr 10, 2022 5:47 pm    Post subject: Reply with quote

Q:It must be something in your code deeper down (lots of heavy lifting that take a while?)
A:this is the code:
Code:
MapTiles = {}
-- main form
if form1 then form1.Destroy() end
form1 = createForm()
form1.setSize(250, 250)
form1.Position = "poScreenCenter"

k = 0
-- 5x5 table
for i = 0 ,4, 1 do
   for j = 0 ,4, 1 do
       k = k + 1
       MapTiles[k] = createImage(form1)
       MapTiles[k].Picture.loadFromStream(findTableFile([[Block_QM.png]]).Stream)
       MapTiles[k].Height = 50
       MapTiles[k].width = 50
       MapTiles[k].top = i * MapTiles[k].Height
       MapTiles[k].left = j * MapTiles[k].width
       MapTiles[k].stretch = true
       MapTiles[k].ShowHint = true
       MapTiles[k].Hint = i + 1 .. ":" .. j + 1
   end
end
form1.Caption = k .. " tiles"


Q:You could try running this in a separate thread.
A:how?
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 458

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

PostPosted: Sun Apr 10, 2022 10:25 pm    Post subject: Reply with quote

add processMessages() in the loop.


also, instead of multiple images on the form i recommend a single image that only updates when an image changes (and only that one spot

that way you can use createPicture instead of createImage so you can use threads

_________________
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
kucingkembar
Advanced Cheater
Reputation: 0

Joined: 08 Oct 2020
Posts: 71

PostPosted: Mon Apr 11, 2022 1:34 am    Post subject: Reply with quote

thank you Dark Byte for the reply,
the processMessages() work flawlessly,
but about createPicture() I still don't get it,
it seems createPicture() do not have width property : attempt to perform arithmetic on a nil value (field 'width')
Back to top
View user's profile Send private message
AylinCE
Grandmaster Cheater Supreme
Reputation: 32

Joined: 16 Feb 2017
Posts: 1253

PostPosted: Mon Apr 11, 2022 2:36 pm    Post subject: Reply with quote

An example;

Code:
MapTiles = {}
-- main form
if form1 then form1.Destroy() end
form1 = createForm()
form1.setSize(250, 250)
form1.Position = "poScreenCenter"

function crtPic(url)
int = getInternet()
local logostr=int.getURL(url)
int.destroy ()
local ss=createStringStream(logostr)
i3=createPicture()
i3.loadFromStream(ss)
ss.destroy()
return i3
end

pic1=crtPic("https://i.ibb.co/ZYqHBBF/ce-logo-770.png")

k = 0
-- 5x5 table
for i = 0 ,4, 1 do
   for j = 0 ,4, 1 do
       k = k + 1
       MapTiles[k] = createImage(form1)
       MapTiles[k].Picture=pic1 --.loadFromStream(findTableFile([[Block_QM.png]]).Stream)
       MapTiles[k].Height = 50
       MapTiles[k].width = 50
       MapTiles[k].top = i * MapTiles[k].Height
       MapTiles[k].left = j * MapTiles[k].width
       MapTiles[k].stretch = true
       MapTiles[k].ShowHint = true
       MapTiles[k].Hint = i + 1 .. ":" .. j + 1
   end
end
form1.Caption = k .. " tiles"


in your case
An example;
Code:
MapTiles = {}
-- main form
if form1 then form1.Destroy() end
form1 = createForm()
form1.setSize(250, 250)
form1.Position = "poScreenCenter"

function crtPic(name)
i3=createPicture()
i3.loadFromStream(findTableFile(name).stream)
return i3
end

pic1=crtPic("Block_QM.png")

k = 0
-- 5x5 table
for i = 0 ,4, 1 do
   for j = 0 ,4, 1 do
       k = k + 1
       MapTiles[k] = createImage(form1)
       MapTiles[k].Picture=pic1 --.loadFromStream(findTableFile([[Block_QM.png]]).Stream)
       MapTiles[k].Height = 50
       MapTiles[k].width = 50
       MapTiles[k].top = i * MapTiles[k].Height
       MapTiles[k].left = j * MapTiles[k].width
       MapTiles[k].stretch = true
       MapTiles[k].ShowHint = true
       MapTiles[k].Hint = i + 1 .. ":" .. j + 1
   end
end
form1.Caption = k .. " tiles"

_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
Enthusiastic people: Always one step ahead
Do not underestimate me Master: You were a beginner in the past
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
kucingkembar
Advanced Cheater
Reputation: 0

Joined: 08 Oct 2020
Posts: 71

PostPosted: Tue Apr 12, 2022 3:37 am    Post subject: Reply with quote

sorry for the late reply,
I tried your code, it seems the result is relative the same between createPicture() vs createImage(),
the dark byte mention using "threads", is there any step to activate it?
and thank you again for your reply
Back to top
View user's profile Send private message
AylinCE
Grandmaster Cheater Supreme
Reputation: 32

Joined: 16 Feb 2017
Posts: 1253

PostPosted: Tue Apr 12, 2022 5:23 am    Post subject: Reply with quote

Maybe it can give some idea.

Code:
MapTiles = {}
-- main form
if form1 then form1.Destroy() end
form1 = createForm()
form1.setSize(875, 875)
form1.Position = "poScreenCenter"
form1.visible = false
function crtPic(name)
i3=createPicture()
i3.loadFromStream(findTableFile(name).stream)
return i3
end

pic1=crtPic("aylinCE.png")

i = 0
j = 0
k = 0
l = 0
m = 35 * 35 + 1
n = 0

-- 35x35 table
function crtImg1()
while true do
   if i~=m then
       i = i + 1
       j = j + 1
       k = k + 1
       MapTiles[k] = createImage(form1)
       MapTiles[k].Picture=pic1 --.loadFromStream(findTableFile([[Block_QM.png]]).Stream)
       MapTiles[k].Height = 25
       MapTiles[k].width = 25
       if j==36 then l = l + 25 j = 0 n = 0 end
       MapTiles[k].top = l
       MapTiles[k].left = n
       n = n + 25
       MapTiles[k].stretch = true
       MapTiles[k].ShowHint = true
       MapTiles[k].Hint = i .. ":" .. j + 1
       else
       form1.visible = true
       return false
   end
form1.Caption = k .. " tiles"
end
end
createNativeThread(crtImg1)



AylinCE.PNG
 Description:
 Filesize:  47.46 KB
 Viewed:  1745 Time(s)

AylinCE.PNG



_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
Enthusiastic people: Always one step ahead
Do not underestimate me Master: You were a beginner in the past
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
kucingkembar
Advanced Cheater
Reputation: 0

Joined: 08 Oct 2020
Posts: 71

PostPosted: Tue Apr 12, 2022 5:35 am    Post subject: Reply with quote

I expect it will be fast, but instantaneous, I don't expect that,
thank you thank you thank you
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