Button OnClicked is called after variable chang

0 favourites
  • 8 posts
From the Asset Store
Medeival & Viking War Horns Sounds / 22 Unique Calls / 2:40 minutes of audio
  • 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?

  • 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.

  • 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.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I'd either have to see the capx or your events to see what is causing this.

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

    ^----- Forums still wont allow me to post screenshots for some reason :/

  • there is no on button clicked on the last text is 3 event.

  • 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?

  • 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!

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