Ask coding questions

← Back to all posts
How do I make variables change after another changes?
LoveFromSkyy (137)

I want the monster of the level to become stronger in terms of hp and attack damage ONLY. I don't want to change the player's stats yet, that's going to be in the beta version How would I make this happen?

Edit: Because every time the player starts a level, LvlCount goes up by one, I want to have monsterHealth and monsterAttacks to get stronger.

Answered by SixBeeps (5353) [earned 5 cycles]
View Answer
SixBeeps (5353)

I don't have much time to look over your code, but from the sounds of it, I think what you want is to set those two variables to be based on LvlCount. You can do something like this:

monster.monsterHealth = 20 + LvlCount * 2;
monster.monsterAttacks = 1 + LvlCount;

Of course, you'd adjust these parameters to your liking, but something like that should work.

LoveFromSkyy (137)

Thank you, this helps a ton!
Have a nice day, @SixBeeps

Baconman321 (1104)

I actually had to do this too.

I finally settled around getters and setters.

Basically I have a class or an object that has a setter.

Instead of changing the value directly, you fire the setter (by changing the setter's value it will do stuff with that value) and then the setter changes the variables you want to change.

Of course, this isn't efficient in your scenario. I recommend sixbeep's answer for this one.