How do I add a global music toggle button

0 favourites
  • 6 posts
From the Asset Store
Globals 2.0
$3.99 USD
Globals 2.0 stores and group variables. You can also load and save data (variables) from/to JSON files.
  • Hello people,

    I have browsed the forums and looked at multiple videos and tutorials on trying to get this to work and I don't know why it isn't.. Seems like it should on the amount of different ways i have tried to do it?

    Atm i have this one because its the one that makes sense to me... And should work?

    imgur.com/a/Zvh6v

    New to construct so be easy on me

    Thanks

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Add else to your second toggle event.

  • Add else to your second toggle event.

    Something like this?

    imgur.com/a/PlwYh

    Still isn't working. If i change the toggle to set silent it makes the music silent but of course cannot turn it back on. Maybe the toggle action is bugged or am i still doing something wrong?

  • I think your "toggle silent" action gets executed twice, once in On Touched event and once in On Mouse Click event.

    If you are testing on PC, both events are triggered at the same time.

    So it toggles off, then on again, that's why nothing happens.

    You can set "Use Mouse Input=No" in Touch properties or remove the On Mouse event, and change your code to this:

    On Touched button
       Set Toggle_music to (Toggle_music=0)      <-this will toggle the variable, 0 will become 1, 1 will become 0
    
    System->Compare variable->Toggle_music=0
    System->Trigger once
         Audio->Pause "music"
    
    System->Compare variable->Toggle_music=1
    System->Trigger once
         Audio->Resume "music"
    
    [/code:p1ja75te]
  • I think your "toggle silent" action gets executed twice, once in On Touched event and once in On Mouse Click event.

    If you are testing on PC, both events are triggered at the same time.

    So it toggles off, then on again, that's why nothing happens.

    You can set "Use Mouse Input=No" in Touch properties or remove the On Mouse event, and change your code to this:

    > On Touched button
       Set Toggle_music to (Toggle_music=0)      <-this will toggle the variable, 0 will become 1, 1 will become 0
    
    System->Compare variable->Toggle_music=0
    System->Trigger once
         Audio->Pause "music"
    
    System->Compare variable->Toggle_music=1
    System->Trigger once
         Audio->Resume "music"
    
    [/code:2e5f0n2g]
    

    Thank you! Working now. I even tried changing it to "or" But turns out on touch and mouse button click are basically both working as a mouse button click (on a mac)

  • also another thing, as i want this button on all my 4 layouts. How would I make it work on all the layers.. I tried including the event sheet but it bugs the game. And when i just copy and paste the events and actions along with the button the sound loops.

    As i have the sound only playing on the menu screen as they will never be able to launch it from the scoreboard or game over screen etc. Then this music sound is playing over across all the layouts i have from the menu screen.

    Basically i want a mute button exactly what i have done, but on the other layouts i got.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)