【发布时间】:2019-01-06 22:29:24
【问题描述】:
我在编写一个简单的代码时遇到了一些麻烦:
SWEP.PrintName = "Gestionnaire d'alarmes Administrateur"
SWEP.Author = "Frass"
SWEP.Instructions = "Clic Gauche : Ouvrir le gestionnaire"
SWEP.Spawnable = true
SWEP.AdminOnly = true
SWEP.Primary.ClipSize = -1
SWEP.Primary.DefaultClip = -1
SWEP.Primary.Automatic = false
SWEP.Primary.Ammo = "none"
SWEP.Secondary.ClipSize = -1
SWEP.Secondary.DefaultClip = -1
SWEP.Secondary.Automatic = true
SWEP.Secondary.Ammo = "none"
SWEP.Weight = 5
SWEP.AutoSwitchTo = false
SWEP.AutoSwitchFrom = false
SWEP.Slot = 1
SWEP.SlotPos = 2
SWEP.DrawAmmo = false
SWEP.DrawCrosshair = true
SWEP.ViewModel = "models/weapons/v_pistol.mdl"
SWEP.WorldModel = "models/weapons/w_pistol.mdl"
local ShootSound = Sound( "buttons/button14.wav" )
function SWEP:PrimaryAttack()
self:TabletMenu()
end
function TabletMenu() (reduced, there's a lot of code inside)
当我尝试在 GMOD 中使用我的 SWEP 时,控制台给了我这个错误:
[ERROR] lua/weapons/alarmtabletld.lua:44: attempt to call method 'TabletMenu' (a nil value)
1. unknown - lua/weapons/alarmtabletld.lua:44
我真的不明白这个错误是怎么回事...... 一些帮助可能真的很好!
【问题讨论】:
-
显然,在文件
alarmtabletld.lua的行44处尝试索引的任何内容中都没有TabletMenu。提供的代码少于 44 行,甚至不清楚它是alarmtabletld.lua。函数function TabletMenu() (reduced, there's a lot of code inside)是全局变量,不是SWEP的字段,所以如果提供的代码全部是,那么self:TabletMenu()是错误的。 -
你好,就像我之前说的,函数 TabletMenu() 已经隐藏在我的文本编辑器中,这就是为什么少于 44 行。我怎样才能使这个函数成为我的扫描字段?
-
和
function SWEP:PrimaryAttack()一样。 -
谢谢它的工作,现在我有另一个问题,但我会为此做另一篇文章。
标签: function lua garrys-mod