[SOLVED] on_tick event not working

Place to get help with not working mods / modding interface.
Post Reply
TigBits
Inserter
Inserter
Posts: 20
Joined: Mon Oct 03, 2016 12:36 am

[SOLVED] on_tick event not working

Post by TigBits »

I'm trying to update my clock mod from v0.11.22 to 0.14.21. I have fixed all of the errors but the on_tick event still isn't working.

This is the code I am running. When I start a new game, I get the clock label in the upper left corner but it never changes. None of the four test lines in the on_tick function do anything. Does anybody know what's wrong here?

Code: Select all

local function create_clock(playerindex)
	local player = game.players[playerindex]
	player.gui.left.add{type="label", name="clock", caption="clock"}
	player.gui.left.clock.style.font_color = {r=1, g=1, b=1}
	player.gui.left.clock.style.font = "default-bold"
end

script.on_event(defines.events.on_player_created, function(event)
	create_clock(event.player_index)
end)

script.on_event(defines.events.on_tick, function(event)
	for playerindex, player in ipairs(game.players) do
		if (player.gui.left.clock == nil) then
			create_clock(playerindex)
		end
		-- the next four lines test to make sure this function works
		player.gui.left.clock.caption = "Hello"
		game.players[playerindex].gui.left.clock.caption = "Hello"
		game.players[playerindex].print("Hello")
		player.print("Hello")
	end
end)
Screenshot of clock label
Untitled.png
Untitled.png (20.06 KiB) Viewed 1207 times
Last edited by TigBits on Tue Jan 17, 2017 12:48 am, edited 1 time in total.

User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5150
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: [0.14.21] on_tick event not working

Post by Klonan »

TigBits wrote:

Code: Select all

script.on_event(defines.events.on_tick, function(event)
	for playerindex, player in ipairs(game.players) do
		if (player.gui.left.clock == nil) then
			create_clock(playerindex)
		end
		-- the next four lines test to make sure this function works
		player.gui.left.clock.caption = "Hello"
		game.players[playerindex].gui.left.clock.caption = "Hello"
		game.players[playerindex].print("Hello")
		player.print("Hello")
	end
end)
ipairs doesn't work any longer on game.players, just use pairs and it will work

TigBits
Inserter
Inserter
Posts: 20
Joined: Mon Oct 03, 2016 12:36 am

Re: [0.14.21] on_tick event not working

Post by TigBits »

Klonan wrote:ipairs doesn't work any longer on game.players, just use pairs and it will work
Thanks, I realized after I posted that it was actually the loop that was failing to work, but I was still looking into why.

I have the mod updated and fully working now.

Post Reply

Return to “Modding help”