尝试索引lua中的nil值
我有这个密码尝试索引lua中的nil值,lua,garrys-mod,Lua,Garrys Mod,我有这个密码 hook.Add( "PlayerSwitchWeapon", function( ply, oldWeapon, newWeapon ) if (tostring(newWeapon) == tostring(hololink_swep) ) then print( "This weapon is speciall" .. newWeapon:GetClass() .. "." ); end end ); 当我执行它时,我得到 错误、警告:lua
hook.Add( "PlayerSwitchWeapon", function( ply, oldWeapon, newWeapon )
if (tostring(newWeapon) == tostring(hololink_swep) ) then
print( "This weapon is speciall" .. newWeapon:GetClass() .. "." );
end
end );
当我执行它时,我得到
错误、警告:lua5.3:源文件。lua:1:尝试索引
nil值(全局“钩子”)堆栈回溯:source_file.lua:1:in main
块[C]:在什么地方
hook
为零,它在错误消息中正确地表示为零。我最好的猜测是Hook
应该改为大写。@DarkWiiPlayer-使用gmod对象的脚本只能在游戏引擎的上下文中运行。您的脚本将无法在纯Lua下工作。hook
为nil,它在错误消息中正确地说明了这一点。我最好的猜测是Hook
应该改为大写。@DarkWiiPlayer-使用gmod对象的脚本只能在游戏引擎的上下文中运行。您的脚本在纯Lua下无法工作。