In this exemple, we create a string with a lot of lines and display it in a textbox with a fixed height, causing a scrollbar to appear. If we want the scrollbar to be at the top immediately, we cannot use the following command:
Code: Select all
/c
local bigText = ""
for i = 1, 100 do
bigText = bigText .. "\n"
end
bigText = bigText .. "A"
local textbox = game.player.gui.center.add{type="text-box", name="test", text=""}
textbox.style.maximal_height = 800
textbox.text = bigText
textbox.scroll_to_top()
However doing it in two commands work:
Code: Select all
/c
local bigText = ""
for i = 1, 100 do
bigText = bigText .. "\n"
end
bigText = bigText .. "A"
local textbox = game.player.gui.center.add{type="text-box", name="test", text=""}
textbox.style.maximal_height = 800
textbox.text = bigText
Code: Select all
/c game.player.gui.center["test"].scroll_to_top()
Code: Select all
/c
local bigText = ""
for i = 1, 100 do
bigText = bigText .. "\n"
end
bigText = bigText .. "A"
local scroll = game.player.gui.center.add{type="scroll-pane", name="scroll"}
local textbox = scroll.add{type = "text-box", name = "test", text = bigText}
scroll.scroll_to_bottom()