GetGUIButtonPosition

Definition

int,int GetGUIButtonPosition(string GUIName, string buttonName)

Description

This function returns 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.

Return Value

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

x = 0
y = 0

function OnSelectMouseLButtonDown()
    x,y = GetGUIButtonPosition("gui_test_test""PlayGame")

    message = string.format("\nGUI button position is > %d, %d" , x,y)
    PrintConsole(message)
end

function OnSelectMouseRButtonDown()

end

function OnSelectMouseEnter()

end
Assume that this script is attached to a button named ShowPosition that belongs to a GUI named gui_position. In this case, whenever you left click on the ShowPosition button, the GetGUIButtonPosition function returns the 2D position of the “PlayGame” button from the GUI named “gui_test_test”. This script then displays the x and y positions on the console.

Example 2

--Name of script is GetGUIButtonPosition2.lua

x = 0
y = 0

function OnSelectMouseLButtonDown()
    x,y = GetGUIButtonPosition("this""PlayGame")

    message = string.format("\nGUI button position is > %d, %d", x, y)
    PrintConsole(message)
end

function OnSelectMouseRButtonDown()

end

function OnSelectMouseEnter()

end
Assume that the above script named GetGUIButtonPosition2.lua is attached to a button named “PlayGame” that belongs to the GUI “gui_1”. In this case, “this” string in the GetGUIButtonPosition function refers to the name “gui_1”. Whenever the user left clicks the “PlayGame” button, we get the position of the button “PlayGame” belonging to current GUI, which is GUI “gui_1”. Then we display the result in the console using the PrintConsole function.
adminGetGUIButtonPosition