0

Having this error when I run my gamemode.

[ERROR]
gamemodes/rp/gamemode/cl_init.lua:910: attempt to index field 'Config' (a nil value)
1. unknown - gamemodes/rp/gamemode/cl_init.lua:910

config is a table, with index's such as config["Run Speed"] and the entire table is set globally equal to GM.Config in the sh_config.lua file. Why is config not being registered as a value? Must I include the config file into the cl_init file? and if so, how? Using the 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

Edit -- config table in 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;

I have includecs("sh_config.lua"); in sh_init.lua. include("sh_config.lua") and AddCSLuaFile("sh_config.lua") in init.lua. and include("sh_config.lua"); in cl_init.lua.

Im still getting this stupid error though. Can someone explain what the difference between including and Addcs'ing a file does. How do I make sh_config's variables global in other files? Or in other words how do I make the desired file(cl_init) read through the code in sh_config.lua and I can use code from it in the client side init?

4

2 回答 2

0

You need to include sh_config.lua at the top of cl_init.lua.

include("path/to/file.lua")

Be sure to do AddCSLuaFile("path/to/lua.lua") in the init.lua file as well. You will also need to do include("path/to/file.lua") in init.lua as well. (That's only required for shared files, though)

Also I am pretty sure the scope of your config table would be limited to sh_config.lua so you should remove local from your variable declaration.

于 2013-06-30T16:39:16.093 回答
0

*sh_config* 是一个共享文件——这意味着它必须包含在客户端和服务器端。

init.lua - 在其他包括之上include("sh_config.lua")
在 init.lua 中放入 put -AddCSLuaFile("sh_config.lua")这将确保文件被客户端下载,并在客户端执行。

cl_init.lua中放置include("sh_config.lua")。还围绕其他包括。这应该按预期工作。

看到这是一个配置文件,我认为应该首先包含它,或者几乎首先包含它。对于脚本加载的其余部分,它可能包含重要设置。

另外 - 通常包含一个 shared.lua ,等于一个 shared_init 文件。这可能是你的情况。如果是,您应该include("sh_config.lua")在 shared.lua 和 -block 中添加一个包含包含的AddCSLuaFile("sh_config.lua")内容if CLIENT then

于 2013-06-30T16:48:53.003 回答