SetGUIButtonPosition

Definition

SetGUIButtonPosition(string GUIName, string buttonName, int x, int y)

Description

This function sets the two-dimensional position of the button buttonName of GUI GUIName relative to the lower left part of the screen as two x, y values. You can view and copy the name of the GUIs and their buttons in the Script Utility section (Tools > Script Editor > Tools > Script Utility) or the Prefabs and GUIs section of the current VScene.

Parameters

GUIName
The name of the GUI to which the buttonName button belongs. You can also use the name “this” for this parameter. In this case, the name “this” refers to the GUI to which the button buttonName belongs.

buttonName
The name of the button that belongs to GUIName.

x, y
Specify the two-dimensional position of the button buttonName of GUI GUIName relative to the lower left part of the screen as two x, y values.

Example 1

function Init()
    SetGUIButtonPosition("gui_SampleGUI17_MainMenu""PlayGame"GetScreenWidth() / 2, GetScreenHeight() / 2)
end

function Update()

end
In this example, the SetGUIButtonPosition function sets the X and Y position of the “PlayGame” button from the GUI named “gui_SampleGUI17_MainMenu” to (screen width / 2) and (screen height / 2), respectively.

Example 2

--Name of script is SetGUIButtonPosition2.lua

function OnSelectMouseLButtonDown()
    SetGUIButtonPosition("this""PlayGame"GetScreenWidth() / 2, GetScreenHeight() / 2)
end

function OnSelectMouseRButtonDown()

end

function OnSelectMouseEnter()

end
Assume that the above script named SetGUIButtonPosition2.lua is attached to a button named “PlayGame” that belongs to the GUI “gui_1”. In this case, “this” string in the SetGUIButtonPosition function refers to the name “gui_1”. Whenever the user left clicks the “PlayGame” button, we set the X and Y position of the button “PlayGame” belonging to current GUI, which is GUI “gui_1”, to (screen width / 2) and (screen height / 2), respectively.
adminSetGUIButtonPosition