Anybody have any idea why this toggle system doesn't work as

0 favourites
  • 6 posts
From the Asset Store
Create complex dialogues with ease with this tool/template!
  • Hi everyone

    I just picked up construct 2 last week because I'm looking for a quick way to make games to easily preview assets which I sell on my asset store. So far it' certainly seems to be quick, I'm really impressed by the speed of which I can knock up a game. In fact I've finished the game and just need to put the sounds in.

    But now I've hit a stumbling block, I can't seem to get a toggle button for my sound control to work. my logic in sudo code is as follows

    global variable soundToggle="ON";

    on button tap call sound toggler function

    function soundToggler(){

    if (soundToggle=="ON"){ soundToggle="OFF";}



    Here's the capx file with a demo.

    WHat Am I missing here ? Is this not the approach to take to change the value of a variable? I know you can't do code in c2 so I think my use of events is roughly equivalent to what I described above in code, Although as I say I've only been using c2 for a few days, so My head hasn't completely got around the system yet.

    Many thanks

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You need to use Else in event 4 so you only check the value for each value once. Just think it through: If toggle is ON, set it to OFF. Then on the next line, you see if the toggle is OFF, which it is - you just set it, then set it to ON.

  • You should ensure you've read the manual and Ashley's posts on 'How Events Work'.

    What is happening is that you test for a condition - Soundtoggle=ON - then immediately set it to OFF in th eactions. This then triggers the very next condition.

    Simple answer is just to use 'Else'.

    EIDT: Ninj'd by BlackHornet whilst typing

  • Thanks black hornet , I actaully wanted to use an else statemnet when I first wrote the code it said in red that I couldn't add an else statement here . ,., I went back and tried again and it let me do it this time. I must have clicked on the wrong event. but yeah of course you're right!! How Stupid of me, what an oversight , I've been hammering away at this for 2 days solid and my brain is freezing up!

    Thanks man, I can carry on with my game now

  • zenox98 yeah , I skimmed through it all , and from what I understand is that events are essentially like code blocks. The problem was I was just being totally and utter dumb! of course setting to if statement like that would have that effect. Thanks for your help

  • The easiest way to add Else is to click on that first event (before doing the next one) and press X. This will add Else. Then add your next condition to this new event. Be sure to click to the very left of the event line to select the event - if you click more to the right, you select the condition. Something to be aware of.

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