Author Topic: [Solved] "BattleGame.getTurnSide" vs "side"  (Read 2585 times)

Offline The Martian

  • Commander
  • *****
  • Posts: 754
  • "It implores you to listen to its arguments..."
    • View Profile
[Solved] "BattleGame.getTurnSide" vs "side"
« on: October 08, 2021, 06:49:54 am »
I was going to try using BattleGame.getTurnSide to determine which side (X-Com, Aliens, Civilians) is currently active, but then I noticed the variable "side" in the openxcom.log...

And thus I have two questions:

(Question #1)
What are the values that BattleGame.getTurnSide and "side" can possess?

For example I've seen this code in existing scripts which leads me to believe that X-Com may have a value of 0 and then the aliens would have 1 as their turn "side" value.
Code: [Select]
          # Make sure this doesn't run an extra time when civilians have a turn
          if eq side 2;
            return;
          end;


(Question #2)
So long as the script hook (For example: damageUnit: or newTurnUnit:) supports both "side" and BattleGame.getTurnSide is there a reason to use one over the other?

(If I'm using the wrong description and these commands aren't know as 'script hooks' please let me know, I'm still learning the terminology.)




« Last Edit: February 12, 2023, 03:08:48 pm by Meridian »

Offline The Martian

  • Commander
  • *****
  • Posts: 754
  • "It implores you to listen to its arguments..."
    • View Profile
Re: "BattleGame.getTurnSide" vs "side"
« Reply #1 on: October 08, 2021, 01:55:49 pm »
I thought that placing this at the beginning of the newTurnUnit: section of the script's code block would cause it to only run for a unit during their own turn.
Code: [Select]
         # [=] Only run during their own turn [=] (In theory)
          if and neq BattleGame.getTurnSide unit.getFaction;
            return;
          end;

But it doesn't seem to be working.

(Example Mod)
TestModStatusEffects V1-7c.zip

Basically the 'poison' effect is tripling as it runs during the X-Com, Aliens & Civilian phase and I'm trying to make it only run once per game turn instead
« Last Edit: October 08, 2021, 02:16:39 pm by The Martian »

Offline Yankes

  • Global Moderator
  • Commander
  • *****
  • Posts: 3350
    • View Profile
Re: "BattleGame.getTurnSide" vs "side"
« Reply #2 on: October 08, 2021, 02:12:42 pm »
I thought that placing this at the beginning of the newTurnUnit: section of the script's code block would cause it to only run for a unit during their own turn.
Code: [Select]
         # [=] Only run during their own turn [=] (In theory)
          if and neq BattleGame.getTurnSide Unit.getFaction;
            return;
          end;

But it doesn't seem to be working.
Error message should say explicitly why it not wok, `BattleGame.getTurnSide` is not variable, this is operation, and rule is that only one operation per line is allowed, and in this line `if` is operation.

For `side` in `damageUnit` its mean "side direction" of unit, where in `newTurnUnit` it mean "side of conflict" aka `0`- human, `1` - aliens, `2` - civilians.

Offline The Martian

  • Commander
  • *****
  • Posts: 754
  • "It implores you to listen to its arguments..."
    • View Profile
Re: "BattleGame.getTurnSide" vs "side"
« Reply #3 on: October 08, 2021, 03:15:11 pm »
That did it!

Thank you!


I changed the code to run off the "side" variable instead and it appears to be working correctly.

Code: [Select]
          var int currentUnitSide;

          # [=] Only run during their own turn [=]
          unit.getFaction currentUnitSide;

          if neq side currentUnitSide;
            return;
          end;




I also tried without success using BattleGame.getTurnSide and unit.getFaction to pass the values to variables first:

Code: [Select]
          var int currentTurnSide;
          var int currentUnitSide;

          # [=] Only run during their own turn [=] (In theory)
          BattleGame.getTurnSide currentTurnSide;
          unit.getFaction currentUnitSide;

          if neq currentTurnSide currentUnitSide;
            return;
          end;

But that produced this error.

Code: [Select]
[08-10-2021_05-52-12] [ERROR] Can't match overload for operator 'BattleGame.getTurnSide' for:
[08-10-2021_05-52-12] [ERROR]   [var int]
[08-10-2021_05-52-12] [ERROR] Expected:
[08-10-2021_05-52-12] [ERROR]   [ptr BattleGame] [var int]
[08-10-2021_05-52-12] [ERROR] Error in parsing script 'newTurnUnit' for 'Global Event Script': invalid operation in line: 'BattleGame.getTurnSide currentTurnSide;'


Although I'm not using the BattleGame.getTurnSide unit.getFaction version I'm still interested in understanding what went wrong with it so as to avoid repeating the error.

Both variables are defined before the section of code that assigns them a value and only the variables are now used in the IF comparison line instead of the .get operations.

The error message seems to read that the line where BattleGame.getTurnSide assigns its value to the currentTurnSide variable is the problem.

If I'm reading it correctly the verbose version of the openxcom.log's newTurnUnit section list BattleGame.getTurnSide as requiring only the variable it assigns its value to.

Code: [Select]
Name: BattleGame.getTurnSide                  Args: [ptr BattleGame] [var int]                        Desc: Return the faction whose turn it is.
How should I have phrase this line instead?
Code: [Select]
          BattleGame.getTurnSide currentTurnSide;

(Fixed version of the example mod) (Uses "side" variable.)
TestModStatusEffects (Fixed).zip

(Broken version of the example mod) (Uses BattleGame.getTurnSide)
TestModStatusEffects (Broken).zip

Offline Yankes

  • Global Moderator
  • Commander
  • *****
  • Posts: 3350
    • View Profile
Re: "BattleGame.getTurnSide" vs "side"
« Reply #4 on: October 08, 2021, 04:25:04 pm »
Required arguments are:
Code: [Select]
[ptr BattleGame] [var int]
and you only supply `currentTurnSide` aka `[var int]`, where is `[ptr BattleGame]`?

to correctly call this operation you need have value of type `BattleGame` and you do not supply it, correct version is:
Code: [Select]
BattleGame.getTurnSide battle_game currentTurnSide;
or using simplified version:
Code: [Select]
battle_game.getTurnSide currentTurnSide;

Offline The Martian

  • Commander
  • *****
  • Posts: 754
  • "It implores you to listen to its arguments..."
    • View Profile
Re: "BattleGame.getTurnSide" vs "side"
« Reply #5 on: October 09, 2021, 11:28:10 am »
I think that I understand now.

The reason unit.getHealth doesn't need to be written as "BattleUnit.getHealth battle_unit VarInt;" and can instead be written "unit.getHealth VarInt;" is because the "newTurnUnit" script hook has a variable called "unit" already defined in the "Script data:" section which is assigned the values held in BattleUnit.
Code: [Select]
Name: unit                                    ptre      BattleUnit
Just as newTurnUnit has a similar variable defined in its "Script data:" called battle_game.
Code: [Select]
Name: battle_game                             ptre      BattleGame

My mistake was thinking when Args: listed [ptr BattleGame] that "BattleGame.getTurnSide" itself was the [ptr BattleGame] instead of a command requiring two items to act on.
Code: [Select]
Name: BattleGame.getTurnSide                  Args: [ptr BattleGame] [var int]                        Desc: Return the faction whose turn it is.

Thank you for explaining that.