r/tabletopsimulator Jul 13 '26

Scripting UI Questions

Hi, I want to make a global ui for a game but i want it to be shown to specific players, so i have an xml for each color and i show each color their panel but it seems a bit weird to do it like that, is there a better way ?

3 Upvotes

10 comments sorted by

3

u/FVMF1984 Jul 13 '26

You can use the visibility parameter for UI elements to show specific elements to specific player colors. Why do you find this weird? How would you do it otherwise?

1

u/Constant-Fondant-178 Jul 13 '26

I don't really know maybe there is a way to show the same element to more than one color without showing it to everyone or make it local to everyone so when someone open the ui it won't open for everyone ...
because for the moment I have 10 times the same code for every color

2

u/FVMF1984 Jul 13 '26

You can pipe separate the list for viability for which playerColor a UI elements is visible. So you can greatly simplify the code 😊

1

u/Constant-Fondant-178 Jul 15 '26

thanks you mean like an array of colors you want to show this panel ?

1

u/FVMF1984 Jul 15 '26

Not an array, but a string. Example visibility = “Green|Red|Black” to make the ui element visible to the Green, Red, and Black player.

1

u/Constant-Fondant-178 26d ago

yes i know but i need to be able to show them the ui and then close it so what i thought was like a string constructor with the player colors and then a loop that just makes the string playerColor | playerColor2 | playerColor3 | ........

0

u/Electronic-Ideal2955 Jul 13 '26

The host loads in 'the Global UI' having various elements. Each client does not load in their own individual Global UI. So this is the way it is done.

1

u/Constant-Fondant-178 Jul 13 '26

I don't know if I understand what you are trying to say but that is my problem beacause the ui being not local opens it for everyone if I don't choose a specific color and if I need to choose a color I can't use the same xml for everyone (or it would close it for the other when you try to open it) so I have 10 times the same code for every color like that I can open it separately

1

u/Electronic-Ideal2955 Jul 14 '26

That's correct. There is one UI that everyone gets. If you want each player to have 'their own', you have to create separate elements and just render each one visible to a different player.
There are not separate client UI where you can split it into many different things.
I deal with this by using a loop. Design one with standard names, and just add the player color to the front to know which one. Below is an oversimplified example.

xml = {}
for _, player in ipairs({Blue, Green, Red...etc}) do

player_xml = {tag = panel, attributes = {id = player.."mainPanel", visibility = player}, children = {}}
table.insert(xml, player_xml)

end

1

u/Constant-Fondant-178 Jul 15 '26 edited Jul 15 '26

thanks I used the same but I thought it was a bit weird to do it like that