For example, I create a function that I call using the console.
Code: Select all
function print_message_within_10_tick()
game.print(game.tick)
end
Code: Select all
function print_message_within_10_tick()
game.print(game.tick)
end
Code: Select all
function print_message_within_10_tick()
if game.tick <= goal then
game.print(game.tick)
else
script.on_event(defines.events.on_tick, nil) -- delete listener
end
end
goal = game.tick + 10
script.on_event(defines.events.on_tick, print_message_within_10_tick) -- add listener
Wow, great work! Thanks for the quick responseDaveMcW wrote: ↑Fri Oct 05, 2018 8:51 pmCode: Select all
function print_message_within_10_tick() if game.tick <= goal then game.print(game.tick) else script.on_event(defines.events.on_tick, nil) -- delete listener end end goal = game.tick + 10 script.on_event(defines.events.on_tick, print_message_within_10_tick) -- add listener
Code: Select all
function return_on_tick()
script.on_event(defines.events.on_tick, function(event)
function_one(event)
function_two(event)
function_three(event)
end)
end
Code: Select all
script.on_init(function()
return_on_tick()
end)
Code: Select all
function print_message_within_10_tick()
if game.tick < goal then
game.print(game.tick)
else
script.on_event(defines.events.on_tick, nil)
return_on_tick()
end
end
function call_print_message_within_10_tick()
goal = game.tick + 10
script.on_event(defines.events.on_tick, print_message_within_10_tick)
end
Code: Select all
function_three(event)
if goal and goal < game.tick then
game.print(game.tick)
end
end
Code: Select all
local function print_in_10(msg)
global.future[game.tick] = msg
end
script.on_init(function() global.future = {} end)
script.on_tick(function()
-- stuff
if global.future[event.tick] then
game.print(global.future[event.tick])
global.future[event.tick] = nil
end