I can't figure out why this isn't working... (it's easy!)

  • I'm trying to do something pretty simple, but it's not working and I can't figure out why. (Clearly my C2 skills have gotten rusty...)

    Here's my pseudocode:

    if left_button clicked then set y of sprite0 to 1
    if sprite0.y >= 1 then add 1 to sprite0.y
    if sprite0.y >= 768 then: 
         destroy sprite0
         set myvariable to 1
    if myvariable >= 1 then add 1 to myvariable
    if myvariable > 50 then [do something]
    [/code:32ads55e]
    
    The global variable "myvariable" is never getting larger than 50.  When I run this code in debug mode the variable jumps up in big numbers and then resets back to 1.  Does anyone know why???  There is probably a better way to do all of this, but for the moment I'm really trying to understand why this isn't working...  It's driving me nuts.
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • It works exactly as described and expected. You should post a capx.

    Sprite 0 moves downwards ever tick until it passes 786, then gets destroyed. Then myvariable increments every tick, and will run the last action every tick after it gets past 50. So what is in your last event in the [do something] part?

  • Man, I'm such an idiot. It took me 10 seconds to find the problem when I looked at it this morning. (I was setting myvariable to "1" when sprite0.y was < 768. <head slap>)

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