Wisp Creation Bug

Sevion

The DIY Ninja
Reaction score
413
I have a small loop that creates wisps in a + shape. Right now, it only works if I comment out the variable setting lines in the following:

JASS:
    //Wisp Wheel 1
    set x = GetRectCenterX(gg_rct_Wisp_Wheel_1)
    set y = GetRectCenterY(gg_rct_Wisp_Wheel_1)
    loop
        set i = i + 1
        exitwhen i > 4
        loop
            set n = n + 1
            exitwhen n > 8
            call CreateUnit(Player(11), 'wisp', x, y, 270)
            //set Wisps[Index] = bj_lastCreatedUnit
            //set Index = Index + 1
            set x = x + 64 * Cos((90*i) * bj_DEGTORAD)
            set y = y + 64 * Sin((90*i) * bj_DEGTORAD)
        endloop
        set n = 0
        set x = GetRectCenterX(gg_rct_Wisp_Wheel_1)
        set y = GetRectCenterY(gg_rct_Wisp_Wheel_1)
    endloop


If I uncomment:
JASS:
            set Wisps[Index] = bj_lastCreatedUnit
            set Index = Index + 1


It will not work, but if I leave them commented, it works -_-' Anyone know what's going on?
 

Darthfett

Aerospace/Cybersecurity Software Engineer
Reaction score
615
CreateUnit is a native function, and so it does not set bj_lastCreateUnit to it.

Perhaps bj_lastCreatedUnit is null, so it causes your function to end early?

You have to directly set a variable to a native Create function. BJ functions automatically do this, and then they return bj_lastCreateUnit.
 

Sevion

The DIY Ninja
Reaction score
413
I changed it to:
JASS:
    //Wisp Wheel 1
    set x = GetRectCenterX(gg_rct_Wisp_Wheel_1)
    set y = GetRectCenterY(gg_rct_Wisp_Wheel_1)
    loop
        set i = i + 1
        exitwhen i > 4
        loop
            set n = n + 1
            exitwhen n > 8
            set Wisps[Index] = CreateUnit(Player(11), 'wisp', x, y, 270)
            set Index = Index + 1
            set x = x + 64 * Cos((90*i) * bj_DEGTORAD)
            set y = y + 64 * Sin((90*i) * bj_DEGTORAD)
        endloop
        set n = 0
        set x = GetRectCenterX(gg_rct_Wisp_Wheel_1)
        set y = GetRectCenterY(gg_rct_Wisp_Wheel_1)
    endloop


And now it doesn't even create a unit.

It seems that even uncommenting one of the bugging lines (set Wisps and set Index) causes the trigger to stop. I don't see anything wrong with set Index = Index + 1, yet it stops executing.
 

quraji

zap
Reaction score
144
Probably Index has no value.


Also, using polar projection for creating horizontal and vertical lines is a bit silly, eh?

To get points heading west, decrement x by your distance. To get points heading east, increment x by your distance.
To get points heading north, increment y by your distance. To get points heading south, decrement y by your distance.
No trig needed, just addition/subtraction =]
 

Dr.Jack

That's Cap'n to you!
Reaction score
109
> Probably Index has no value.

In other words make sure when declaring index you are setting it to 0.

local integer index = 0

That should solve it.
 

Sevion

The DIY Ninja
Reaction score
413
Not a local, :p but I bet that's the problem. I'll give it a try.

Edit: It's working now.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top