[CW3] CONST_COORDX/Y acting differently based on game speed

Grabz · 879


  • Community Guild
  • *****
    • Posts: 186
  • Where will you be when the creeper waves hit?
In one of my recent mapping templates, I ran into a glitch that would make the game behave differently on 1x speed compared to 4x speed.

I've included a stripped down version of my template in the attachment. What it does: Whenever you build a Collector, it will turn into a random enemy unit. If the enemy unit is destroyed, its Power Zone is also destroyed.

First, two tests. Open the save, let the game run until the Collectors are built. Then, place Nullifiers. When the Nullifiers are about to destroy enemy units:
  • If you run the game on 1X, the PZ's aren't destroyed. The trace in top left outputs 1, 1.
  • If you run the game on 4X, the PZ's are destroyed. The trace in top left outputs unit coordinates.

Relevant bit of code from the script:
Code: [Select]
#<-list is a list of enemy UIDs spawned from collectors

0 ->i
<-list GetListCount 0 do
<-list <-i GetListElement ->unit

<-unit CONST_ISDESTROYED GetUnitAttribute if
<-list <-i RemoveListElement
<-i 1 sub ->i

<-unit CONST_COORDX GetUnitAttribute ->x
<-unit CONST_COORDY GetUnitAttribute ->y

<-x <-y Trace2
<-x <-y 0 TRUE GetAllUnitsInRange 0 do

<-unit GetUnitType "POWERZONE" eq if
<-unit 0 Destroy

<-i 1 add ->i

My theory:

When a unit is destroyed, its CONST_COORDX and CONST_COORDY are set to (-1,-1) at the end of a visual frame, not at the end of a logic frame, which is incorrect behaviour. This means that when the game is running on 4X, playing four logic frames per single visual frame, if a unit is destroyed on either logic frame that isn't the last one, the next logic frame can still fetch the unchanged coordinates. If the game is instead running on 1X, a visual frame is played right after the logic frame, setting the coordinates to (-1,-1) making it impossible to retrieve the old unit coordinates on the next logic frame with this solution.

I don't expect the bug to be fixed, but I just wanted to point it out to make sure it doesn't happen in CW4.