Mute/Restore Volume (CMS)

From The Official Visionaire Studio: Adventure Game Engine Wiki
Name Type By
Mute/Restore Volume Definition AFRLme

This script allows you to mute or restore the volume for all sound types; it is also possible from Visionaire Studio 4.0 onwards to mute/restore volume via the new eGlobalVolume command. see eGlobalVolume Method.

Additional Info
Volume types currently available...
eMusicVolume(0), eSoundVolume(1), eSpeechVolume(2), eMovieVolume(3), eGlobalVolume(4)

Instructions

1. Add the main script to the Visionaire Studio Script Editor & set the script as a definition script.
2. Create condition "cond_mute" & set default value to false.
3. Create 5 values vol_0, vol_1, vol_2, vol_3 & vol_4 - these will be used to store volumes values.
4. To mute/restore volume: add an execute a script action to a key input, button or scene object, containing...

globalMute()

Main Script

--[[
Mute/Restore Volume [V1] (20/03/2014)
Written by AFRLme [Lee Clarke]
-- + --
email: afrlme@outlook.com
paypal: afrlme@zoho.com
patreon: https://www.patreon.com/AFRLme
portfolio: https://afrl.me
-- + --
This script is donation optional. In game credit is non-negotiable.
You are free to: ¹ use it in your game(s). ² modify the script.
Do not remove - or edit - this comment block.
--]]

-- * local variables * --
local cond = getObject("Conditions[cond_mute]") -- store muted condition

-- * function that determines if sound should be muted or restored * --
function globalMute()
 if not cond:getBool(VConditionValue) then -- if not muted then...
  for i = 0, 4 do -- (0, 2) if you are still on 3.7.1 or below (eMovieVolume(3) & eGlobalVolume(4) from visionaire studio 4.0 onwards)
   getObject("Values[vol_" .. i .. "]"):setValue(VValueInt, getVolume(i)) -- store volume i into linked editor value
   setVolume(i, 0) -- set volume i to 0
  end
  cond:setValue(VConditionValue, true) -- set muted condition to true
 else -- if already muted then do...
  for i = 0, 4 do -- (0, 2) if you are still on 3.7.1 or below (eMovieVolume(3) & eGlobalVolume(4) from visionaire studio 4.0 onwards)
   setVolume(i, getObject("Values[vol_" .. i .. "]"):getInt(VValueInt)) -- return volume level for i based on linked editor value
  end
  cond:setValue(VConditionValue, false) -- set muted condition to false
 end
 -- startVolSlider() -- uncomment this line if you are also using the volume slider script
end

eGlobalVolume Method

--[[
Mute/Restore Volume (global method; visionaire studio 4.0+ only) [V1] (20/03/2014)
Written by AFRLme [Lee Clarke]
-- + --
email: afrlme@outlook.com
paypal: afrlme@zoho.com
patreon: https://www.patreon.com/AFRLme
portfolio: https://afrl.me
-- + --
This script is donation optional. In game credit is non-negotiable.
You are free to: ¹ use it in your game(s). ² modify the script.
Do not remove - or edit - this comment block.
--]]

-- * local variables * --
local cond = getObject("Conditions[cond_mute]") -- store muted condition

-- * function that determines if sound should be muted or restored * --
function globalMute()
 if not cond:getBool(VConditionValue) then setVolume(eGlobalVolume, 0); cond:setValue(VConditionValue, true) else setVolume(eGlobalVolume, 100); cond:setValue(VConditionValue, false) end
end


Relevant Pages: Volume Control