Is there a way to use a variable to change another variable

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By swordofbling

I don’t know how to explain it but I have a variable called powerup that will change and whenever I get this powerup I want to set that variable to true. E.g. I have a variable called shield_powerup = false and I have a variable powerup = “shield” and I use this get(str2var(str(powerup) + "_powerup")) = true to get the variable shield_powerup but it says I can’t assign to an expression.

If someone could help me I would greatly appreciate it.

:bust_in_silhouette: Reply From: leo-pnt

Not sure if I understood correctly but maybe you can find an other way of getting the powerup change.

func on_powerup_change(powerup):
    if powerup == "shield":
        shield_powerup = true
    # [...] Then all the other cases

Then you can call that function instead of using that “get”

I could do that but I just did not want to make a case for each powerup that exists and was hoping for a shorter method.

swordofbling | 2020-11-12 16:07