HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Indexing failure

05-15-2009, 02:30 PM#1
Vestras
This debug msg always displays 0: call BJDebugMsg(I2S(h) (in static method create in struct sndx)

Why?

Collapse JASS:
library vSndx initializer DurationConfigVX

    globals
     private constant real EPSILON        = 0.000001
     
     private constant real TIMER_INTERVAL = 0.03
     //* Interval of static timer which updates sounds
     public real array SOUND_DURATIONS 
     //* configurable in function DurationConfigVX
    endglobals

    private function DurationConfigVX takes nothing returns nothing
        set SOUND_DURATIONS[S2I("")] = 0. //* <-- This line must not be deleted!!
        
        //* set sound durations here
        //* form: set SOUND_DURATIONS[S2I(mySoundFile)] = duration
        set SOUND_DURATIONS[S2I("Abilities\\Spells\\Demon\\RainOfFire\\RainOfFireTarget1.wav")] = 3.
        set SOUND_DURATIONS[S2I("Abilities\\Spells\\Demon\\RainOfFire\\RainOfFireTarget2.wav")] = 3.
        set SOUND_DURATIONS[S2I("Abilities\\Spells\\Demon\\RainOfFire\\RainOfFireTarget3.wav")] = 3.
    endfunction

    //* start of system code
    
    struct sndx
     private  sound  snd=null
     private   real temp=0.
     private   real sndC=0.
     private boolean use=false
     
     //* sndx setup
     real          durEx //* use only if you don't want to use the default SOUND_DURATION
     string         file
     boolean     looping
     boolean        is3D
     boolean playLocally
     boolean     fadeOut
     integer  fadeInRate
     integer fadeOutRate
     integer         vol
     unit     attachUnit
     player    toPlayFor
     
     real x
     real y
     real z
     
     real velX
     real velY
     real velZ
     
     static boolean array Playing
     static    sndx array   Sndxz
     
     //*
     static integer    SoundCount=0
     static   timer    SoundTimer=CreateTimer()
     
     //* for searching
     static sndx array searchSndx
     
     //* for debug
     debug static integer PlayCount=0
     
        private method playEx takes nothing returns nothing
            if (sndx.Playing[this]==false) then
                if (.snd==null) then
                    set .snd=CreateSound(.file,.looping,.is3D,false,.fadeInRate,.fadeOutRate,"")
                endif
                
                call SetSoundVolume(.snd,.vol)
                call SetSoundVelocity(.snd,.velX,.velY,.velZ)
                
                if (.attachUnit!=null) then
                    call AttachSoundToUnit(.snd,.attachUnit)
                else
                    call SetSoundPosition(.snd,.x,.y,.z)
                endif
                
                if (.use==true) then
                    set .durEx=.temp
                endif
                
                set sndx.Playing[this]=true
                if (GetLocalPlayer()==.toPlayFor) and (.playLocally) then
                    call StartSound(.snd)
                else
                    call StartSound(.snd)
                endif
                
                debug   set sndx.PlayCount=(sndx.PlayCount+1)
                debug   call BJDebugMsg("vSndx - playing sounds: "+I2S(sndx.PlayCount))
                
                set sndx.SoundCount=(sndx.SoundCount+1)
                set sndx.Sndxz[sndx.SoundCount]=this
                
                if (sndx.SoundCount==1) then
                    call TimerStart(.SoundTimer,TIMER_INTERVAL,true,function sndx.update)
                endif
            endif
        endmethod
     
        method play takes nothing returns nothing
         local integer s=S2I(.file)
         
            if (SOUND_DURATIONS[s]>0) and (.durEx==-1.) then
                set .use=true
                set .temp=.durEx
                set .durEx=(SOUND_DURATIONS[s]+EPSILON)
            else
                set .use=false
            endif
            
            call .playEx()
        endmethod
        
        private static method update takes nothing returns nothing
         local sndx s
         local integer i=0
         
            loop
                exitwhen (i>.SoundCount)
                set s=.Sndxz[i]
                set s.sndC=(s.sndC+TIMER_INTERVAL)
                
                if (s.sndC>=s.durEx) then
                    set .Playing[s]=false
                    call StopSound(s.snd,false,s.fadeOut)
                    
                    debug   set .PlayCount=(.PlayCount-1)
                    debug   call BJDebugMsg("vSndx - playing sounds: "+I2S(.PlayCount))
                    
                    set .Sndxz[i]=.Sndxz[.SoundCount]
                    set .SoundCount=(.SoundCount-1)
                    if (.SoundCount==0) then
                        call PauseTimer(.SoundTimer)
                    endif
                endif
                set i=(i+1)
            endloop
        endmethod
        
        static method create takes string file returns sndx
         local sndx s
         local integer h=S2I(file)
         
            if (.searchSndx[h]!=0) then
                set s=.searchSndx[h]
            else
                set s=sndx.allocate()
                set s.file=file
                set .searchSndx[h]=s
            endif
         
            set .Playing[s]=false
            call BJDebugMsg(I2S(h))
         
         return s
        endmethod
    endstruct

    function BasicSndxSetupVX takes sndx s returns sndx
        set s.durEx=-1.
        set s.looping=false
        set s.is3D=false
        set s.playLocally=false
        set s.fadeOut=false
        set s.fadeInRate=12700
        set s.fadeOutRate=12700
        set s.vol=127
        set s.x=0
        set s.y=0
        set s.z=0
        set s.velX=0
        set s.velY=0
        set s.velZ=0
        set s.attachUnit=null
        set s.toPlayFor=Player(0)
        
     return s
    endfunction
    
endlibrary

Collapse JASS:
library vSndxTest initializer Init requires vSndx

    globals
     private sndx S1
     private sndx S2
     private sndx S3
     //* I know I could've used arrays, but meh...
    endglobals

    private function PlayAgain takes nothing returns nothing
        call S1.play()
        call S2.play()
        call S3.play()
        
        call DestroyTimer(GetExpiredTimer())
    endfunction
    
    private function Actions takes nothing returns nothing
        set S1=sndx.create("Abilities\\Spells\\Demon\\RainOfFire\\RainOfFireTarget1.wav")
        set S2=sndx.create("Abilities\\Spells\\Demon\\RainOfFire\\RainOfFireTarget2.wav")
        set S3=sndx.create("Abilities\\Spells\\Demon\\RainOfFire\\RainOfFireTarget3.wav")
        
        call BasicSndxSetupVX(S1)
        call BasicSndxSetupVX(S2)
        call BasicSndxSetupVX(S3)
        
        set S1.durEx=3.
        set S2.durEx=3.
        set S3.durEx=3.
        
        set S1.playLocally=true
        set S2.playLocally=true
        set S3.playLocally=true
        
        set S1.toPlayFor=Player(1)
        set S2.toPlayFor=Player(1)
        set S3.toPlayFor=Player(1)
        
        call S1.play()
        call S2.play()
        call S3.play()
        
        call S1.play()
        call S2.play()
        call S3.play()
        
        call DestroyTimer(GetExpiredTimer())
        call TimerStart(CreateTimer(),3.25,false,function PlayAgain)
    endfunction
    
    private function Init takes nothing returns nothing
        call TimerStart(CreateTimer(),0.25,false,function Actions)
    endfunction
    
endlibrary

What I'm trying to do: make the create function search for a struct (already existing) with the same file and return that instead of creating a new one...
05-15-2009, 02:51 PM#2
Opossum
What do you expect S2I of a file path to return?
It just turns that string into an integer and as there's not much of an integer value in that string it will return 0.

Converting anything into an integer doesn't always return a unique id. Basically only handles do that.
05-15-2009, 03:13 PM#3
Deaod
Collapse JASS:
function s2i takes string s returns integer
    return s
    return 0
endfunction
I think you might want to replace S2I with this one. But be careful, the string table is empty after saving and loading a game.