• My first library.. Need help.
    8 replies, posted
Hello. I am making a clientside library. Here's my code: [code] local vx vx = {} function vx.roundedbox( w, h ) draw.RoundedBox(0, 0, 0, w, h, Color(30, 30, 30, 200)) end [/code] I have this file AddCSLuaFile'd and included, and when I go put [code] vx.roundedbox(50, 50) [/code] in my HUDDraw code, it gives me errors saying attempt to index global 'vx' (a nil value) [editline]27th October 2013[/editline] Still can't figure it out :l
remove the "local vx" at the top.
[QUOTE=dingusnin;42664917]remove the "local vx" at the top.[/QUOTE] :o idk how that fixed it.. but it did.. Thank you :D
Yeah, when you call the function it doesn't know what vx is. [editline] se [/editline] Because vx was a local table (usable in that file.), but when you remove local it becomes a global table (usable anywhere.)
Okay, so now, it works, but now I want to define a **[B][U]serverside[/U][/B]** library. The code above was clientside. Here's my code: [code] vx = {} local cmds = {} function vx.AddChatCmd( cmdname ) table.insert(cmds, cmdname) end function ChatCmds( ply, text, public ) for _, v in pairs(cmds) do if (string.sub(text, 1, string.len(v)) == v) then print("You said " ..v.. "!") return(true) end end end hook.Add( "PlayerSay", "AllCmds", ChatCmds ) [/code] I tried running vx:AddChatCmd("/hi") and I get "attempt to index global 'vx' (a nil value)"
vx.AddChatCmd not vx:AddChatCmd (wrong operator)
[QUOTE=arcaneex;42665356]vx.AddChatCmd not vx:AddChatCmd (wrong operator)[/QUOTE] I fixed that. [code] [ERROR] gamemodes/vxlightning/gamemode/plugins/chatcmds/sv_plugin.lua:1: attempt to index global 'vx' (a nil value) 1. unknown - gamemodes/vxlightning/gamemode/plugins/chatcmds/sv_plugin.lua:1 2. include - [C]:-1 3. unknown - gamemodes/vxlightning/gamemode/init.lua:23 [/code] sv_plugin.lua: [code] vx.AddChatCmd("/hi") [/code]
[QUOTE=sackcreator54;42665372]I fixed that. [code] [ERROR] gamemodes/vxlightning/gamemode/plugins/chatcmds/sv_plugin.lua:1: attempt to index global 'vx' (a nil value) 1. unknown - gamemodes/vxlightning/gamemode/plugins/chatcmds/sv_plugin.lua:1 2. include - [C]:-1 3. unknown - gamemodes/vxlightning/gamemode/init.lua:23 [/code] sv_plugin.lua: [code] vx.AddChatCmd("/hi") [/code][/QUOTE] Make sure your vx table is declared before you run the function. Usually this is because one file is included before another.
For some reason, when i put vx.AddChatCmd("/hi") in the library file under function vx.AddChatCmd( cmdname ), it works, I type "/hi" in game, and it prints "You said /hi!" Hmm..
Sorry, you need to Log In to post a reply to this thread.