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 


native thread and timer

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
mgr.inz.Player
I post too much
Reputation: 218

Joined: 07 Nov 2008
Posts: 4438
Location: W kraju nad Wisla. UTC+01:00

PostPosted: Sat Aug 16, 2014 10:54 am    Post subject: native thread and timer Reply with quote

I have very long Lua script. It works great.

But it has one downside: I have to use openProcess in a loop, and this instruction freezes CE (micro stuttering while form dragging, or scrolling my NFO window).

So, I moved this loop into another function, function assigned to native thread (created with createNativeThread).

But, another problem arise: looks like a can not enable timer object in native thread.



Here, I wrote another script you can test this issue:
Code:
function smrtDestroy(o) if o and o.destroy then o.destroy() end end

smrtDestroy(testTimer); testTimer=nil

testTimer = createTimer(nil,false)
testTimer.Interval = 1000
testTimer.OnTimer = function (timer) print("testTimer tick") end

function tTest(thread)
  thread.name = 'tTest'
  print('tTest thread started')

  while not allow do
    sleep(1000)
  end

  testTimer.Enabled = true
  print('testTimer should work')
end

createNativeThread(tTest)



Launch this script,
then, in Lua Engine window, execute this:
Code:
allow = true


Output is:
Code:
tTest thread started
allow = true

testTimer should work


I expected "testTimer tick" as well, but it doesn't show up.



EDIT:
I could change this line
testTimer.Enabled = true

into
thread.synchronize(function () testTimer.Enabled = true end)

But, it looks weird. Is there other solution?

_________________
Back to top
View user's profile Send private message MSN Messenger
Dark Byte
Site Admin
Reputation: 457

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

PostPosted: Sat Aug 16, 2014 6:56 pm    Post subject: Reply with quote

Not sure. The timer falls in the "gui" category, so it's to be expected to be buggy when used in a thread, but it's so low level there shouldn't be too many issues.

Instead of setting enabled to true, try creating it enabled by default, but keep OnTimer unassigned (or point it to an empty function)
In the thread then assign the timer an OnTimer event . This might work better as it's less unsafe (still 2 pointers, code and data)

The "official" solution is to use synchronize though

_________________
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
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