How to change the visibility/position of a GUI node (SOLVED)

In the game that I am writing I want to show a “league table” with the standing of the 4 best players and then the current standing of the current player. To that end I have created a “leaguetable” GUI with four boxes containing text nodes to show the scores and handles of those 4 “best” players. I then use this GUI in a “leaguetable” collection which gets loaded via a proxy after first fetching the current league table from one of my servers.

All right thus far. But now here lies the problem. At play-time I cannot be certain that there will be 4 “better” players. So from within the script that works with the collection in question I need to hide the unrequired leaguetable boxes that are present courtesy of the embeded GUI. It is not clear to me how I do this.

Here is what I am doing

local count = table.getn(_hold.leaguetable)
local index = 1
while (index < count) do
       --eventually to be used to populate the league table boxes that DO need to be shown
  index = index + 1
  end

--now I need to hide excess the leaguetable boxes if the server has returned < 4 "better" players
for i=index,4 do
 local item ="boxOuter_"..i
 local pos = go.get_position(item)
 pos.z = -2
go.set_position(item)

end

The leaguetable boxes in leaguetable.gui bear the ids boxOuter_N where N is in 1…4. When I embed the GUI in my leaguetable.collection I can see boxOuter_N as expected. However, the above code I get

Instance boxOuter_2 not found. I assume that there is a way to address GUI nodes from within a collection but it is not clear to me what that mechanism might be.

If it is a GUI object, you need to use the gui set of commands.

local node = gui.get_node("my_node")
local pos = gui.get_position(node)
3 Likes

To expand Gianmichele’s answer a bit: If you’re trying to modify GUI nodes from a script on a game object, you can’t. “.script” files don’t have access to the “gui” namespace and vice versa: “.gui_script” files don’t have access to the “go” namespace. You’ll need to send a message from the game object to the gui component and do the actual stuff in your gui_script.

You can share lua modules between game objects and gui, but otherwise they are fairly separate systems. GUI components & nodes don’t inherit transforms from game objects, they automatically scale based on the window size (unless that’s disabled), and they are usually rendered differently, etc.

gui.set_enabled() shows/hides gui nodes.

2 Likes

I see. After my HTTP call to get server-side leaguetable data I am storing the leaguetable in a global _hold.leaguetable. From what I have figured out the order of the init function calls for a “collection containing a gui” would be

  1. The init function for the collection - in a .script file - would be called first
  2. The init function for the contained gui - in a .gui_script file - subsequently

My mistake was trying to access the GUI child nodes from within .script. Fair enough. I can simply handle the GUI customization from the relevant .gui_script instead.

This handles my current needs. However, a purely hypothetical question - suppose my collection embeds more than one GUI. Is there any guarantee that the various contained .gui_script inits get called in any predictable order?

To answer your question about update order, neither the script nor gui components come in a predictable order (apart from one component type after another)

1 Like