hello, can anyone tell me how to increase the values of all the children contained in a structure?
what you see in the image below are the damage values of the weapons contained in my game
I would like that when the player activates a certain power up the values of all weapons are increased but only for a certain period.
when the time of the powerup ends the values return to the origin again
The easiest way would be to use a multiplier variable. Set the variable to 1. Then when the powerup is collected, change it to say 1.1 for a 10 percent increase. Start a timer. When the time reaches the limit then delete the timer and set the variable back to 1
If you’re using the health behavior then apply a damage of the weapon value times the variable.
A more flixible approach would be to use variable with both values. You could use 2 structure, one with 2 lists of weapons. Or you could use a list of weapons that have 2 children, one for the basic and one for the powerup.
You would then build the object name dynamically using a variable for the child name, similar to how I’m assuming you’re getting the current value.
The array approach would be more complex but would allow you to use different levels of increase.
To subtract an extra 10% just multiply bullets.damage by 1.1. But as @Keith_1357 wrote, you should put that damage multiplier in a variable (say named damageMultiplier) so the damage formula becomes bullets.damage * damageMultiplier.
So in your case, say the current weapon’s name is stored in the variable currentWeapon, it would be danno[currentWeapon] * damageMultiplier.
so i put the value 10 to “damage multiplier” in a variable and multiplied when the enemy is hit “bullets.damage * damage multiplier” but it doesn’t work.
where am i going wrong this time?
Do all the projectiles or weapons have the variable damage? If not, that may be causing the error. You can try fixing it by adding the damage variable to the object group.
BTW, what is the error message from the red underline?
I think that’s the wrong thing to do - you should work out why it’s wrong, because the reason could give problems elsewhere. The clue is in the error text: