I was trying to do name changing that depends on sex choosing (by default it's male). But I can't do it. I have been trying to do it all day but it still doesn't work correctly. Actually it works, the sex is correctly changing from male to female but when I'm trying to change it back(from female to male), I get an error:
[ERROR] *path*/cl_new_character.lua:1055: attempt to perform arithmetic on upvalue 'defMaleInfos' (a table value)
1. DoClick - *path*/cl_new_character.lua:1055
2. unknown - lua/vgui/dlabel.lua:232
Here's the code:
local defMaleInfos = {
model = "models/kerry/player/citizen/male_02.mdl",
name = randommname,
surname = randommsurname,
sex = 1,
playerColor = Vector(1,1,1),
bodygroups = {
top = "polo",
pant = "pant",
},
skin = 0,
eyestexture = {
basetexture = {
["r"] = "eyes/eyes/amber_r",
["l"] = "eyes/eyes/amber_l",
},
},
hasCostume = false,
teetexture = {
basetexture = "models/citizen/body/citizen_sheet",
hasCustomThings = false,
},
panttexture = {
basetexture = "models/citizen/body/citizen_sheet",
},
}
local infos = defMaleInfos
local defFemaleInfos = {
model = "models/kerry/player/citizen/female_01.mdl",
name = randomwname,
surname = randomwsurname,
sex = 0,
playerColor = Vector(1,1,1),
bodygroups = {
top = "polo",
pant = "pant",
},
skin = 0,
eyestexture = {
basetexture = {
["r"] = "eyes/eyes/amber_r",
["l"] = "eyes/eyes/amber_l",
},
},
hasCostume = false,
teetexture = {
basetexture = "models/humans/modern/female/sheet_01",
hasCustomThings = false,
},
panttexture = {
basetexture = "models/humans/modern/female/sheet_01",
},
}
local infosw = defFemaleInfos
*code of panel*
local DButton1 = vgui.Create( "DButton", DPanel2)
DButton1:SetSize( 80,80 )
DButton1:SetPos( w/2-80/2 -100,h/4-80/2+20 )
DButton1:SetText( "" )
DButton1.Paint = function(pnl, w, h )
local m = 1
if infos.sex != 1 then
m = 0
end
surface.SetDrawColor( 255, 255, 255, 255 )
surface.SetMaterial( male )
surface.DrawTexturedRect( 2 + (w-4)/2 - 64/2, 2 + (h-4)/2 - 64/2, 64,64 )
end
DButton1.DoClick = function( pnl )
infos.name = table.Random(listWName)
infos.surname = table.Random(listWSurname)
infos = defMaleInfos
modelPanel.Actualize()
end
local DButton2 = vgui.Create( "DButton", DPanel2)
DButton2:SetSize( 80,80 )
DButton2:SetPos( w/2-80/2 + 100,h/4-80/2 +20 )
DButton2:SetText( "" )
DButton2.Paint = function(pnl, w, h )
local m = 1
if infos.sex != 0 then
m = 0
end
surface.SetDrawColor( 255, 255, 255, 255 )
surface.SetMaterial( female )
surface.DrawTexturedRect( 2 + (w-4)/2 - 64/2, 2 + (h-4)/2 - 64/2, 64,64 )
end
DButton2.DoClick = function( pnl )
infos.name = table.Random(listWName)
infos.surname = table.Random(listWSurname)
infos = defFemaleInfos
modelPanel.Actualize()
end