Antibird Posted January 10, 2011 Share Posted January 10, 2011 (edited) 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 January 10, 2011 by Guest Link to comment
eAi Posted January 10, 2011 Share Posted January 10, 2011 It's a feature Honestly, that's how it was designed. I can't quite remember why. It's open to debate whether this is a useful feature. Link to comment
Antibird Posted January 10, 2011 Author Share Posted January 10, 2011 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 Link to comment
SDK Posted January 10, 2011 Share Posted January 10, 2011 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
Antibird Posted January 10, 2011 Author Share Posted January 10, 2011 Oh, God! Thank you SDK! This is something I totally forgot about. (I need to patch my brain.dll) May be closed, thanks you both. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now