Results 1 to 3 of 3

Thread: UI and XML scripting questions

  1. #1

    UI and XML scripting questions

    Hello everyone,

    In my game I am trying to have the following items:
    1) a unique, client-side UI whereby only the player seated at a particular color can manipulate their UI and other players cannot manipulate it;
    2) a more resourceful way to parse through the UI.getXMLTable's returned data.
    3) dynamically adjusted UI elements based on what each player is doing to/with their UI.

    I am familiar enough with coding to get a good majority of it together by myself but the above elements are eluding me and I feel that I may just not know where to look for the methods to do what I want.

    For 1)
    I have a UI created that has a show/hide button to test. I initially thought that a UI element would be handled on a client-side basis but in testing each player can click that button and the UI element shows/hides for all players at once. What I'd expect is that there is just a UI element for each player that is unique to that player's client. Do I have to individually code a UI for all players or is there a more elegant way of approaching this? It would be a lot of copy-paste code redundancy if I cannot somehow recycle the existing code and that would be disappointing.

    For 2)
    I understand how the data is stored and produced into a Lua table from the XML code. My UI has several "child" objects inside Panels and other areas. This makes the resulting Lua table from XML pretty complicated and tough to understand from the get-go. I have begun trying to make embedded for loops to iterate through each table but this is a very tedious method to do. Am I missing some code somewhere that will parse out the table data for me or do I have to manually go through each layer as I am? (i.e. for...for...for...for...for...etc until I'm at my expected "deepest" table, instead of some method that just iterates through with ease)

    For 3)
    My game has hidden elements unique to each player which is the brunt of my need for a UI. What a player does with the UI needs to dynamically update. I have been able to successfully use XML id tag attributes to identify where I may want to change something but the result I am expecting/wanting is not working.
    Let's say I have:
    <Panel id="01"><TableLayout><Row><Cell id="c01"></Cell><Cell id="c02"><Button id="b01"></Button></cell><Cell id="c03"></cell></row></TableLayout></Panel>
    I'd like to dynamically insert XML elements into each of those cells. I have tried UI.getValue to retrieve what's currently there and UI.setValue to change the cell's contents. (I do realize that "value" refers to what's between the tags <cell></cell>.) When I go to try and set the value of c02 with a string that contains all the necessary XML formatting, it just inserts it as a string and does not recognize the XML code within that string. (I expected that what was between <cell></cell> to be a value, which would also mean any tags between, but apparently this isn't the case.).
    How do I dynamically change/adjust the elements within those sample cells?
    Tying this together, how would I need to go about it to make it work for every player?

    Hopefully someone has some answers out there or can point me in the right direction. I know I have a lot to learn but I feel I can't be the only one that has had these questions before.

    Thanks for any help in advance!

  2. #2

    UI and XML scripting questions Reply

    Hey man I have a similar mission with my scripts. Did you find a solution yet? I have an Idea for you but if you have a solution already, I'd like to have a peek so I can incorporate your solution into my scripts. But if you are still lost maybe we can both bounce Ideas off of each other. I also can help you with updating current values into the current displayed xml panel / elements. Let me know whats up.

    Last edited by Champagne32; 04-10-2019 at 04:07 PM. Reason: Extra Info

  3. #3
    Last time I tried to work with the UI was more than six months ago and I gave up because I couldn't find a way to save the position of UI elements after they were being dragged around. So my memory is a little clouded, but I'll try to help as much as I can based on what I think I learned at the time.

    1) If you look here:

    you'll see that there is a Visibility Target flag for UI elements. By default a UI element is visible to any and all players and everybody can interact with it. So i guess that if you want for each player to be able to interact with his/her own copy of a UI element you will have to instantiate that same UI element for each player and make each copy visible to only one player (for example by specifying the seat color that it's meant to be visible to).

    3) Maybe you already know (I couldn't figure it out by reading your post) but UI.setValue() will just set the target tag attribute value. It won't update the UI. In order to update the run time UI you have to call UI.setXmlTable(), which takes a data table and produces the XML code itself.

    So, every time you want to update the UI interface, you basically have to retrive the currently running UI (for example through UI.getXmlTable()), modify it according to your necessity, re-save it as a data table and call UI.setXmlTable() with that table as the argument. After a single frame the UI will be updated.

    If you already knew all of this, then sorry for wasting your time, but I believe that it was important to clarify this issue, just in case.

    Which leads us to:

    2) Parsing the lua-table-formatted xml code and modifying it is tricky, as you already noticed. The UI data table is a nested nightmare of sub-tables (children). Every time you have to find the right one by tag and insert into it the new code that will implement the dynamic modifications to the UI.
    I wrote a couple of functions in order to help me do that. While I know that - at the time - they were working and producing the results I was expecting, I didn't extensively test them, so I can't state that they are bug-free. But I will post them anyway because they might give you some ideas.

    The first function was meant to retrieve by recursion a snippet of UI according to its id. It stops when it finds the first applicable id tag. So it won't work if you want to retrieve a children nested inside a parent with the same name tag (if it's even possible to name them the same... not sure). The logging part was meant for debug.

    -- function scanTable (UITable, idString)
    -- Scans the UI table "UITable" and returns (and logs) the element whose id is "idString"
    function scanTable (UITable, idString)
    	if == idString then
    		log(UITable, "----------------")
    		return UITable
    			if UITable.children then
    						for i=1,#UITable.children,1 do
    							scanTable(UITable.children[i], idString)
    The second function is just a modification of the first whose purpose is to actually insert new code into the children once it has been found and retrieved

    -- function setChildren (UITable, idString, _children)
    -- Adds UI children elements "_children" to the "UITable" element whose id is "idString"
    -- "UITable" is usually the currently running UI or one of its elements.
    function setChildren (UITable, idString, _children)
    	if == idString then
    		UITable.children = _children
    			if UITable.children then
    						for i=1,#UITable.children,1 do
    							setChildren(UITable.children[i], idString, _children)
    I hope it might help somewhat...

    edit: damn... I just realized this thread is more than five months old... I guess I came a little too late xD

Similar Threads

  1. Questions about IRC and Tabletop Simulator
    By Tragic in forum General Discussion
    Replies: 1
    Last Post: 02-15-2017, 12:36 PM
  2. Few general questions
    By teroks in forum General Discussion
    Replies: 2
    Last Post: 10-18-2016, 09:26 AM
  3. A few scripting questions
    By McCheesyThePuff in forum Scripting
    Replies: 3
    Last Post: 04-14-2016, 02:52 PM
  4. Dial model questions
    By Jabrwock in forum General Discussion
    Replies: 3
    Last Post: 12-02-2015, 02:51 PM
  5. More questions.
    By LilBrudda in forum General Discussion
    Replies: 2
    Last Post: 03-17-2014, 10:12 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts