Posted: Wed Feb 19, 2020 5:07 am Post subject: How using aa script box to en/disable lua timer (luacall?)?
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
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!
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')
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