create variable

Hello There! how would i create a variable in lua? like a function would trigger a variable to be created with a name like IDrandomnumber (random number been a random chosen number)

Creating a variable in lua is one of the simplest basic things you can do, you should have more knowledge than that if you’re gonna come here

im not asking how to create a variable like



var = "a string :D"


im asking how to get my lua script to create a variable

Ready the tutorial at the garrysmod wiki

This may help you:
Beginner Tutorials
Learn Lua in 15 Minutes
Learn LUA in Y Minutes
Lua Variables

[editline]17th July 2015[/editline]

Give us more details. Perhaps, express yourself in any C-like/Java language, or write a pseudo-code.
What is your main goal? Trigger an event when a variable changes its value? …

im trying to create a custom variable for an event, say when ever someone types !newvariable in chat it will create a new variable called their name so for instance if i typed !newvariable it would become Datkid and it would by default set it to false

Hook into

GM/PlayerSay using

hook.Add and then set a variable on the player (ply.Variable = false).

yet again i know that but thats not what im trying to do, im trying to actually create the variable like using something like CreateVar

Like binding a variable to a player?

A global variable that is changed at the call of a function? Just do


variable = false

and anywhere you want that to change (like inside said function) do


variable = "Some Players Name or whatever"

As long as the variable is the same name, it is the same variable (unless you localize it).

Do you mean a console variable?

im wanting to create a variable in the lua script like what that guy below is trying to do is trying to do, none of these worked for me though

http://forum.facepunch.com/showthread.php?t=864398&p=19215794

Store the “variables” in a table and get them from the table as well.
[lua]local variables = {}

– Creating the variable
variables[“Example Name”] = “Example Value”

– Getting the variable
print(variables[“Example Name”])[/lua]
And that prints out “Example Value”.

Just tell us what it’s for and it might be easier to understand what you really want.

Or do what man with hat said.