script.on_nth_tick crashes with nil; also documentation

Bugs that are actually features.
Post Reply
swni
Long Handed Inserter
Long Handed Inserter
Posts: 91
Joined: Sat Mar 05, 2016 1:54 am
Contact:

script.on_nth_tick crashes with nil; also documentation

Post by swni »

script.on_nth_tick(nil, nil) crashes, but the documentation says:
Parameters

tick :: uint or array of uint: The nth-tick(s) to invoke the handler on. Passing nil will unregister all nth-tick handlers.

f :: function(NthTickEvent): The handler to run. Passing nil will unregister the handler for the provided ticks.
Furthermore, the documentation doesn't make clear that the specified event fires on every tick that is a multiple of n, instead of only on the nth tick; I had assumed the latter. I suggest something like "Register a handler to run on every tick that is a multiple of n.". It is also unclear whether, if you pass the array {2, 3} say, the handler is run once or twice on tick 6.

Rseding91
Factorio Staff
Factorio Staff
Posts: 13246
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: script.on_nth_tick crashes with nil; also documentation

Post by Rseding91 »

Thanks for the report however: no it doesn't. It gives a script error stating you gave invalid parameters (which you did).

You pass: script.on_nth_tick(nil) to unregister all nth-tick handlers or script.on_nth_tick(#, nil) to unregister that specific nth tick handler. Anything else is invalid.
If you want to get ahold of me I'm almost always on Discord.

swni
Long Handed Inserter
Long Handed Inserter
Posts: 91
Joined: Sat Mar 05, 2016 1:54 am
Contact:

Re: script.on_nth_tick crashes with nil; also documentation

Post by swni »

You're right, I meant the script crashes not that the game crashes. (I forget that those are different things because the end result is I have to restart factorio either way.)

Thanks for letting me know about the correct usage. Could that also be documented? There is nothing in the documentation saying that f is an optional parameter or that it must be omitted if the first parameter is nil. The documentation reads as if on_nth_tick always takes two parameters.

Post Reply

Return to “Not a bug”