I know this is weird and seems like a stupid question, but may I ask if there is a way to print the local variable name instead of their value
let’s say i have
local abc = “hey”
and then we can print the local variable name which is abc.
I know this is weird and seems like a stupid question, but may I ask if there is a way to print the local variable name instead of their value
let’s say i have
local abc = “hey”
and then we can print the local variable name which is abc.
Do these articles help?
(Check the last comments on the first one(
I don’t see why you would need this, but I guess for debugging purposes you could print the variable name and its value to see what it’s set as, to see if everything is working as intended.
local thing1 = "thing2"
print("thing1 is", thing1) --> thing1 is thing2
you could use getfenv() but it will not work for local variables
a = 10
b = "epic"
print(getfenv()) -- {["a"] = 10, ["b"] = "epic"}
I know this is weird and seems like a stupid question.
I said this before, that’s why. Just for curiousity
Local variables work differently behind the scenes. They run faster and using them can help to keep your code clean and ensure proper garbage collection.
You might be interested in dictionaries.
local variables = {abc = "hey"}
You can iterate over this to get abc from hey.