• Help with Derma
    5 replies, posted
Alright so the first DCheckBoxLabel works perfectly fine it turns the velocity meter off/on. The Second DCheckBoxLabel doesnt seem to do anything at all. What I'm trying to do is get it to paint "Velocity:" on the screen when enabled. Only way i can get it to work is if I change the variables in the first DCheckBoxLabel OnChange to textenable instead of hudenable. Any help on this would be amazing! Short version of the code: [lua] local hudenable = 1 local textenable = 1 --The MAgic function velocity() if ( hudenable == 0 ) then return end local Speed = tostring( math.Round( LocalPlayer( ):GetVelocity( ):Length( ) ) ); if ( textenable == 1 ) then draw.SimpleText( "Velocity:", "MenuFont3", ScrW() / 2 -35, ScrH() / 2, Color( 255, 255, 255, 255 ), TEXT_ALIGN_CENTER ) end draw.SimpleText( Speed, "MenuFont3", ScrW() / 2, ScrH() / 2, Color( 255, 255, 255, 255 ), TEXT_ALIGN_CENTER ) end --Enable CheckBox local FormContentOne = vgui.Create( "DCheckBoxLabel" ) FormContentOne:SetText( "Enable" ) FormContentOne:SetValue( 1 ) FormContentOne:SizeToContents() function FormContentOne.OnChange() if ( hudenable == 1 ) then hudenable = 0 else hudenable = 1 end end TestingForm:AddItem( FormContentOne ) --Text Enable CheckBox local textenable = true local FormContentTwo = vgui.Create( "DCheckBoxLabel" ) FormContentTwo:SetText( "Disable Text" ) FormContentTwo:SetValue( 0 ) FormContentTwo:SizeToContents() function FormContentTwo.OnChange() if ( textenable == 1 ) then textenable = 0 else textenable = 1 end end TestingForm:AddItem( FormContentTwo ) [/lua]
I won't tell you how bad it looks to be using numbers as booleans but if you remove line 31 it'll work.
Damn I forgot to remove it after i moved my variables to the top of my code, thank you very much. And if you could tell me a better way to do this id really appreciate it. I'm a rookie coder and im looking to get better/learn how to do things the right way. **edit** I tried using something like this but I couldnt get it to work [lua] FormContentOne.OnChange = function(fValue) HudEnable = fValue end [/lua]
true / false instead of 1 / 0 true and false are one bit (8 in space), your numbers are 32 bits (64? I don't remember what Lua uses) Either way you should use booleans so you can use not, and, or, etc. [lua]FormContentOne.OnChange = function(me, value) HudEnable = value end[/lua] It's calling MyPanel:OnChange(value) which is the same as MyPanel.OnChange(Panel, value) You can write it as function MyPanel:OnChange(value) or function MyPanel.OnChange(me, value)
Thats exactly what I tried before im not sure if its broken in gmod13 or what. I had a buddy look at it before i posted it on FP and he told me that should definitely be working. Also how do I uncheck a checkbox if a player checks another box? I tried this but its not working. [lua] --Above Crosshair CheckBox local FormContentOne = vgui.Create( "DCheckBoxLabel" ) FormContentOne:SetText( "Above Crosshair" ) FormContentOne:SetValue( 1 ) FormContentOne:SizeToContents() function FormContentOne.OnChange() FormContentTwo:SetValue( 0 ) PosX = ACX PosY = ACY end TestingForm:AddItem( FormContentOne ) --Below Crosshair CheckBox local FormContentTwo = vgui.Create( "DCheckBoxLabel" ) FormContentTwo:SetText( "Below Crosshair" ) FormContentTwo:SetValue( 1 ) FormContentTwo:SizeToContents() function FormContentTwo.OnChange() PosX = BCX PosY = BCY end TestingForm:AddItem( FormContentTwo ) [/lua]
Is it even possible to uncheck a check box if you select another one?
Sorry, you need to Log In to post a reply to this thread.