Posted: Thu Aug 23, 2018 2:27 am Post subject: Problematic Lua Script
I've ran into a problem regarding a Lua script. I want it to overwrite a value every 10ms when enabled and write a different value as well as destroy the previous timer so it behaves as usual when disabled. It keeps writing the value on it when its disabled. Found no possible causes after checking the script multiple times and figured I'd ask help from more experienced people.
You may have clicked "disable script without executing disable section" or something similar when developing and/or testing the script.
Make the code more resilient to outside factors like this:
Code:
[enable]
{$lua}
if syntaxcheck or htimer or not memrec then return end
htimer = createTimer()
htimer.Interval = 10
htimer.OnTimer = function(t)
local addr, enabled = getAddressSafe('["my_health"]+1C'), memrec.Active
if addr then
writeFloat(addr, enabled and 1200. or 1000.)
end
if not enabled then
t.destroy()
end
end
{$asm}
[disable]
{$lua}
if syntaxcheck or not htimer then return end
htimer.destroy()
htimer = nil
local a = getAddressSafe('["my_health"]+1C')
if a then
writeFloat(a, 1000.)
end
{$asm}
_________________
I don't know where I'm going, but I'll figure it out when I get there.
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