451 posts
Location
The left part of this post
Posted 16 January 2013 - 01:52 AM
function setVal(key, value)
data.key = value
end
this problem is fustrant i wnt to pass the variable to his value and pass that to the table but is not working HEEEELP
2088 posts
Location
South Africa
Posted 16 January 2013 - 01:55 AM
What's it doing?
try
function setVal(key, value)
data[key] = value
end
451 posts
Location
The left part of this post
Posted 16 January 2013 - 01:59 AM
thanks why i dont mid on that xDDD
7508 posts
Location
Australia
Posted 16 January 2013 - 03:30 AM
As stated
here under the heading "Tables as Dictionaries", you can access data using the shorthand ( syntactical sugar ) of a . but when assigning or updating a key it must be with [ ]
2005 posts
Posted 16 January 2013 - 05:49 AM
That's a little inaccurate. The exact problem is that data.key is precisely equivalent to data["key"], in which key is the literal string "key" and not whatever is contained in the variable with the identifier "key". Thus you need to use data[key], so that you index by the value contained in the variable with the identifier "key" rather than indexing by the literal string value "key".
You can assign new indexes using the format data.key, but the assignment will always be to the literal string value rather than to any variable associated with the identifier.