Property not set during loop

Discuss macro implementations, ask for macro help (to share your creations, see User Creations, probably either Campaign Frameworks or Drop-in Resources).

Moderators: dorpond, trevor, Azhrei, giliath, jay, Mr.Ice

Post Reply
xavram
Dragon
Posts: 891
Joined: Tue Apr 20, 2010 8:22 pm

Property not set during loop

Post by xavram »

So at the end of a turn, this macro runs...

Code: Select all

[h : allPCs = getPC()]
[FOREACH(pc, allPCs, "<br>"), code : {
  [h : CheckBurnMods(pc)]
  [h : switchToken(pc)]
  [h : setState("FiringOrdersIn", 0)]
  [h : setState("MovementDone", 0)]
  [h : setProperty("SpeedChangeThisTurn", 0, pc)]
  [h : setProperty("FiredThisTurn", 0, pc)]
  [h : setProperty("FiringPenaltyForTurn", 0, pc)]
  [h : airfoilBonus = 0]
  [h, if(CurrentSpeed >= 60 && (Spoiler ==1 || Airdam == 1)) : airfoilBonus = 1] 

  [h : setProperty("CurrentHC", Sum(CurrentHC, airfoilBonus, max(1, BaseHC)), pc)]
  [h : maxHC = Sum(airfoilBonus, getProperty("BaseHC"))]

  [h, if(getProperty("CurrentHC", pc) > maxHC) : setProperty("CurrentHC", maxHC, pc)]

  [h, if(EngineTransHit == 1), code : {
  	[h : BaseMaxSpeed = max(0, Sum(BaseMaxSpeed,-10))]
  	[h : MaxSpeed = max(0, Sum(MaxSpeed,-10))]
	[h : MaxAcceleration = max(0, Sum(MaxAcceleration, -5))]
	[broadcast("<b>" + getName(pc) + "</b> has a damaged transmission, so top speed is reduced down to " + CurrentSpeed + " and max acceleration drops by 5!")]  
  }]

  [h, if(CurrentSpeed > MaxSpeed), code : {
	[h : CurrentSpeed = max(MaxSpeed, Sum(CurrentSpeed,-20))]
	[broadcast("<b>" + getName(pc) + "</b> is travelling over its max speed, so speed is reduced down to " + CurrentSpeed)]
  }]

  [h, If(EngineDP <= 0 || DriverDP <= 0) : reduceSpeed = 1; reduceSpeed = 0]
  [h, if(reduceSpeed == 1 && CurrentSpeed > 0), code : {
	[h : CurrentSpeed = max(0, Sum(CurrentSpeed,-20))]
	[broadcast("<b>" + getName(pc) + "</b> has a destroyed engine or dead driver, so speed is reduced down to " + CurrentSpeed)]  
  }]

  [h, if(SustainedOn == CurrentTarget && CurrentTarget != ""), code : {
	[h : SustainedBonus = min(2, Sum(SustainedBonus,1))]	
  };
  {
	[h : SustainedBonus = 0]
  }]
  [h : CurrentTarget = ""]

  [h : modInit = Sum(CurrentSpeed, (1d99/100))]
  [h : setInitiative(modInit)]
}]

[h : broadcast("<b>All cars regain HC equal to their base HC!</b>")]
[h : sortInitiative()]
[h : setCurrentInitiative(0)]
[h : setInitiativeRound(1)]

[h : foundMovement = 0]
[h, while(foundMovement == 0), code : {
	[h : nextInitiative()]
	[h : initId = getInitiativeToken()]
	[h, if(getName(initId) == "Movement") : foundMovement = 1]
}]
The part that seems to be having an issue is towards the top, these 3 lines.
[h : setProperty("SpeedChangeThisTurn", 0, pc)]
[h : setProperty("FiredThisTurn", 0, pc)]
[h : setProperty("FiringPenaltyForTurn", 0, pc)]

These are not getting zero'd out for the player tokens; they are keeping their current values, whatever those are, instead.

This macro runs when all the players have signalled that they are "done" and I know its in fact running, since the broadcast messages are all coming through. Also, I can see the values being set in the logging file.

If I MANUALLY run the macro (ie, click the button), then the properties are all set correctly. Any ideas why?

Have also tried changing the "setProperty" to "resetProperty" (since 0 is what it defaults to), same thing, doesn't reset them to 0.

xavram
Dragon
Posts: 891
Joined: Tue Apr 20, 2010 8:22 pm

Re: Property not set during loop

Post by xavram »

To make this easier to diagnose, I simplified the macro to...

Code: Select all

[h : allPCs = getPC()]
[FOREACH(pc, allPCs, "<br>"), code : {
  [h : switchToken(pc)]
  [h : setState("FiringOrdersIn", 0)]
  [h : setState("MovementDone", 0)]
  [h : setProperty("SpeedChangeThisTurn", 0, pc)]
  [h : setProperty("FiredThisTurn", 0, pc)]
  [h : setProperty("FiringPenaltyForTurn", 0, pc)]
}]

[h : broadcast("<b>All cars regain HC equal to their base HC!</b>")]
[h : sortInitiative()]
[h : setCurrentInitiative(0)]
[h : setInitiativeRound(1)]

[h : foundMovement = 0]
[h, while(foundMovement == 0), code : {
	[h : nextInitiative()]
	[h : initId = getInitiativeToken()]
	[h, if(getName(initId) == "Movement") : foundMovement = 1]
}]
Again, I see the broad casts, the initiative board gets set right, and those states get back to "false". But the properties don't get set to zero.

User avatar
aliasmask
RPTools Team
Posts: 9024
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: Property not set during loop

Post by aliasmask »

It's an MT timing thing with the token draw. When you sort the initiative states may be undone. I try to avoid setting states and messing with the initiative in one macro. I would try the sort later and with a deferred macro set the states for each token. See Wiki: execLink(). Even that may not work.

xavram
Dragon
Posts: 891
Joined: Tue Apr 20, 2010 8:22 pm

Re: Property not set during loop

Post by xavram »

The states are working as desired, no problems there. its the properties that I'm having an issue with.

I guess I could try the same thing without re-sorting the initiative and see if the properties get set. But you would think setting property values wouldn't have anything to do with "drawing".

xavram
Dragon
Posts: 891
Joined: Tue Apr 20, 2010 8:22 pm

Re: Property not set during loop

Post by xavram »

I think I figured it out, looks like I was calling the sortInitiative twice under certain circumstances. Once I fixed that, then it seems that the properties are now setting correctly.

Post Reply

Return to “Macros”