Help with a variable check

So, I’m a complete newbie to programming, and I’m trying my hand at choicescript.
Today, I was faced with a situation: I wanted to make a variable check. Basically: we have two repeatable labels, one where you attack and another where the enemy attacks. There is a limited amount of enemies which you have to defeat, and when that happens, the loop between attack and defense ends and you go to another label.

I’m just having a doubt here. I did this:
image

Basically, I created a temporary variable called “battle”. If, when you return to the attack label, the enemies are all defeated, it can’t repeat. So, for that, there is this code up there: if, when you return to this label, the variable in regards to the knights, archers and mages is equal to zero, meaning all of them were defeated, you increase battle in +1. If battle reaches three, meaning all of them were reduced to zero, you skip the attack label and go to the next part of the scene.

However, I’m quite sure this actually makes it so that check is repeated every time the label starts? Basically, that means Battle would reach 3 before all variables reached zero, or even surpass three.

I don’t know if that’s right, but it is what my logic seems to account for. Can anyone help me with this? If this is indeed the case, can you suggest to me some way to still make that check, but not repeating it? I’ll appreciate your help!

*label fight_init
*temp battle 0
*set battle + sdr_knights
*set battle + sdr_archers
*set battle + sdr_mages

*goto battle_1

*label battle_1
*if battle = 0
  *goto sdr_ending
*else
  *goto continue_battle

*label continue_battle
And here comes the code for the battle where you do
*set battle -1
each time a sdr_xxx dies.
and then
*goto battle_1

Something like that?

Also, my game has a couple of battles in it, you can check that if you want, maybe there’s something useful for you there.

1 Like

Just reset the value of battle at the start of the label, or skip it completely and check if there are still any enemies left.

Option 1:

*label sdr_final
*set battle 0
.
.
.

Option 2:

*label sdr_final
*if ((sdr_knights + sdr_archers) + sdr_mages) = 0)
    *goto sdr_ending
. 
. 
. 
1 Like

Does ChoiceScript actually use +=?

1 Like

Nope. That’s a Python thing. Sorry, lost in translation :woozy_face:

1 Like

Thank you to both of you! I’m going to test it all out.

1 Like