• Derma not saving it's value?
    12 replies, posted
So I'm creating a derma with a pop down selection checkbox. Whenever I try to do anything with those variables though it is always whatever I set it to at first. And after realising this I closed and re-opened after changing all the checks and they reverted back to normal. [code]local SettingsDerma = vgui.Create( "DFrame" ) SettingsDerma:SetPos( (ScrW()/2)-250, (ScrH()/2)-250 ) SettingsDerma:SetSize( 500, 500 ) SettingsDerma:SetTitle( "Minimap Settings" ) SettingsDerma:SetVisible( settingsVisable ) SettingsDerma:SetDraggable( false ) SettingsDerma:ShowCloseButton( false ) SettingsDerma:MakePopup() local PlayerList = vgui.Create("DCollapsibleCategory", DermaPanel) PlayerList:SetParent(SettingsDerma) PlayerList:SetPos( 25,50 ) PlayerList:SetSize( 200, 50 ) -- Keep the second number at 50 PlayerList:SetExpanded( 0 ) -- Expanded when popped up PlayerList:SetLabel( "Friends" ) PlayersListContents = vgui.Create( "DPanelList" ) PlayersListContents:SetAutoSize( true ) PlayersListContents:SetSpacing( 5 ) PlayersListContents:EnableHorizontal( false ) PlayersListContents:EnableVerticalScrollbar( true ) PlayerList:SetContents( PlayersListContents ) -- Add our list above us as the contents of the collapsible category local players = player.GetAll() for k,v in pairs(players) do if LocalPlayer()!=v then name = v:Nick() listNum = 1 BoxName = tostring("PlrBox"..listNum) BoxName = vgui.Create("DCheckBoxLabel") BoxName:SetText(name) BoxNAme:SetValue(0) PlayersListContents:AddItem(BoxName) listNum = listNum + 1 if BoxName:GetValue() == 1 then v.friend = true else v.friend = false end end end end [/code]
Yes, Derma panels and all metadata are removed when they are closed. Try creating a local table variable and storing your data in that.
Alright now what if I'm trying to keep track of many variables. Like with that code, i've been trying to do this. And it isn't working one bit. [code] value = {} local players = player.GetAll() for k,v in pairs(players) do if LocalPlayer()!=v then local name = v:Nick() local listNum = 1 BoxName = tostring(name..listNum) BoxName = vgui.Create("DCheckBoxLabel") BoxName:SetText(name) BoxName:SetValue(value.listNum) PlayersListContents:AddItem(BoxName) print(value[listNum]) if BoxName:GetValue() == 1 then v.friend = true value.listNum = 1 elseif BoxName:GetValue() == 0 then v.friend = false value.listNum = 0 else value.listNum = 0 end listNum = listNum + 1 end end [/code] and it's always nil when I try to use the values!
Wow someone else had the same issue a me! Thing is with my derma panels everything works fine in single player but when i am in multiplayer the dcheckboxes loose their values when i re-open the derma. But this doesn't happen every time but often enough to be a pain. Also take a look at this for tables [URL="http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index2584.html"]http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index2584.html[/URL]
Well let's hope someone helps us XD
I don't think i can be of much help here but take a look at this example table. This is a snippet taken from my wip gamemode. In cl_init.lua [code] -----------Weapons Table---------------- local myweapons = {} myweapons["weapon_crowbar"]="Crowbar" myweapons["weapon_fists"]="Fists" myweapons["weapon_pistol"]="Pistol" myweapons["weapon_357"]="357" myweapons["weapon_smg1"]="SMG" myweapons["weapon_ar2"]="Pulse Rifle" myweapons["weapon_shotgun"]="Shotgun" myweapons["weapon_crossbow"]="Crossbow" myweapons["weapon_frag"]="Grenade" myweapons["weapon_rpg"]="RPG" myweapons["weapon_slam"]="Slam" myweapons["weapon_physgun"]="Physgun" myweapons["weapon_physcannon"]="Gravity Gun" myweapons["m9k_glock"]="Glock" myweapons["m9k_honeybadger"]="Honey Badger" myweapons["m9k_coltpython"]="Colt Python" myweapons["m9k_ump45"]="UMP45" myweapons["rens_pulse_rifle"]="Hax0r Gun" ----------------------------------------- [/code] What this does is when i am calling the table to compare a value it searches the table and compares to another value then gets the name i have created. (That all sounds confusing) So for example if i wanted to look up the value of weapon_crowbar [code] local myweapons = {} myweapons["weapon_crowbar"]="Crowbar" [/code] My function/code would get the value of weapon_crowbar from the table which in this case returns the string "Crowbar" (Without quotes) Also, try not to use spaces in your defined names. For example use ply instead of your player [code] local ply = LocalPlayer() [/code] This now makes it to wherever you use the string/value ply, the game knows that ply is actually referring to or equal to LocalPlayer() Now for adding values to a table you can use [URL="http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index2d46.html"]http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index2d46.html[/URL]
I understand tables, just not how to use the values in a for loop to name values of the table..
[QUOTE=WolfNinja2;42921103]I understand tables, just not how to use the values in a for loop to name values of the table..[/QUOTE] What you've done is accessed the table before you've assigned any values to it. You do BoxName:SetValue(value.listNum) before you've set value.listNum to anything.
set value.listNum, it is still bringing back a reset derma [code] local players = player.GetAll() for k,v in pairs(players) do if LocalPlayer()!=v then local name = v:Nick() local listNum = 1 if !value.listNum then value.listNum = 0 end BoxName = tostring(name..listNum) BoxName = vgui.Create("DCheckBoxLabel") BoxName:SetText(name) BoxName:SetValue(value.listNum) PlayersListContents:AddItem(BoxName) if BoxName:GetValue() == 1 then v.friend = true value.listNum = 1 elseif BoxName:GetValue() == 0 then v.friend = false value.listNum = 0 end listNum = listNum + 1 end end [/code]
Alright so, First of all you will want to create "temporary" variables, what you want to do with them is whenever a checkbox gets ticked then ur gonna set ur temporary variable to true inside the function that happens when u tick a checkbox, also run a check to see if they equal true then make them true else make them false, so whenever you open your derma it would run a check for those temporary variables and if they equal true then change the DCheckBox value to true et et.. Hope this helped you, if not then i will be glad to answer you in more detail but this should work for you.
[QUOTE=Luamaster;42943162]Alright so, First of all you will want to create "temporary" variables, what you want to do with them is whenever a checkbox gets ticked then ur gonna set ur temporary variable to true inside the function that happens when u tick a checkbox, also run a check to see if they equal true then make them true else make them false, so whenever you open your derma it would run a check for those temporary variables and if they equal true then change the DCheckBox value to true et et.. Hope this helped you, if not then i will be glad to answer you in more detail but this should work for you.[/QUOTE] Holly crap thank you XD I had this same issue and it was messing up quite a bit of stuff!
[QUOTE=Luamaster;42943162]Alright so, First of all you will want to create "temporary" variables, what you want to do with them is whenever a checkbox gets ticked then ur gonna set ur temporary variable to true inside the function that happens when u tick a checkbox, also run a check to see if they equal true then make them true else make them false, so whenever you open your derma it would run a check for those temporary variables and if they equal true then change the DCheckBox value to true et et.. Hope this helped you, if not then i will be glad to answer you in more detail but this should work for you.[/QUOTE] Now what about in my case? Where I have a for loop for all players and each needs their own true false variable. How could i do this?
[QUOTE=WolfNinja2;42952214]Now what about in my case? Where I have a for loop for all players and each needs their own true false variable. How could i do this?[/QUOTE] Assign the value to each player like Player.Variable = Value.
Sorry, you need to Log In to post a reply to this thread.