[Solved] Volume control via script

  • #1, by marco-roncoMonday, 21. August 2017, 18:24 7 years ago
    Hi smile

    I'm trying to control Music, Voice and Speech Volume in my Game.

    The process

    I have created a Menu that looks like this:



    First of all, I have an animation with 10 frames.
    Animation name is "Music_Volume_ANIM", inside "Music_Volume" scene object.



    Each frame represents a volume status, from o (empty) to 11 (full).
    So frame 1 represents volume 10, frame 2 is for volume 20 and so on.


    The animation is set it to infinite loop and it is the default animation for the scene object.
    The pause between frames is 100ms. 



    Then, as AFRLme suggested, I created a called by other action part.

    local vol = getVolume(eMusicVolume)
    
    if vol >= 0 and vol < 10 then 
     ActiveAnimations["Music_Volume_ANIM"].AnimationFirstFrame = 1 
     ActiveAnimations["Music_Volume_ANIM"].AnimationLastFrame = 1
    elseif vol >= 10 and vol < 20 then 
    ActiveAnimations["Music_Volume_ANIM"].AnimationFirstFrame = 2
    ActiveAnimations["Music_Volume_ANIM"].AnimationLastFrame = 2
    
    ...
    end




    The script contains all volumes from 0 to 100.
    This script is an execute a script action part inside of the first frame of the "Music_Volume_ANIM" animation.



    This is where the script is called


    The animation is the default animation, so it starts automatically:

    --------------

    The issue

    When I test the scene, Music_Volume_ANIM loops, apparently ignoring the AnimationFirstFrame and AnimationLastFrame.

    The log file is empty.

    Any help is appreciated, thanks! smile

    Newbie

    22 Posts


  • #2, by sebastianMonday, 21. August 2017, 18:49 7 years ago
    couldnt you just use one frame and instead move the animation position to the correct location? 

    Thread Captain

    2346 Posts

  • #3, by marco-roncoMonday, 21. August 2017, 18:55 7 years ago
    Thanks Sebastian, that's a good idea too smile

    For those find this useful,  I have found the issue btw:

    "The script contains all volumes from 0 to 100."

    the last elseif in the script was written like this:

    if vol >= 90 and vol < 100 then 
     ActiveAnimations["Music_Volume_ANIM"].AnimationFirstFrame = 11 
     ActiveAnimations["Music_Volume_ANIM"].AnimationLastFrame = 11
    end

    But... yes it sound obvious now... volume is 100 by default.
    So if I type < 100, 100 will not be included.

    The correct version is

    if vol >= 90 and vol < 101 then 
     ActiveAnimations["Music_Volume_ANIM"].AnimationFirstFrame = 11 
     ActiveAnimations["Music_Volume_ANIM"].AnimationLastFrame = 11
    end

    (or <= 100)

    Newbie

    22 Posts