[lua]
MyTable = {"hai"}
hai = "Sup"
print(MyTable[1])
[/lua]
How would I make this print sup without changing the first 2 lines?
:wtc:
Try reading up on tables here: [url]http://wiki.garrysmod.com/?title=Tables[/url]
[QUOTE=Lord Ned;26370716]Try reading up on tables here: [url]http://wiki.garrysmod.com/?title=Tables[/url][/QUOTE]
That dosent tell me how to read a variable with a string.
[lua]
function Red()
Red = "lol yay"
hai = Red
print(hai)
print("TEST ONE COMPLETED STARTING TEST TWO")
Green = "lol yay"
bai = "Green"
print(bai)
end
concommand.Add("Red",Red)
[/lua]
Now this returns...
[code]
[code]
] Red
lol yay
TEST ONE COMPLETED STARTING TEST TWO
Green
[/code]
See what I mean?
The table returns the value in quotes. I need a way to basicly remove those quotes once ive gotten the value.
What I need to do is keep the quotes in the table but make it read the variable.
Is there something I can do like tostring() to complete the action I need?
There is no table in that function of yours... But it's going to return the value in quotes if it's a string.
How do I make it so it isnt a string or a number?
I cannot do
hAi = {Value1, Value2)
Why not?
Because the comma could be apart of the variable name .. Why couldn't it?
When I tried it just returned nil
[lua]hai = "Sup"
MyTable = {"hai"}
print(MyTable[1])[/lua]
Output:
hai
[lua]hai = "Sup"
MyTable = {hai}
print(MyTable[1])[/lua]
Output:
Sup
[lua]hai = "Sup"
thar = "Bro"
MyTable = {hai,thar}
print(MyTable[1])
print(MyTable[2])[/lua]
Output:
Sup
Bro
[QUOTE=zzaacckk;26374932]Because the comma could be apart of the variable name .. Why couldn't it?
When I tried it just returned nil[/QUOTE]
You can't use commas in variable names anyways.
[QUOTE=zzaacckk;26370475][lua]
MyTable = {"hai"}
hai = "Sup"
print(MyTable[1])
[/lua]
How would I make this print sup without changing the first 2 lines?[/QUOTE]
To make it print without changing them?
Do
print("sup"). Simple as that.
Sorry, you need to Log In to post a reply to this thread.