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 


How using aa script box to en/disable lua timer (luacall?)?

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
Straputsky
How do I cheat?
Reputation: 0

Joined: 09 Aug 2009
Posts: 7

PostPosted: Wed Feb 19, 2020 5:07 am    Post subject: How using aa script box to en/disable lua timer (luacall?)? Reply with quote

Short story:
I want to enable/disable a timer in lua by ticking/un-ticking the box of an aa script

Long story:
I wrote a lua script that changes the experience of each skill in Kingdom Come to 1 point short for the next level. This seems to work fine so far (only tested it in the starting location). However I'm not able to call the lua function of the timer via luacall. The luacall itself seems to work as the "speakEnglish" command afterwards is applied correctly.
The following script is a shortened version of the original code:

Code:

[Enable]
{$lua}
SetTimer = 1

function Training()
  if (SetTimer ~= 1) then timer.destroy() speakEnglish('Training stopped') end
  //from here some checks and code to change the values
end

function ActivateTimer(Setting)
  timer = createTimer(getMainForm(),false)
  timer.OnTimer = Training
  timer.Interval = 1000
  timer.Enabled = Setting
end

if (SetTimer == 1) then ActivateTimer(true) speakEnglish('Training started') end

{$asm}
???
//luacall(ActivateTimer(true) speakEnglish('Timer runs'))

[Disable]
???
//luacall(timer.destroy() speakEnglish('Timer killed'))


When I activate the asm commands, I get the spoken feedback, but nothing happens. The functions work, as I can de-/activate everything by changing the SetTimer value and closing the script window. As this is a bit inconvenient, I'm curious if I could do it better (well obviously I can't otherwise I wouldn't need to ask, that is...)

P.S. It would be nice, if the answers (if any) are formulated in more simple terms, even if it's not THAT technically correct. This script is some sort of my "Hello World", please keep this in mind. Thanks! Wink
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 138

Joined: 06 Jul 2014
Posts: 4275

PostPosted: Wed Feb 19, 2020 10:49 am    Post subject: Reply with quote

A lot of that seems unnecessarily convoluted. Why not do something more straightforward?
Code:
{$lua}
if syntaxcheck then return end

[Enable]

uniqueTimerName = createTimer()
uniqueTimerName.Interval = 1000
uniqueTimerName.OnTimer = function()
  //from here some checks and code to change the values
end
speakEnglish('Training started')

[Disable]

uniqueTimerName.destroy()
uniqueTimerName = nil
speakEnglish('Training stopped')

If it still doesn't work, we'd need to see the code run by the OnTimer function.

_________________
I don't know where I'm going, but I'll figure it out when I get there.
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