Page 1 of 1

[0.18.10] [Documentation?] calling on_nth_tick(nil, anything) gives error

Posted: Sun Mar 08, 2020 3:48 pm
by Uthrom
According to the documentation:

Code: Select all

on_nth_tick(tick, f)
Register a handler to run every nth tick(s). When the game is on tick 0 it will trigger all registered handlers.

Parameters
tick :: uint or array of uint: The nth-tick(s) to invoke the handler on. Passing nil as the only parameter will unregister all nth-tick handlers.
f :: function(NthTickEvent): The handler to run. Passing nil will unregister the handler for the provided ticks.
Actual code:

Code: Select all

    Events.findall_radars()
    script.on_nth_tick(nil, nil)
    script.on_nth_tick((global.Mod.PanopticonRechartInterval * 60), Events.rechart_base)
Factorio error:

Code: Select all

Error while running event Panopticon::on_runtime_mod_setting_changed (ID 59)
First argument must be a number or table.
stack traceback:
	__Panopticon__/control.lua:21: in function 'UpdateSetting'
	__Panopticon__/control.lua:35: in function <__Panopticon__/control.lua:34>
stack traceback:
	[C]: in function 'on_nth_tick'
	__Panopticon__/control.lua:21: in function 'UpdateSetting'
	__Panopticon__/control.lua:35: in function <__Panopticon__/control.lua:34>

The error also occurs with

Code: Select all

script.on_nth_tick(nil, Events.rechart_base)
I found viewtopic.php?t=71803, which reports it as not-a-bug saying the correct call is on_nth_tick(nil) -- but that's in opposition to what the documentation says.

Can either the documentation be updated to reflect the proper calling convention, or update the function to act according to the documentation?

Thanks!

Re: [0.18.10] [Documentation?] calling on_nth_tick(nil, anything) gives error

Posted: Sun Mar 08, 2020 4:05 pm
by boskid
Passing nil as the only parameter
when you give more than 1 parameter, this part about nil does not apply.

Re: [0.18.10] [Documentation?] calling on_nth_tick(nil, anything) gives error

Posted: Sun Mar 08, 2020 5:08 pm
by Uthrom
boskid wrote: Sun Mar 08, 2020 4:05 pm
Passing nil as the only parameter
when you give more than 1 parameter, this part about nil does not apply.
on_nth_tick(tick, f)
Register a handler to run every nth tick(s). When the game is on tick 0 it will trigger all registered handlers.

Parameters
tick :: uint or array of uint: The nth-tick(s) to invoke the handler on.
f :: function(NthTickEvent): The handler to run. Passing nil will unregister the handler for the provided ticks.

Passing nil as the only parameter will unregister all nth-tick handlers.


There, I fixed it.