How do i change a variable dynamically

in my code, i want to change the variable: room_dex[active_room][active_enemies[Enemy.ID]].hp. however, the action: “change variable value” does not allow such an expression. i tried to find something about this, but couldn’t. how do i do this.

For sure there should be no dot on end

sorry for the misconception, that isnt part of the expression, its just a period to mark the end of the sentence

I suck with proper formating

Try

room_dex[active_room][active_enemies[Enemy.ID]]hp

If that don’t work tell me what each variable is
But also can you build it part by part and tell me when you start to see red error?

1 Like

ZeroX4, the problem he’s having is that “Change Variable Value” will literally look for a child named “active_room” instead of checking the variable active_room’s value. Same with active_enemies, Enemy.ID, etc.

SnowyRawrGamer, It will only look for a child named active_room if active_room is in quotes or active_room is a string variable which contained active_room

ZeroX4, You do need the last period before hp

When you replace a child variable name with a dynamic name in brackets, you only remove the preceding period.

Make sure all of the variables used to build the variable dynamically are declared and spelled correctly including the case.

If the child is a structure, make sure the variable used to point to it is a string. If the child is an array, make sure it returns a number.

I stand corrected. Tried this out just now and worked perfectly.

I remember trying to do this while making an extension, and didn’t seem to work then but maybe something has changed.

1 Like

it works, thanks for the help!

1 Like