DE EN FR ES IT CZ
Back Back to top

Decrease / Increase Music Volume

This thread is a few years old. Some details may refer to an earlier version of Visionaire Studio. Current tutorials

  • #1, by marvel 14 years ago Quote
    I would need a little script for the + and - key to control the volume of the music. smile
  • New to Visionaire Studio?

    Create point and click adventures without coding. The free version covers up to 25 scenes per project. For more scenes or to earn money with your game, you need a license.

    See the Indie Bundle Try it for free
  • #2, by superscheibenkleiste 14 years ago Quote
    Dazu brauchst du doch kein Script :-)
    Geh auf Tastenaktionen -> + / - -> Lautstärke ändern -> Musik -> Operator +/-
    Oder willste was Anderes?
    Superscheibenkleiste
  • #3, by marvel 14 years ago Quote
    @superscheibenkleiste: Bitte in Englisch antworten. Sonst wirds für alle englischsprachigen User schwierig wink

    @all: I cannot control the music volume via the action part. When i use the action part "change volume", nothing happens when i press the keys. So i thought lua could maybe help wink Also i thought about a more fluid change of the volume... not in steps (action part)
  • #4, by afrlme 14 years ago Quote
    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.
  • #5, by afrlme 14 years ago Quote
    & something without fading...
    for you to manually alter with +/- key input commands.

    -- let's create the increase/decrease music volume function
    function adjMusicVol(sta, val)
     if sta == 1 then
      if getVolume(eMusicVolume) > 0 then setVolume(eMusicVolume, getVolume(eMusicVolume) - val) end
      if getVolume(eMusicVolume) < 0 then setVolume(eMusicVolume, 0) end
     elseif sta == 2 then
       if getVolume(eMusicVolume) < 100 then setVolume(eMusicVolume, getVolume(eMusicVolume) + val) end
       if getVolume(eMusicVolume) > 100 then setVolume(eMusicVolume, 100) end
     end
    end
    


    execute a script > adjMusicVol(sta, val)

    sta = integer value (1=decrease, 2=increase)
    val = integer value (this controls how much volume increases/decreases - I recommend value between 1 & 10)
  • #6, by marvel 14 years ago Quote
    Thanks for the scripts lee. Thats fantastic.

    You know what? The + and - Keys didnt work to increase/decrease the music... because i tried to use the keys from the numeral part on the right of my laptop-keyboard. ^^ The MAIN Keys are working.
  • #7, by afrlme 14 years ago Quote
    “
    Thanks for the scripts lee. Thats fantastic.

    You know what? The + and - Keys didnt work to increase/decrease the music... because i tried to use the keys from the numeral part on the right of my laptop-keyboard. ^^ The MAIN Keys are working.
    „


    haha razz

    yes, speaking of that, we could do with adding some more keys to the key input such as ctrl, alt, shift etc & the numerical keys.
    but people who would use numerical keys should take into consideration that not all people on laptops/netbooks or people using small keyboards have easy access or access to the numpad.