Is there a function to call a variable based on the casted value of that variable? Example below…
CODE START
var x = “123”
var temp_var = “x”
print(“VALUE OF X:”, var(temp_var)) # THIS IS THE FUNCTION I’M LOOKING FOR
CODE END
I would hope to see the following print statement:
VALUE OF X: 123
KingGD
2
Can you try this?
print("VALUE OF X: ", get(temp_var))
1 Like
In order for that to work, temp_var
would need to be string property name of the current object - not just any local variable.
1 Like
Have a look at the docs about Evaluating expressions:
2 Likes
Looks like evaluating expressions will do it. Will update this post after testing. Thank you!
This is correct, the full sample works.
var x: int = 123
var temp_var: String = "x"
func _ready() -> void:
print("Value of x is: ", get(temp_var))
2 Likes
KingGD
9
Thanks! I think I just misunderstood @lexpeartha reply for overthinking.
The get() solved it for me! Thank you!