2k/3 2k3: Store "number of present enemies" in a variable.

Version used: 2003 v1.12a

1777137963511.png


Desired result: Number of present enemies is stored in a variable, in my Battle-Start battle event.

1777138253355.png


Manually adding or removing variable assignments strikes me as both tedious and foolish.

That seems like a great way to make editing troops a pain, or to even enjoy random crashes when a battle event checks for Enemy 5's data in a four-enemy troop.

The fact that checking a missing enemy's data using a variable assignment or a conditional branch causes a crash instead of just skipping that assignment is what's stopping me from proceeding.

If I could store enemy count, I could easily use common events to check every enemy for a "Scanned" status, say. And I could do it by just pasting my common-event-calling battle event into each troop, without having to adjust it.

Is this possible without patches, or at least without switching the entire project to Maniacs? Working under 2k3's restrictions to keep my scope narrow is part of my goal.
But each troop is a static value, couldn't you simply insert the value before calling the Common Event?

When I try to copy the events page to the Common Event, I will receive a warning (Message box), and it will look like this:
Spoiler: COMMON EVENT
Code:
@> Control Variables: [0001] = 0
@> Conditional Branch: [1:?] can move
  @> Control Variables: [0001] += 1
  @>
 : Branch End
@> Conditional Branch: [2:?] can move
  @> Control Variables: [0001] += 1
  @>
 : Branch End
@> Conditional Branch: [3:?] can move
  @> Control Variables: [0001] += 1
  @>
 : Branch End
@> Conditional Branch: [4:?] can move
  @> Control Variables: [0001] += 1
  @>
 : Branch End
@> Conditional Branch: [5:?] can move
  @> Control Variables: [0001] += 1
  @>
 : Branch End
@> Conditional Branch: [6:?] can move
  @> Control Variables: [0001] += 1
  @>
 : Branch End
@> Conditional Branch: [7:?] can move
  @> Control Variables: [0001] += 1
  @>
 : Branch End
@> Conditional Branch: [8:?] can move
  @> Control Variables: [0001] += 1
  @>
 : Branch End
@> Text: Troops size: \v[1]

Edited:
However, if you define the number of enemies before calling the event and add a condition for each one that ensures the non-existent enemy is never read, it will work:
1777140927856.png


The entire event must be created on a battle page and then copied to the regular event, as we don't have access to certain parameters outside of the battle editor:
Code:
@> Conditional Branch: Variable [0001:EnemyExist?] >= 1
  @> Conditional Branch: [1:?] can move
    @> Control Variables: [0011:Scan-HP] = [2:?]'s HP
    @>
   : Branch End
  @>
 : Branch End
@> Conditional Branch: Variable [0001:EnemyExist?] >= 2
  @> Conditional Branch: [2:?] can move
    @> Control Variables: [0011:Scan-HP] = [2:?]'s HP
    @>
   : Branch End
  @>
 : Branch End
@> Conditional Branch: Variable [0001:EnemyExist?] >= 3
  @> Conditional Branch: [3:?] can move
    @> Control Variables: [0011:Scan-HP] = [3:?]'s HP
    @>
   : Branch End
  @>
 : Branch End
@> Conditional Branch: Variable [0001:EnemyExist?] >= 4
  @> Conditional Branch: [4:?] can move
    @> Control Variables: [0011:Scan-HP] = [4:?]'s HP
    @>
   : Branch End
  @>
 : Branch End
@> Conditional Branch: Variable [0001:EnemyExist?] >= 5
  @> Conditional Branch: [5:?] can move
    @> Control Variables: [0011:Scan-HP] = [5:?]'s HP
    @>
   : Branch End
  @>
 : Branch End
@> Conditional Branch: Variable [0001:EnemyExist?] >= 6
  @> Conditional Branch: [6:?] can move
    @> Control Variables: [0011:Scan-HP] = [6:?]'s HP
    @>
   : Branch End
  @>
 : Branch End
@> Conditional Branch: Variable [0001:EnemyExist?] >= 7
  @> Conditional Branch: [7:?] can move
    @> Control Variables: [0011:Scan-HP] = [7:?]'s HP
    @>
   : Branch End
  @>
 : Branch End
@> Conditional Branch: Variable [0001:EnemyExist?] == 8
  @> Conditional Branch: [8:?] can move
    @> Control Variables: [0011:Scan-HP] = [8:?]'s HP
    @>
   : Branch End
  @>
 : Branch End
I don't know much about 2k3, but… isn't the number of enemies in the troop just a known constant? I mean, if you're working in troop 12 which has 4 enemies, then you already know there are exactly 4 enemies. And if you're working in troop 46 that has 2 enemies, you know there are 2 enemies.

Unless there's some kind of "base troop" situation going on here (but I didn't think 2k3 supported anything like that?) or a common event, I think you can just make the code for 8 enemies, copy-paste it to every troop, and delete the cases in each troop for enemies that don't exist. And if it is a common event you can set the variable to that known value before calling the common event. Pretty much what @Dev_With_Coffee said, really.
Thanks for taking the time to reply.

To be clear:
- It's very easy to assign "6" to a Troop Size variable at the start of a troop's events.
- It's also very easy to forget to update that variable when adjusting a troop.
- It's also very easy, having made such an error, for that troop to never appear while testing a dungeon, or to never use an event-driven command targeting the missing enemy slot in that particular troop.

Which, all together, means it's very easy to publish with a troop that will cause crashes.

All it would take is deciding that (example) a boss needs two minions, down from three.

I wanted to see if there was a way to let events adjust dynamically, so I wouldn't have to worry about this. Does that clarify the goal?
Yes, that had already become clear, the fact is that the developers in 2003 didn't think about it.

What I showed would easily solve the problem, since you would only need to worry about the first page starting from the first turn, leaving the variable at the top so it can be visible.

It's still routine to modify a troop and then test it.
Okay, the answer would be "There isn't a trick you're overlooking; you'll have to set it by hand."

Thanks again for your time.
This type of response doesn't exactly clarify why it's not possible, nor does it help to improve things. Sometimes a simple method can be explained in a conversation like this.

That's why I always try to show the methods I've used or still use to make my work easier.


For example, a user on an old forum asked how to modify the text speed of dialogues without having to create multiple Conditional Branches, so I or another user posted something that nobody realized would work:
\s[\v[10]]
A variable will always be numeric, so if you put that at the beginning of the text and create a configuration menu for the player to change the variable's value, it will work.
Thanks for taking the time to reply.

To be clear:
- It's very easy to assign "6" to a Troop Size variable at the start of a troop's events.
- It's also very easy to forget to update that variable when adjusting a troop.
- It's also very easy, having made such an error, for that troop to never appear while testing a dungeon, or to never use an event-driven command targeting the missing enemy slot in that particular troop.

Which, all together, means it's very easy to publish with a troop that will cause crashes.

All it would take is deciding that (example) a boss needs two minions, down from three.

I wanted to see if there was a way to let events adjust dynamically, so I wouldn't have to worry about this. Does that clarify the goal?
If it's just crashes you're worried about, there's an easy way to avoid the crashes. It won't make troops work correctly if you forgot to set the variable, but at least it won't execute code that'll crash.

All you need to do is make the common event set the variable to 0 when it's finished its work.

Of course, that does mean that nothing else in the battle can reference the variable; but if you need that, you can probably just have the common event transfer the value to a different variable before setting the other variable to 0, and anything else in battle events checks the new variable instead.

Original thread: https://forums.rpgmakerweb.com/threads/2k3-store-number-of-present-enemies-in-a-variable.183389/