Button OnClicked is called after variable chang

Get help using Construct 2

Post » Mon Dec 30, 2013 3:02 pm

Hi guys. I am experiencing weird behaviour with the Button object...

Here is a statement I constructed:

if Button1 on clicked and System global variable lastText == 2 then lastText = 3.

another statement I constructed is

if Button1 on clicked and System global variable lastText == 3 then Stop all audio and Play MyAudioTrack not looping at volume 0dB.


The problem is that When I press the Button and lastText is equal to 2. Once it has set last text is equal to 3 it detects that I have pressed the button for lastText is equal to 3 aswell and the audio plays in either case :S.

This to me is strange behaviour as a programmer. What is the way around it?

tsugaruddr2013-12-30 15:03:08
B
3
Posts: 36
Reputation: 299

Post » Mon Dec 30, 2013 3:18 pm

Event sheets are read top to bottom every tick.

You should use else statements or a wait 0 seconds (execute at the end of the event sheet, before next tick) action here.
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Mon Dec 30, 2013 3:37 pm

else is greyed out. Dont know why. :S

Waiting does not make a difference. Even if I set it to 5 seconds. The statement where it checks for lastText==3 is underneath the lastText==2 statement.
B
3
Posts: 36
Reputation: 299

Post » Mon Dec 30, 2013 3:41 pm

I'd either have to see the capx or your events to see what is causing this.

I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Mon Dec 30, 2013 3:51 pm

h ttp://www .jaboston .com/relevantevents.p n g

^----- Forums still wont allow me to post screenshots for some reason :/tsugaruddr2013-12-30 15:52:59
B
3
Posts: 36
Reputation: 299

Post » Mon Dec 30, 2013 3:55 pm

there is no on button clicked on the last text is 3 event.
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Mon Dec 30, 2013 3:59 pm

Also you could put the last text = checks as subevents and just by changing the order, putting the last text is 3 above the last text is 2 it should work.

But I would recommende using the else statement there, because it seems that button is only for changing from 2 to three, or am I wrong?
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Mon Dec 30, 2013 4:17 pm

basiaclly depending on the events in the story lastText is used to tell me what part of the story I am on. THis helps me identify what events should be happening all over the game.

What worked for me is your suggestion to put 3 above 2. No idea why I didnt think of this simple solution before! Too much objective C and Java I think.

Thankyou!
B
3
Posts: 36
Reputation: 299


Return to How do I....?

Who is online

Users browsing this forum: mcscooter and 28 guests