• Print

Author Topic: Include file(s)  (Read 4345 times)

0 Members and 1 Guest are viewing this topic.

Offline Tomzen

  • Full Member
  • ***
  • Posts: 115
  • Karma: -1
  • A new lua adventurer
    • Thirdage Gaming
Include file(s)
« on: May 21, 2015, 02:29:22 am »
For an addon I'm currently making, I'm using:
Code: Lua
  1. include( "rules_settings.lua" )
to include the settings, and in the settings file I have:
Code: [Select]
local SERVERNAME = GetHostName()
local GAMEMODE = gmod.GetGamemode()

Rule1 = "Rule 1"
Rule2 = "Rule 2"
Rule3 = "Rule 3"
Rule4 = "Rule 4"
Rule5 = "Rule 5"
Rule6 = "Rule 6"
Rule7 = "Rule 7"
Rule8 = "Rule 8"
Rule9 = "Rule 9"
Rule10 = "Rule 10"

I get this error when trying to use it:
Code: [Select]
[ERROR] lua/autorun/rules.lua:16: attempt to concatenate global 'SERVERNAME' (a nil value)

I don't necessarily need to use "include" but it makes it easier for others to edit.
And yes it has the right directory.
« Last Edit: May 21, 2015, 02:32:44 am by Tomzen »
Finished:
Impersonate
<==> FakePromote/Demote <==> RandomMap <==> ForceMic <==> Search <==> PlayMenu <==
WIP:
ServerMode <==

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2727
  • Karma: 430
    • |G4P| Gman4President
Re: Include file(s)
« Reply #1 on: May 21, 2015, 03:59:36 am »
A couple things to consider:

1. include is relative to the lua directory. So if your addon has the rules_settings.lua in lua/rules_settings.lua then the way you have it should work.
2. You are defining SERVERNAME as a local. You would only be able to call it inside that file. If you want to call it outside the file, remove the local prefix.
3. GAMEMODE is already a thing. you don't need to define GAMEMODE = gmod.GetGamemode(). That is 1000% redundant.

  • Print