Page 1 of 1

Script.on_event Error support

Posted: Sun Sep 04, 2016 5:47 pm
by Ranakastrasz

Code: Select all

script.on_event(defines.events.on_tick, ticker)
function ticker() -- run once per tickRate number of gameticks.
    if (game.tick % RanaMods.ModularArmor.config.tickRate) == 0 then
		tick()
        
	else
	end
    --[[if (game.tick %  60) == 0 then
        refresh_equipment()
    end]]--
end
This code doesn't call the function, but it doesn't display an error that the function doesn't exist either. You have to put the event registration after the function.
I request that if you do this, it should throw an error claiming the function can't be found, instead of silently doing nothing.

Wasted several days until I figured the problem out.

It works fine if it is registered in a function itself, presumably since the whole file was read before the function was called, but it doesn't work if its outside of a function. That is why I didn't realize the issue.

Re: Script.on_event Error support

Posted: Sun Sep 04, 2016 6:02 pm
by Nexela
It is not silently doing anything though, you are passing nil to script.on_event effectively un-registering it

If you don't want want a nil value assign the variable before you use the variable


I recommend installing luacheck it would have given you a warning :)

Re: Script.on_event Error support

Posted: Sun Sep 04, 2016 6:15 pm
by Ranakastrasz
Ah. That makes a bit more sense.