I am creating a music fade out system using a periodic timer and a hashtable. Since timers and hashtables in jass are still new to me, I'm using this as reference Changing waits to Timers in Spells. (though I'm not using vjass).
udg_TimerHash is defined in the variable editor as type Hashtable.
udg_MusicVolume is defined in the variable editor as type Integer initialized with value 80.
The values in MusicLocalPlayWF function report null or 0 values. Can anyone see why null or empty values are being loaded from my Hashtable?
On a side note, do I add the below to MusicLocalPlayWFLoop to prevent memory leaks?
I can imagine the data would otherwise accumulate in my TimerHash if I don't start clearing out the stuff?
udg_TimerHash is defined in the variable editor as type Hashtable.
udg_MusicVolume is defined in the variable editor as type Integer initialized with value 80.
The values in MusicLocalPlayWF function report null or 0 values. Can anyone see why null or empty values are being loaded from my Hashtable?
JASS:
function MusicLocalPlay takes string musicPath , player p returns nothing
if GetLocalPlayer() == p then
call PlayMusic(musicPath)
endif
endfunction
function MusicLocalPlayWFLoop takes nothing returns nothing
local timer t = GetExpiredTimer()
local player p = LoadPlayerHandle(udg_TimerHash, GetHandleId(t), 1)
local integer musicVolume = LoadInteger(udg_TimerHash, GetHandleId(t), 2)
call BJDebugMsg("musicVolume = " + I2S(LoadInteger(udg_TimerHash, GetHandleId(t), 2)))
call BJDebugMsg("musicPath = " + (LoadStr(udg_TimerHash, GetHandleId(t), 3)))
if musicVolume <= 0 then
call DestroyTimer(t)
call MusicLocalPlay(LoadStr(udg_TimerHash, GetHandleId(t), 3), p)
else
if GetLocalPlayer() == p then
call SetMusicVolume(musicVolume)
endif
call BJDebugMsg("musicVolume is greater than 0")
set musicVolume = musicVolume - 5
call SaveInteger(udg_TimerHash, GetHandleId(t), 2, musicVolume)
endif
//set player = null
endfunction
function MusicLocalPlayWF takes string musicPath , player p returns nothing
local integer musicVolume = udg_MusicVolume
local timer t = CreateTimer()
call SavePlayerHandle(udg_TimerHash, GetHandleId(t), 1, p)
call SaveInteger(udg_TimerHash, GetHandleId(t), 2, musicVolume)
call SaveStr(udg_TimerHash, GetHandleId(t), 3, musicPath)
call BJDebugMsg("Saving musicInteger = " + I2S(LoadInteger(udg_TimerHash, GetHandleId(t), 2)))
call BJDebugMsg("Saving musicPath = " + LoadStr(udg_TimerHash, GetHandleId(t), 3))
call TimerStart( t, 0.1, true, function MusicLocalPlayWFLoop )
endfunction
//===========================================================================
function InitTrig_MusicSystem takes nothing returns nothing
endfunction
On a side note, do I add the below to MusicLocalPlayWFLoop to prevent memory leaks?
JASS:
FlushChildHashtable(udg_TimerHash, GetHandleId(t))
I can imagine the data would otherwise accumulate in my TimerHash if I don't start clearing out the stuff?