#Getting a variable name as a string.

1 messages · Page 1 of 1 (latest)

flat pier
#

Say I had a dictionary like this

Foods = {
Apple = 7,
Oranges = 3,
Bananas = 9}

Is there any way to get the name of a variable in that dictionary as a string. Like ("Apple" or "Bananas")

#

When I try it usually prints the actual table name which is just a long string of randomised numbers and letters

sturdy wave
#

that's a non-indexed table, so you can't really get the variables name directly...
you can use a for loop though

for key, value in pairs(Foods) do
    print(key) -- key is the variable name, value well.. the value
end
quartz pasture
#

bro ofc u can

sturdy wave
sturdy wave
#

and gl with your game

flat pier
#

Tysm

quartz pasture