性別の選択に応じて名前を変更しようとしていました(デフォルトでは男性です)。しかし、私はそれを行うことはできません。私は一日中それをやろうとしていますが、それでも正しく動作しません. 実際には機能し、性別は男性から女性に正しく変更されていますが、元に戻そうとすると(女性から男性に)、エラーが発生します:
[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
コードは次のとおりです。
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