Jump to content

setElementData on GUI


Antibird

Recommended Posts

This looks confusing for me, but element data set for some GUI-parent element is shared with every child the parent-element has. If a child element is a parent as well, the whole process keep going down the tree, so it's not only related to "gui-window" type of elements.

local window = guiCreateWindow( 100, 200, 100, 100, "testwindow", false ) 
local button = guiCreateButton( 10, 30, 30, 30, "testbutton", false, window ) 
local label = guiCreateLabel( 0, 0, 20, 20, "testlabel", false, button ) 
  
outputChatBox( "W1: " .. tostring( getElementData( window, "testdata" ) ) ) 
outputChatBox( "B1: " .. tostring( getElementData( button, "testdata" ) ) ) 
outputChatBox( "L1: " .. tostring( getElementData( label, "testdata" ) ) ) 
--all 3 returns false 
  
setElementData( window, "testdata", "THEDATA" ) --try changing to "button" 
--no matter, if 4th (sync) argument is specified 
  
outputChatBox( "W2: " .. tostring( getElementData( window, "testdata" ) ) ) 
outputChatBox( "B2: " .. tostring( getElementData( button, "testdata" ) ) ) 
outputChatBox( "L2: " .. tostring( getElementData( label, "testdata" ) ) ) 
--all 3 returns "TESTDATA" string =( 

Shall this be classified as a bug? Everything seems to be Ok to other (non-GUI) elements, also that's not mentioned on wiki.

Edited by Guest
Link to comment

Phew, why no-one told me that before, I thought my GUI system just fools me =)

Anyway, this feature looks half-done in this case. Could be also extended to other types of elements, or just disabled for GUI, or (probably the best case) a 5th argument could be added to setElementData() to choose whether or not to share the data with children. False by default ofc :D

Link to comment

Actually, it works on all elements, not only GUI elements. And if I understand it correctly, setElementData only set's data on the element you specify, not on the children.

What happens in your script is that getElementData inherits the value of the element's parent, the window here. Inheriting happens by default, but you can disable it with the inherit parameter.

Wiki: inherit: - toggles whether or not the function should go up the hierarchy to find the requested key in case the specified element doesn't have it.

    local window = guiCreateWindow( 100, 200, 100, 100, "testwindow", false ) 
    local button = guiCreateButton( 10, 30, 30, 30, "testbutton", false, window ) 
    local label = guiCreateLabel( 0, 0, 20, 20, "testlabel", false, button ) 
      
    outputChatBox( "W1: " .. tostring( getElementData( window, "testdata", false ) ) ) 
    outputChatBox( "B1: " .. tostring( getElementData( button, "testdata", false ) ) ) 
    outputChatBox( "L1: " .. tostring( getElementData( label, "testdata", false ) ) ) 
      
    setElementData( window, "testdata", "THEDATA" ) 
       
    outputChatBox( "W2: " .. tostring( getElementData( window, "testdata", false ) ) ) 
    outputChatBox( "B2: " .. tostring( getElementData( button, "testdata", false ) ) ) 
    outputChatBox( "L2: " .. tostring( getElementData( label, "testdata", false ) ) ) 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...