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

Get help using Construct 2

Post » Wed Sep 28, 2016 4:28 pm

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:

Code: Select all
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]


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.
B
11
S
3
Posts: 79
Reputation: 854

Post » Wed Sep 28, 2016 5:13 pm

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?
Mistakes were made.
B
52
S
26
G
109
Posts: 1,606
Reputation: 61,633

Post » Thu Sep 29, 2016 8:22 am

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>)
B
11
S
3
Posts: 79
Reputation: 854


Return to How do I....?

Who is online

Users browsing this forum: Euduardo and 25 guests