• Derma error when i call GetValue() on my slider
    4 replies, posted
Hi, i'm working on a character creation screen, but i'm having some problems getting the value of my slider. The function i'm using right now is: [lua] results.age = age.GetValue() [/lua]([i]This is on line [b]225[/b] in the code[/i]) But it comes up with this error: [code] vgui/DNumSlider.lua:67: attempt to index local 'self' (a nil value) [/code] How do i retrieve the value of my slider? [b]Another question[/b]: I use this function, when wanna retrieve the info from my DMultiChoice-menu: [lua] surname.OnSelect = function(index,value,data) surnameOption = data end [/lua]([i]This is on line [b]79[/b] in the code[/i]) Later on i just read the "surnameOption" variable. Isn't there a function like Getvalue() to use instead? [b]Source Code[/b] Source code can be found here: [url]http://pastebay.com/75526[/url] and here: [lua] function namepicker(ply, cmd, args) local width = 500 local height = 500 local padding = 10 local dermaPanel = vgui.Create("DFrame") dermaPanel:SetPos(ScrW() - width - 50,(ScrH() / 2 - height / 2)) dermaPanel:SetSize(width, height) dermaPanel:SetTitle("Please customize your character") dermaPanel:SetVisible(true) dermaPanel:SetDraggable(false) dermaPanel:ShowCloseButton(true) dermaPanel:MakePopup() local propertySheet = vgui.Create("DPropertySheet", dermaPanel) propertySheet:SetPos(padding, 20 + padding) propertySheet:SetSize(width - padding * 2, height - 20 - padding * 2) /* THIS IS THE INTRO SCREEN! */ local introScreen = vgui.Create("DPanelList", dermaPanel) introScreen:SetPos(padding,20 + padding) introScreen:SetSize(width - padding * 2, height - 20 - padding * 2) introScreen:SetSpacing(5) -- Spacing between items introScreen:EnableHorizontal(false) -- Only vertical items introScreen:EnableVerticalScrollbar(true) -- Allow scrollbar if you exceed the Y axis local info = vgui.Create("DLabel", introScreen) info:SetPos(padding,padding) info:SetText([[ Welcome to the server. You need to create your character before joining. Choose with care. You can't change the name and age later on. To start: go to the next tab in this menu. ]]) info:SizeToContents() /* THIS IS THE INFO SCREEN*/ local infoScreen = vgui.Create("DPanelList", dermaPanel) infoScreen:SetPos(padding,20 + padding) infoScreen:SetSize(width - padding * 2, height - 20 - padding * 2) infoScreen:SetSpacing(5) -- Spacing between items infoScreen:EnableHorizontal(false) -- Only vertical items infoScreen:EnableVerticalScrollbar(true) -- Allow scrollbar if you exceed the Y axis local firstnameLabel = vgui.Create("DLabel", infoScreen) firstnameLabel:SetPos(padding,padding) firstnameLabel:SetText("Please select a firstname: ") firstnameLabel:SizeToContents() local firstname = vgui.Create("DTextEntry", infoScreen) firstname:SetPos(150,padding) firstname:SetTall(20) firstname:SetWide(310) firstname:SetEnterAllowed(true) local surnameLabel = vgui.Create("DLabel", infoScreen) surnameLabel:SetPos(padding,padding + 30) surnameLabel:SetText("Please select a surname: ") surnameLabel:SizeToContents() local surname = vgui.Create("DMultiChoice", infoScreen) surname:SetPos(150, padding + 30) surname:SetSize(310, 20) surname:SetEditable(false) surnameOption = "" local surnames = { "svendsen", "johansen", "eriksen", "iversen", "jakobsen" } for k,v in pairs(surnames) do surname:AddChoice(v) -- Add our options end surname.OnSelect = function(index,value,data) surnameOption = data end local ageLabel = vgui.Create("DLabel", infoScreen) ageLabel:SetPos(padding,padding + 75) ageLabel:SetText("Age of your character: ") ageLabel:SizeToContents() local age = vgui.Create("DNumSlider", infoScreen) age:SetPos(150,padding + 60) age:SetSize(310, 250) age:SetText("Age of your character") age:SetMin(15) age:SetMax(50) age:SetDecimals(0) /* THE PLAYERMODEL SCREEN */ local modelScreen = vgui.Create("DPanelList", dermaPanel) modelScreen:SetPos(padding,20 + padding) modelScreen:SetSize(width - padding * 2, height - 20 - padding * 2) modelScreen:SetSpacing(5) -- Spacing between items modelScreen:EnableHorizontal(false) -- Only vertical items modelScreen:EnableVerticalScrollbar(true) -- Allow scrollbar if you exceed the Y axis local genderSheet = vgui.Create("DPropertySheet", modelScreen) genderSheet:SetPos(2, 2) genderSheet:SetSize(466, 426) local maleScreen = vgui.Create("DPanelList", modelScreen) maleScreen:EnableVerticalScrollbar(true) maleScreen:EnableHorizontal(true) maleScreen:SetPadding(0) maleScreen:SetPos(padding,padding) maleScreen:SetSize(width - 50, height - 90) local femaleScreen = vgui.Create("DPanelList", modelScreen) femaleScreen:EnableVerticalScrollbar(true) femaleScreen:EnableHorizontal(true) femaleScreen:SetPadding(0) femaleScreen:SetPos(padding,padding) femaleScreen:SetSize(width - 50, height - 90) local malemodels = { "models/player/Group01/male_07.mdl", "models/player/Group01/Male_01.mdl", "models/player/Hostage/Hostage_01.mdl", "models/player/Hostage/Hostage_04.mdl", "models/player/Group01/male_07.mdl", "models/player/Group01/Male_01.mdl", "models/player/Hostage/Hostage_01.mdl", "models/player/Hostage/Hostage_04.mdl" } local femalemodels = { "models/player/Group01/Female_01.mdl", "models/player/Group01/Female_07.mdl", "models/player/Group01/Female_01.mdl", "models/player/Group01/Female_07.mdl" } playermodel = "" for k,v in pairs(malemodels) do local icon = vgui.Create("SpawnIcon", maleScreen) icon:SetModel(v) maleScreen:AddItem(icon) icon.DoClick = function(icon) playermodel = v LocalPlayer():EmitSound("click.wav") end end for k,v in pairs(femalemodels) do local icon = vgui.Create("SpawnIcon", maleScreen) icon:SetModel(v) femaleScreen:AddItem(icon) icon.DoClick = function(icon) playermodel = v LocalPlayer():EmitSound("click.wav") end end genderSheet:AddSheet("Male", maleScreen, "gui/silkicons/group", false, false, "All the male playermodels goes in here") genderSheet:AddSheet("Female", femaleScreen, "gui/silkicons/group", false, false, "All the female playermodels goes in here") /* THE KEYBINDSSCREEN*/ local bindsScreen = vgui.Create("DPanelList", dermaPanel) bindsScreen:SetPos(padding,20 + padding) bindsScreen:SetSize(width - padding * 2, height - 20 - padding * 2) bindsScreen:SetSpacing(5) -- Spacing between items bindsScreen:EnableHorizontal(false) -- Only vertical items bindsScreen:EnableVerticalScrollbar(true) -- Allow scrollbar if you exceed the Y axis local bindsinfo = vgui.Create("DLabel", bindsScreen) bindsinfo:SetPos(padding,padding) bindsinfo:SetText([[ Instead of using the standard keybinds, you can use your own. Just bind these console commands to 2 different keys. If you just wanna use the normal binds, ignore this message. ]]) bindsinfo:SizeToContents() local commandInfo = vgui.Create("DCollapsibleCategory", bindsScreen) commandInfo:SetPos(padding,60 + padding ) commandInfo:SetSize(450, 50) commandInfo:SetExpanded(0) -- Expanded when popped up commandInfo:SetPadding(5) commandInfo:SetLabel("Commands, click to view") local commandinfoWrap = vgui.Create("DPanelList", commandInfo) commandinfoWrap:SetPos(5,25) commandinfoWrap:SetSize(440, 100) commandinfoWrap:SetSpacing(5) -- Spacing between items commandinfoWrap:EnableHorizontal(true) -- Only vertical items commandinfoWrap:EnableVerticalScrollbar(true) -- Allow scrollbar if you exceed the Y axis local commands = vgui.Create("DLabel", commandinfoWrap) commands:SetPos(padding,padding) commands:SetText([[ bind <key> rp_menu bind <key> rp_doormenu+ ]]) commands:SizeToContents() commandInfo:SetContents(commandinfoWrap) -- Add our list above us as the contents of the collapsible category /* THE GOSCREEN */ local finishScreen = vgui.Create("DPanelList", dermaPanel) finishScreen:SetPos(padding,20 + padding) finishScreen:SetSize(width - padding * 2, height - 20 - padding * 2) finishScreen:SetSpacing(5) -- Spacing between items finishScreen:EnableHorizontal(false) -
[lua]age:GetValue()[/lua] not [lua]age.GetValue()[/lua] [editline]02:37PM[/editline] About your second question, I think that the way you are doing it at the moment is the only way (not sure though).
Ok thanks :D I just found a small typo, in my if-statement and change the "." to ":". Now it works perfectly. Thanks! :D
In fact, you could set the ConVar that the DMultiChoice changes when a choice is selected, then read the [url=http://wiki.garrysmod.com/?title=ConVar]convar[/url]. Look [url=http://wiki.garrysmod.com/?title=DMultiChoice.SetConVar]here[/url].
Ok, thanks :-)
Sorry, you need to Log In to post a reply to this thread.