• 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] Castbar System Freezes

Status
Not open for further replies.
Level 4
Joined
Jun 8, 2007
Messages
89
Okay, so I'm making a system to display a cast bar underneath the hero model, but I have run into a problem. It simply freezes when I run it. After a 30 second-ish time period, the game unfreezes again and i can see the Debug messages "Loop" and "%" but none of the other ones. I bet I did something overly nubbish. hehe

Anyway, could anybody help me out a bit?

-Thanks in advance

JASS:
library CastbarDisplaySystemV1

private constant function GetCastbarCharacter takes nothing returns string
    return "]"
endfunction

private constant function GetCastbarSize takes nothing returns real
    return .01
endfunction

struct CastbarData
    unit caster

    real totalCastTime
    real currentTime = 0
    real percentFilled
    
    texttag castbar = CreateTextTag()
    
    string display = ""
    string color
    
        // calculate percentage filled
        // rounds down to the nereast multiple of 5
    method CalculatePercentageFilled takes nothing returns nothing
        set this.percentFilled = I2R(R2I(((this.currentTime/this.totalCastTime)*200)/10))
    endmethod
    
        // setup the display string
    method SetDisplay takes nothing returns nothing
        local integer i = 0
        
            // setup the front of the colored portion
        set this.display = "|cff" + this.color
        
            // filled castbar
        loop
            exitwhen i >= this.percentFilled
            
            set this.display = this.display + GetCastbarCharacter()
            
            set i = i + 1
        endloop
        
            // end the colored portion
        set this.display = this.display + "|r"
        
            // empty castbar
        loop
            exitwhen i >= 20
            
            set this.display = this.display + GetCastbarCharacter()
            
            set i = i + 1
        endloop
            
    endmethod
    
        // Draw the castbar
    method Draw takes nothing returns nothing
        local real xpos = GetUnitX(this.caster)
        local real ypos = GetUnitY(this.caster) - 25.0
        
        call DestroyTextTag(this.castbar)
        set this.castbar = CreateTextTag()

        call SetTextTagText(this.castbar, this.display, GetCastbarSize())
        call SetTextTagPos(this.castbar, xpos, ypos, -15)
        
        call SetTextTagVisibility(this.castbar, false)
        call SetTextTagVisibility(this.castbar, not IsUnitFogged(this.caster, GetLocalPlayer())) 
        
    endmethod
    
        // wait .1 secs -> increment time
    method Wait takes nothing returns nothing
        set this.currentTime = this.currentTime + .025
        call TriggerSleepAction(.025)
    endmethod
endstruct



function CastbarDisplay takes unit caster, real totalCastTime, string color returns nothing
    local CastbarData data  = CastbarData.create()
    local timer t = CreateTimer()
    
    set data.caster         = caster
    set data.totalCastTime  = totalCastTime
    set data.color          = color
    
    loop
        exitwhen data.currentTime >= data.totalCastTime
        
            // calculate the percentage of the bar to be filled
        call data.CalculatePercentageFilled()
        
            // set display
        call data.SetDisplay()
        
            // draw the castbar
        call data.Draw()
        
            // wait and increment time
        call data.Wait()
        
    endloop
    
    call DestroyTextTag(data.castbar)
    call data.destroy()
endfunction

endlibrary

Also, I assume my CastbarData.Wait() function is kind of crappy... How would I go about incorporating a timer instead, I'm not very good with those. =/
 
Last edited:
Level 13
Joined
Nov 22, 2006
Messages
1,260
I'm not sure, but I think these two loops cause the freeze, because you never increase the integer i, so the system freezes:

JASS:
loop
    exitwhen i >= this.percentFilled

    set this.display = this.display + "I"
endloop

JASS:
loop
    exitwhen i >= 10

    set this.display = this.display + "I"
endloop
 
Level 4
Joined
Jun 8, 2007
Messages
89
That was a lot harder for me than it should have been. :hohum:

-Thanks

*Edit*

Made another stupid mistake, Got it fixed though. heh

*End Edit*

-Thanks again
 
Last edited:
Status
Not open for further replies.
Top