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

Bugs that are actually features.
Uthrom
Inserter
Inserter
Posts: 33
Joined: Fri Jan 11, 2019 4:01 pm
Contact:

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

Post 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!
User avatar
boskid
Factorio Staff
Factorio Staff
Posts: 3272
Joined: Thu Dec 14, 2017 6:56 pm
Contact:

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

Post by boskid »

Passing nil as the only parameter
when you give more than 1 parameter, this part about nil does not apply.
Uthrom
Inserter
Inserter
Posts: 33
Joined: Fri Jan 11, 2019 4:01 pm
Contact:

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

Post 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.
Post Reply

Return to “Not a bug”