Page 1 of 1

[0.17.59] auto_center not available in LuaGuiElement::add()

Posted: Fri Jul 26, 2019 12:07 am
by asdff45
auto_center does not work, when defined in LuaGuiElement::add().
When defining auto_center=true in add(), and then reading it, it is still false.

Reproduction
All executed ingame with /c

Code: Select all

local test_frame = game.player.gui.screen.add{name='test',type='frame',auto_center=true} -- new frame in the center
game.player.print(game.player.gui.screen.test.auto_center) -- prints false
game.player.gui.screen.test.add{type="label",caption="test-element"} -- set element
-- element is displayed in the top-left corner

Code: Select all

local test_frame = game.player.gui.screen.add{name='test',type='frame'}  -- new frame in the center
game.player.gui.screen.test.auto_center = true -- set auto_center external
game.player.print(game.player.gui.screen.test.auto_center) -- prints true
game.player.gui.screen.test.add{type="label",caption="test-element"} -- set element
-- element is displayed in the center
Edit:
I think i musunderstood, how the add-function works, sorry. I thought, i can define everything there, but that is not the case.

Re: [0.17.59] auto_center not available in LuaGuiElement::add()

Posted: Sun Jul 28, 2019 6:33 pm
by Rseding91
auto_center is only available on elements stored directly in .screen and writing to it checks that. It doesn't know if it's in screen until after it's created so I wasn't able to make it support setting it in .add().