[0.18.36] Default tab selection not preserved after saving a game

Place to get help with not working mods / modding interface.
CosmicKid
Manual Inserter
Manual Inserter
Posts: 2
Joined: Mon Apr 02, 2018 7:14 pm
Contact:

[0.18.36] Default tab selection not preserved after saving a game

Post by CosmicKid »

I found something I believe to be a minor bug in the game but I'm not sure. So, when developing a mod I found there's a small issue with tabbed panes. I made a small mod to reproduce this issue (single control.lua file):

Code: Select all

require("mod-gui")

script.on_event(defines.events.on_player_joined_game,
	function (e)
		local player = game.get_player(e.player_index)
		local buttons = mod_gui.get_button_flow(player)

		if not buttons["tab-test-button"] then
			buttons.add{
				type = "button",
				name = "tab-test-button",
				caption = "Test tab",
				style = mod_gui.button_style
			}
		end
	end
)

script.on_event(defines.events.on_gui_click,
	function (e)
		if e.element.name == "tab-test-button" then
			local player = game.get_player(e.player_index)
			local frames = mod_gui.get_frame_flow(player)

			if frames["tab-test-frame"] then
				return
			end

			local frame = frames.add{
				type = "frame",
				name = "tab-test-frame",
				caption = "Tab test",
				direction = "vertical",
				style = mod_gui.frame_style
			}
			
			local tabbed_pane = frame.add{type="tabbed-pane"}
			local tab1 = tabbed_pane.add{type="tab", caption="Tab 1"}
			local tab2 = tabbed_pane.add{type="tab", caption="Tab 2"}
			local label1 = tabbed_pane.add{type="label", caption="Label 1"}
			local label2 = tabbed_pane.add{type="label", caption="Label 2"}
			tabbed_pane.add_tab(tab1, label1)
			tabbed_pane.add_tab(tab2, label2)

			log(tabbed_pane.selected_tab_index)
		end
	end
)
This mod adds a button that opens a frame with tabbed-pane and adds two tabs to it. What I did was:

1. I created a new game.
2. I clicked on the button, the frame showed up. The first tab was selected by default.
3. However, log(tabbed_pane.selected_tab_index) printed nil.
4. I saved the game and rejoined it. There was no tab selected.
5. I selected one of those tabs.
5. I saved the game and rejoined it. This time the tab was selected.

I believe there shouldn't be that discrepancy between what is visible after creating a tabbed pane (first tab is selected by default) and what is actually stored (tabbed_pane.selected_tab_index is nil).

inb4 the solution is just to set tabbed_pane.selected_tab_index = 1 manually.
Post Reply

Return to “Modding help”