XS Script PlayerNumber affecting wrong player

:arrow_forward: GAME INFORMATION

  • GAME BUILD #: 16124732
  • GAME PLATFORM: Steam
  • OPERATING SYSTEM: Windows 11

:arrow_forward: ISSUE EXPERIENCED

The playerNumber parameter passed in to the xsEffectAmount function does not apply to the correct player when the scenario is started with players out of order.

:arrow_forward: FREQUENCY OF ISSUE

  • 100% of the time

:arrow_forward: REPRODUCTION STEPS

  1. Create a new scenario
  2. Give player 1 and player 2 one castle each.
  3. Create a new trigger with the Script Call effect below:

void setP1CastleAttack() {
const int cPierce = 3;
xsEffectAmount(cAddAttribute, 82, cAttack, cPierce*256 + 50, 1);
}

This script call will add 50 pierce attack to player 1’s castle (unit 82)

  1. Open the scenario in Single Player. Before starting the game, invert the players so that you are 2 (Red) and the AI is 1 (Blue)

  2. When the scenario starts, it will be Player 2 (Red)'s castle that is affected by the script call.

  3. Run the scenario again. This time, play as player 1 (Blue)

  4. This time, Player 1 (Blue)'s castle will be affected by the script call.

:arrow_forward: EXPECTED RESULT

In both cases above, the xsEffectAmount call targeting player 1 should be applied to player 1.

In other words, the playerNumber parameter should be based on the actual in-game player number, instead of being based on the order of players in the game settings / lobby page.

Triggers that target player numbers follow the actual player number, so this causes a misalignment with the XS’s “player number” if players switch colors prior to starting the scenario.

:arrow_forward: IMAGE

Hi there,
This is by design. The order of players in the lobby is, in fact, the real order of players in the game engine. Numbers that are displayed next to players in-game only represent the position in the scenario file.

The reason why it is like this is simple: it might be possible for slots to be absent (i.e there being player colors 1, 2, and 4, but not 3). The ordering ensures that there are no gaps in IDs of players actually playing the game, which is necessary to iterate through players using a for loop in XS.

Unfortunately there is currently no built-in function to convert between Scenario Index and Actual Index. However, workarounds involving the use of trigger effects (which are aware of player positioning) can be used. For example, storing the player number in a special Player Resource.

1 Like