you mean to fade in/out the volume smoothly/gradually as opposed to directly changing from x amount to x amount?
I recently got my thinking cap on about the mainLoop function & that we don't necessarily need to use it for creating loops. I completely forgot about the while & repeat functions of Lua.
In other words you could create a function which you can call along with an included variable to control the function....
-- let's create a function to smoothly increase/decrease music volume without using mainLoop function
function setMusicVol(sta, vol)
if sta == 1 then
repeat
if getVolume(eMusicVolume) > vol then setVolume(eMusicVolume, getVolume(eMusicVolume) - 1) end
--print("volume:" .. getVolume(eMusicVolume)) --testing only!
until getVolume(eMusicVolume) <= vol
elseif sta == 2 then
repeat
if getVolume(eMusicVolume) < vol then setVolume(eMusicVolume, getVolume(eMusicVolume) + 1) end
--print("volume:" .. getVolume(eMusicVolume)) --testing only!
until getVolume(eMusicVolume) >= vol
end
end
call it via an execute a script action part > setMusicVol(sta, vol)
sta (state) integer value (1=decrease volume, 2=increase volume)
vol (volume) integer value (add a number between 0 & 100)
P.S: it fades really quick so if you wanted to slow it down you would have to create an pause action part which toggles a condition but I'm not going to show how to do that for the sake of keeping this simple.