• How include works
    2 replies, posted
I don't understand something. I'm trying to make RTV for TTT, where the voting system is wiox's gmod-mapvote, and I made the RTV system. With wiox's mapvote you start a mapvote using: [CODE]MapVote.Start( settings.Length, settings.AllowCurrent, settings.Limit, settings.Prefix )[/CODE] Ofc I can just replace those with the corrosponding numbers, but something weird happened with "include". I thought if I add a line saying [CODE]include( "mapvote/sv_rtv.lua" )[/CODE] It will be like taking the entire code and pasting it instead of that line, but when I did that exactly (Deleted sv_rtv.lua and pasted the content into autorun/server/ttt_mapvote.lua) it worked. When I used include I got this error: [CODE][ERROR] addons/gmod-mapvote-master/lua/mapvote/sv_rtv.lua:118: attempt to index global 'settings' (a nil value) 1. StartVote - addons/gmod-mapvote-master/lua/mapvote/sv_rtv.lua:118 2. Vote - addons/gmod-mapvote-master/lua/mapvote/sv_rtv.lua:40 3. fn - addons/gmod-mapvote-master/lua/mapvote/sv_rtv.lua:46 4. unknown - addons/ulib/lua/ulib/shared/hook.lua:183 [/CODE] Oh ye start of autorun/server/ttt_mapvote.lua [CODE]local settings = { Length = 20, -- Vote lasts 20 seconds AllowCurrent = false, -- Don't allow current map to be re-voted Limit = 10, -- Only allow the choice of 10 maps Prefix = {"ttt_"}, -- Only allow maps beginning with ttt_ }[/CODE]
Because your "settings" thing is declared as local. Include is simply a RunString on contents of a file you specified so it won't see local variables from other files.
[QUOTE=mijyuoon;48815844]Because your "settings" thing is declared as local. Include is simply a RunString on contents of a file you specified so it won't see local variables from other files.[/QUOTE] Ahh ok. Thanks
Sorry, you need to Log In to post a reply to this thread.