So I want to do something like this
local mission = {
Dummy = {"Amount" == 3, "Money" == 300, "Exp" == 300}
}
How would I index the amount which is 3
Thanks
So I want to do something like this
local mission = {
Dummy = {"Amount" == 3, "Money" == 300, "Exp" == 300}
}
How would I index the amount which is 3
Thanks
You’d have to put [ ] around “Amount”, “Money”, and “Exp”, and change your == to = but:
local amount = mission.Dummy.Amount
print(amount) -- 3
in total:
local mission = {
Dummy = {
["Amount"] = 3; ["Money"] = 300; ["Exp"] = 300;
Amount = 3; Money = 300; Exp = 300; -- this would also work.
}
}
local mission = {
Dummy = {"Amount" = 3, "Money" = 300, "Exp" = 300}
}
“==” is only for statements like if statements
“=” is for assigning variables
As it turns out, this is valid syntax. Since the code uses == instead of =, the three expressions inside of the array evaluate to booleans and it is the same as:
local mission = {
Dummy = {false, false, false}
}
Which makes Dummy a table of three boolean values at indexes 1, 2, and 3. This may be why you were having issues and no errors were showing up. What a tricky problem!
Thank you
And to everyone else who replied
You could also do syntax like
Table = {ObjectOne = "Five", ObjectTwo = "Four"}
It’s the same as doing ["ObjectOne"]
or "ObjectOne"