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 


Timer enable question

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

Joined: 08 Oct 2012
Posts: 577

PostPosted: Thu Sep 12, 2013 8:47 pm    Post subject: Timer enable question Reply with quote

I had a bit of code at the end of all the code lines immediately preceding a form_show(CheatPanel) command:
Code:

tSave = createTimer(nil, true)
timer_onTimer(tSave, SaveAnywhere)
timer_setInterval(tSave, 500)--checks every 500 milliseconds
timer_setEnabled(tSave, true)
print("The save timer is enabled")

function SaveAnywhere(sender)
addresslist = getAddressList()
saveanywhereaddress = addresslist_getMemoryRecordByDescription(addresslist, "Save 0 No 128 Yes (Note: Airship may disappear)")
print("The address of the save is = ", saveanywhereaddress)
saveanywhere = memoryrecord_getValue(saveanywhereaddress)
print("The value of the save is = ", saveanywhere)
  if tonumber(saveanywhere) ~= 0 then
    prevsaveanywhere = tonumber(saveanywhere)
  else
    memoryrecord_setValue(saveanywhereaddress, prevsaveanywhere)
  end
end


When I opened the CE table nothing happened, except the print statement "The save timer is enabled"??

So I experimented a bit and put
Code:

tSave = createTimer(nil, true)
timer_onTimer(tSave, SaveAnywhere)
timer_setInterval(tSave, 500)--checks every 500 milliseconds
timer_setEnabled(tSave, true)
print("The save timer is enabled")
in function FormShow(sender)

When the table was opened the print commands began running non-stop as I expected.

The question why didn't the timer execute in the first bit of code?
Back to top
View user's profile Send private message Yahoo Messenger
Dark Byte
Site Admin
Reputation: 458

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

PostPosted: Fri Sep 13, 2013 3:06 am    Post subject: Reply with quote

when this code is execute the first time:
Code:

timer_onTimer(tSave, SaveAnywhere)

it is equivalent to
Code:

timer_onTimer(tSave, nil)


SaveAnywhere is still nil because it has not yet been declared. That happens after the print

Declare the function above the timer, not below it. (Or use a string as function, ce handles those differently)

_________________
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
bknight2602
Grandmaster Cheater
Reputation: 0

Joined: 08 Oct 2012
Posts: 577

PostPosted: Fri Sep 13, 2013 6:40 am    Post subject: Reply with quote

Dark Byte wrote:
...Or use a string as function, ce handles those differently)


Would you give me an example of a string as function, please?
Back to top
View user's profile Send private message Yahoo Messenger
Dark Byte
Site Admin
Reputation: 458

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

PostPosted: Fri Sep 13, 2013 7:22 am    Post subject: Reply with quote

timer_onTimer(tSave, "SaveAnywhere")
_________________
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
bknight2602
Grandmaster Cheater
Reputation: 0

Joined: 08 Oct 2012
Posts: 577

PostPosted: Fri Sep 13, 2013 9:59 pm    Post subject: Reply with quote

Ok I misunderstood your first post as I thought there was another way to code that statement
Back to top
View user's profile Send private message Yahoo 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