• DCheckBox.OnChange() returns the panel?
    5 replies, posted
I must be going blind or retarded. Code: [lua] local comval = GetConVarNumber( com ) local box = vgui.Create( "DCheckBox", panel ) box:SetPos( 3, 0 ) box:SetChecked( comval ) box:SetValue( comval ) box.OnChange = function( valuz ) Msg( tostring(valuz).."\n\n" ) --ASA.Rcon( com, tostring(valuz) ) end [/lua] Console: [code] Panel: 23A8EE78 [/code] My console messages a panel object! Not a bool or a number. What the **** is happening? lol
[lua]box.OnChange = function( pnl, valuz )[/lua]
The source of the DCheckBox say's this: [lua] /*--------------------------------------------------------- Name: OnChange ---------------------------------------------------------*/ function PANEL:OnChange( bVal ) // For override end [/lua] [editline]11:14PM[/editline] I envy blackops... WTF WHY????????????????????? lol
It's because of the difference between : and . I don't really know how to explain it, but : is used when you want the first parameter to automatically be the upvalue (in this case the panel) of the function.
[QUOTE=Nori;19067782]It's because of the difference between : and . I don't really know how to explain it, but : is used when you want the first parameter to automatically be the upvalue (in this case the panel) of the function.[/QUOTE] ":" is syntactic sugar for ".bla(bla,...)" ie [lua] function something:AFunc( a, b ) == function something.AFunc( self, a, b ) and something:AFunc( 1, 2 ) == something.AFunc( something, 1, 2 ) [/lua]
Ahhh, why haven't I ever known that? lol
Sorry, you need to Log In to post a reply to this thread.