-1

I don't know lua, though I'm decent with a few other languages, so I'm not entirely ignorant in regards to tables and such

I found this code online and was trying to use it but it keeps spitting out a table index is nil error.

I've been looking at a few other questions and issues online with the same error message, but still can't solve it.

I asked the author for some help but he can't figure it out either. Apparently the error doesn't happen for him.

Here's the code:

local RolePoints = {
    [ROLE_DETECTIVE] = {[ROLE_DETECTIVE] = -250,--Killed Detective as Detective
                        [ROLE_INNOCENT] = -50,--Killed Innocent as Detective
                        [ROLE_TRAITOR] = 20
                    },
    [ROLE_INNOCENT] = {[ROLE_DETECTIVE] = -250,
                        [ROLE_INNOCENT] = -20,
                        [ROLE_TRAITOR] = 20
                    },
    [ROLE_TRAITOR] = {[ROLE_DETECTIVE] = 30,
                        [ROLE_INNOCENT] = 10,
                        [ROLE_TRAITOR] = -500
                    }
    }

In particular, the interpreter claims that this line is the culprit:

[ROLE_DETECTIVE] = {[ROLE_DETECTIVE] = -250,--Killed Detective as Detective

Any ideas?

Thanks

EDIT: I've found that it works if I put it on my own client (though it still gets the errors) but won't work on my server.

hjpotter92
  • 78,589
  • 36
  • 144
  • 183
Rob
  • 7,980
  • 30
  • 75
  • 115

1 Answers1

2

ROLE_DETECTIVE (and the other allcaps names) are almost certainly constants defined elsewhere in the code you pulled this from.

Either quote them and use them as strings, or define them yourself with values (probably numerical IDs).


Googling, it looks like the specific code is Trouble in Terrorist Town, a Garry's Mod mode.

Amber
  • 507,862
  • 82
  • 626
  • 550
  • Correct, in which case the constants are likely defined in the TTT code somewhere. – Rob Jan 05 '13 at 21:08