How do I create a single prompt that toggles music on or off?

0 favourites
  • 5 posts
From the Asset Store
Toggles Dials Switches and Alerts ! A foundational sound grouping of Analog type switches and Steampunk effects
  • My intention was to have the M key being able to both mute the music and unmute it. The music icon is an icon on the UI to indicate whether music is playing.

    This is what I set up to make it happen, but it's not working. What am I doing wrong?

  • This is a common issue among new users. Basically what's happening is the first event runs and sets the music to 0. But the second event will also run (afterwards), see that the music is 0, and then set it to 1.

    So both events are technically running correctly.

    There are a lot of ways to handle this. For simplicity, I suggest breaking it into two parts in a single event:

    1: On M pressed, set music to 1-music. (this way 1 becomes 0, and 0 becomes 1)

    2: If music = 1, do "enable actions". Else, do "disable actions"

  • You can use boolean variable, when pressing a key, you can toggle that boolean variable.

    If boolean = true, set mute.

    If false, not mute.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • This is how I do it and it works fine for me:

    Like the other guys said, the issue with your code is that it triggers both events. That's why I use the 0.2 seconds and the =2 variable, to break the loop.

    BUUTTTT I can also see that the way I do it is super ghetto and perhaps what i'm telling you is not the best advice.

  • You can use boolean variable, when pressing a key, you can toggle that boolean variable.

    If boolean = true, set mute.

    If false, not mute.

    I like this way more than my way <3

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