尝试对表格值进行算术运算
2018-11-5 13:41:13
收藏:0
阅读:113
评论:1
我正在尝试对性别选择更改名称(默认为男性)。但我做不到。我一整天都在尝试,但它仍然无法正常工作。 实际上它可以工作,性别从男性正确地更改为女性,但当我尝试将其更改回来(从女性更改为男性)时,我会收到错误提示:
[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
*面板代码*
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
点赞
评论区的留言会收到邮件通知哦~
推荐文章
- Lua 虚拟机加密load(string.dump(function)) 后执行失败问题如何解决
- 我想创建一个 Nginx 规则,禁止访问
- 如何将两个不同的lua文件合成一个 东西有点长 大佬请耐心看完 我是小白研究几天了都没搞定
- 如何在roblox studio中1:1导入真实世界的地形?
- 求解,lua_resume的第二次调用继续执行协程问题。
- 【上海普陀区】内向猫网络招募【Skynet游戏框架Lua后端程序员】
- SF爱好求教:如何用lua实现游戏内调用数据库函数实现账号密码注册?
- Lua实现网站后台开发
- LUA错误显式返回,社区常见的规约是怎么样的
- lua5.3下载库失败
- 请问如何实现文本框内容和某个网页搜索框内容连接,并把网页输出来的结果反馈到另外一个文本框上
- lua lanes多线程使用
- 一个kv数据库
- openresty 有没有比较轻量的 docker 镜像
- 想问一下,有大佬用过luacurl吗
- 在Lua执行过程中使用Load函数出现问题
- 为什么 neovim 里没有显示一些特殊字符?
- Lua比较两个表的值(不考虑键的顺序)
- 有个lua简单的项目,外包,有意者加微信 liuheng600456详谈,最好在成都
- 如何在 Visual Studio 2022 中运行 Lua 代码?

能告诉我们哪一行是 1055 行吗? 因为我能看到的只有四个“_infos_”表的成员被编辑,然后全部被一个性别的默认信息替换了。
infos.name = table.Random(listWName) infos.surname = table.Random(listWSurname) infos = defMaleInfos ------------------------------------------- infos.name = table.Random(listWName) infos.surname = table.Random(listWSurname) infos = defFemaleInfos应该是这样的:
infos = defMaleInfos infos.name = table.Random(listWName) infos.surname = table.Random(listWSurname) ------------------------------------------- infos = defFemaleInfos infos.name = table.Random(listWName) infos.surname = table.Random(listWSurname)编辑:还有一些其他的事情你应该看一下(第989到1022行),因为在这些行中,你使用了一种C语言风格的注释代码。所以你应该将那些 /* */ 分别替换为 --[[ 和 **--]]**:
-- [[local TextEntry = vgui.Create( "DTextEntry", DPanel ) -- create the form as a child of frame TextEntry:SetPos( w/2-100, 30 + 40 ) TextEntry:SetSize( 200, 30 ) TextEntry:SetText( infos.name ) TextEntry.OnTextChanged = function( self ) txt = self:GetValue() local amt = string.len(txt) if amt > 15 then self.OldText = self.OldText or infos.name self:SetText(self.OldText) self:SetValue(self.OldText) else self.OldText = txt end infos.name = TextEntry:GetValue() end local TextEntry2 = vgui.Create( "DTextEntry", DPanel ) -- create the form as a child of frame TextEntry2:SetPos( w/2-100, 30 + 40 * 2 ) TextEntry2:SetSize( 200, 30 ) TextEntry2:SetText( infos.surname ) TextEntry2.OnTextChanged = function( self ) txt = self:GetValue() local amt = string.len(txt) if amt > 15 then self.OldText = self.OldText or infos.surname self:SetText(self.OldText) self:SetValue(self.OldText) else self.OldText = txt end infos.surname = TextEntry2:GetValue() end --]]