• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[JASS] GetUnitState() causes thread crash?

Status
Not open for further replies.
Level 9
Joined
Nov 28, 2008
Messages
704
Alright, Ive got a fairly minor problem blocking me from completeing a spell.

using GetUnitState() in a function, or setting a variable to it, causes it to be null. This unit HAS mana, it is NOT null (checked this, debugging with those ever so useful BJDebugMsg()'s..

heres a lil bit of codes.

JASS:
    static method Move takes nothing returns nothing
        local LBD lbd
        local integer i = LightningBallCounter
        local real x
        local real y
        local integer ii
        local real distance
        local real manaCheck = 0
        
        loop
            set lbd = Lbd[i]
            set x = GetUnitX(lbd.Dummy) + lbd.Speed * lbd.Cosine
            set y = GetUnitY(lbd.Dummy) + lbd.Speed * lbd.Sine
            
            call SetUnitX(lbd.Dummy, x)
            call SetUnitY(lbd.Dummy, y)
            call SetUnitX(lbd.Unit, x)
            call SetUnitY(lbd.Unit, y)
            call SetUnitX(lbd.FXDummy, x)
            call SetUnitY(lbd.FXDummy, y)
            
            set manaCheck = GetUnitState(lbd.Unit, UNIT_STATE_MANA) //I reutrn null. However, SetUnitState does work.
            set lbd.Speed = lbd.Speed + lbd.SpeedIncrease
            
            call MoveLightning(lbd.Bolt, true, lbd.OriginalX, lbd.OriginalY, x, y)
            
            call SetUnitState(lbd.Unit, UNIT_STATE_MANA , GetUnitState(lbd.Unit, UNIT_STATE_MANA) - lbd.ManaCost) //I work, breaking the laws of physics.
            
            set distance = SquareRoot((lbd.DestinationX - x) * (lbd.DestinationX - x) + (lbd.DestinationY - y) * (lbd.DestinationY - y)) 
            
            if manaCheck == null then
                call BJDebugMsg("Roar!")    //I trigger lots!
            endif
            
            if manaCheck < 1 then//distance < lbd.Speed * 5 then  //I only work when the mana is in fact below 0. Otherwise, I crash this thread, causing no knockbacks to happen anymoar.
                call lbd.destroy()
                if LightningBallCounter == -1 then
                    call PauseTimer(LBDTimer)
                endif
                set ii = i
                loop
                    exitwhen i > LightningBallCounter
                    set Lbd[ii + 1] = Lbd[i]
                    set ii = ii + 1
                endloop
            endif
            set i = i - 1
        endloop
            
    endmethod

In using the SetUnitState(), it causes the unit to lose the mana correctly. WTH, much?

Setting it to the real causes the real to be null, causing the crash in the if. This is part of a knockback timer, by the way. After it checks the manaCheck, and finds it null.. crash. Timer does not run, no knockback.

Suggestions, anyone?
 
Level 14
Joined
Nov 23, 2008
Messages
187
Hmm, I think, you have at least two mistakes in your code.

1. You have no exitwhen condition in outer loop. Should be like that:

JASS:
// . . .
  set i = i - 1
  exitwhen i <= 0
  // or just exitwhen i < 0
  // if numeration of indexes starts from 0
endloop

2. You have wrong exitwhen condition in inner loop. It uses i instead of ii. Should be like that:

JASS:
                set ii = i
                loop
                    exitwhen ii > LightningBallCounter
                    set Lbd[ii + 1] = Lbd[i]
                    set ii = ii + 1
                endloop

Also, check, if lbd.Unit is not null.
 
Status
Not open for further replies.
Top