Do X every 4 turns.

is there a way to use a Turn script to trigger something every four turns without having to do something like
game.turn=game.turn+1
if game.turn=4 then script and of course resetting turns to 0 at the end of the script.
or is that the only way to do it?
In my example, it basically every 4 turns = a day to pass


I'd say that's the simplest way to do it. Although I'd probably use a modulo rather than resetting the count to zero.

Something like:

if (not HasInt (this, "turns")) this.turns = 0
this.turns = this.turns + 1
if (this.turns % 4 = 0) {
  // code goes here
}

(I used this rather than game because it seems that the turn counter only matters to this particular turnscript. Putting attributes on the object they refer to makes your code more structured, easier for debugging)


Still confused how THIS works though. So bit confused how the code works. where do I add increase the turn number?


In a turnscript, this refers to the turnscript itself. It's a convenient place to put attributes that won't be used elsewhere.
(The same applies to commands; this can be used to store data related to the command)

Somehow I missed the +1 line; easy to make mistakes while typing on my phone. Sorry about that.


This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums