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

Get help using Construct 2

Post » Fri Aug 26, 2016 3:31 pm

Message: RobertBrooks can only post plain text URLS until they have 500 rep. 1 URLS modified. Why?
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";}
if(soundToggle=="OFF"){soundToggle="ON";}
}

Here's the capx file with a demo.
https://www.dropbox.com/s/cxh3exl4z7m4jyo/soundToggle.capx?dl=0
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
B
3
S
1
Posts: 5
Reputation: 339

Post » Fri Aug 26, 2016 3:37 pm

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.
ImageImageImage
B
71
S
22
G
259
Posts: 3,794
Reputation: 143,704

Post » Fri Aug 26, 2016 3:43 pm

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 :)
If your vision so exceeds your ability, then look to something closer.
Moderator
B
137
S
31
G
87
Posts: 5,557
Reputation: 60,458

Post » Fri Aug 26, 2016 3:55 pm

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
B
3
S
1
Posts: 5
Reputation: 339

Post » Fri Aug 26, 2016 4:00 pm

@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
B
3
S
1
Posts: 5
Reputation: 339

Post » Fri Aug 26, 2016 4:01 pm

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.
ImageImageImage
B
71
S
22
G
259
Posts: 3,794
Reputation: 143,704


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 29 guests