【发布时间】:2013-07-01 08:06:53
【问题描述】:
运行游戏模式时出现此错误。
[错误]
gamemodes/rp/gamemode/cl_init.lua:910: 尝试索引字段 'Config'(一个 nil 值)
1. 未知 - gamemodes/rp/gamemode/cl_init.lua:910
config 是一个表,具有诸如config["Run Speed"] 之类的索引,并且整个表在sh_config.lua 文件中全局设置为等于GM.Config。为什么配置没有被注册为一个值?我必须将配置文件包含到 cl_init 文件中吗?如果是这样,如何?使用包含()?
function GM:Think()
if ( self.Config["Local Voice"] ) then **--Referred line(910)**
for k, v in pairs( player.GetAll() ) do
if ( hook.Call("PlayerCanVoice",GAMEMODE, v) ) then
if ( v:IsMuted() ) then v:SetMuted(); end
else
if ( !v:IsMuted() ) then v:SetMuted(); end
end
end
end
-- Call the base class function.
return self.BaseClass:Think();
end
编辑 -- sh_config.lua 中的配置表。
local config = {};
-- Command
config["Command Prefix"] = "/"; -- The prefix that is used for chat commands.
config["Maximum Notes"] = 2; -- Maximum notes per player
config["Advert Cost"] = 60; -- The money that it costs to advertise.
config["Advert Timeout"] = 150 -- How many seconds between adverts
config["OOC Timeout"] = 60 -- How many seconds between OOC messages
config["Item Timer"] = 7 -- How many seconds between item uses
config["Item Timer (S)"] = 20 -- How many seconds between specific item uses
config["Note Fade Speed"] = 12 -- How many minutes before nots disappear
-- Voice
config["Local Voice"] = true; -- Players can only hear a player's voice if they are near them. This is the index being called which is creating an error.
config["Talk Radius"] = 256; -- The radius of each player that
--other players have to be in to hear them talk (units).
-- Player Stuff
config["Walk Speed"] = 150; -- The speed that players walk at.
config["Run Speed"] = 275; -- The speed that players run at.
GM.Config = config;
我在 sh_init.lua 中有 includecs("sh_config.lua");。 include("sh_config.lua") 和 AddCSLuaFile("sh_config.lua") 在 init.lua 中。和 cl_init.lua 中的 include("sh_config.lua");。
我仍然收到这个愚蠢的错误。有人可以解释包含和添加文件之间的区别。如何使 sh_config 的变量在其他文件中成为全局变量?或者换句话说,我如何使所需的文件(cl_init)通过 sh_config.lua 中的代码读取,我可以在客户端 init 中使用它的代码?
【问题讨论】:
-
显示负责设置
GM.Config的表的代码以及调用此代码的位置。 -
添加了代码。在哪里调用它是什么意思?
-
@NickZook 他的意思是你打电话给
GM:Think()的sn-p -
另一种选择可能是 facepunch.com 的 Lua 脚本部分 - 看到这是一个官方论坛,那里有很多伟大的 GMod Lua 头脑。
-
@NickZook - GM:Think() 由游戏本身调用。它被重复调用 - 与 GM:Tick() 相同 - 通常以 66 或 100 次/秒开始。想想还不止这些。
标签: lua