當我運行我的遊戲模式時發生此錯誤。需要Lua幫助。嘗試索引字段「配置」(一個零值)Gmod13
[ERROR]
遊戲模式/ RP /遊戲模式/ cl_init.lua:910:嘗試索引字段 '配置'(一個零值)
1.未知 - 遊戲模式/ RP /遊戲模式/ cl_init.lua:910
config
是一個表,具有索引的諸如config["Run Speed"]
和整個表全局等於設定爲GM.Config在sh_config.lua文件。爲什麼配置沒有被註冊爲一個值?我必須將配置文件包含到cl_init文件中嗎?如果是這樣,怎麼樣?使用include()?
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");
。 init.lua中的include("sh_config.lua")
和AddCSLuaFile("sh_config.lua")
。和cl_init.lua中的include("sh_config.lua");
。
雖然我仍然得到這個愚蠢的錯誤。有人能解釋包含和添加文件的區別嗎?如何在其他文件中將sh_config的變量設爲全局變量?換句話說,我如何通過sh_config.lua中的代碼讀取所需的文件(cl_init),並且我可以在客戶端init中使用它的代碼?
顯示負責設置GM.Config表的代碼以及此代碼獲取的位置調用。 – greatwolf
添加代碼。你的意思是它叫什麼名字? –
@NickZook他的意思是一個片段,你可以叫'GM:Think()' –