I don't get why this array variable check isn't working

Get help using Construct 2

Post » Mon Dec 15, 2014 8:25 am

I have an array that I'm using to hold a bunch of variables to track various event triggers in my layout. It worked great for limiting my projectiles to only 3 shots on the screen at once, but now I'm using a new variable as a switch to switch between multiple characters on the layout. If its equal to 0 my first character is active, if its equal to 1 my other character is active. I use a specific controller button to switch the variable from 0 to 1 and back again.

This should be dead simple. But it does not work. If I manually set the Array Variable on the layout, I can control my second character at Layout start. And I can press my switch button to switch back to the first character. Once. But if I start with the first character (array variable = 0) it will not switch to the second character.

I'm attaching my Capx if anyone is willing to take a look and offer a suggestion. Cause this is getting annoying.

360 controller recommended. Control pad/stick move, A jumps, B shoots (hold for run), hold control pad/stuck down and press A to fall through thin platforms.

R is suppose to switch characters.

Thanks for any help.
You do not have the required permissions to view the files attached to this post.
B
5
Posts: 17
Reputation: 259

Post » Mon Dec 15, 2014 9:00 am

Okay, think about your logic:

    on button:

    --If StanPaula = 0
    ----set stan paula to 1

    --If StanPaula = 1
    ----set stan paula to 0

Now, C2 runs events sequentially. Change a var? That goes into effect immediately. That's where your logic fails. So:

    StanPaula = 0;

    //this is true, so var is changed from 0 to 1
    --If StanPaula = 0
    ----set stan paula to 1

    //this event still runs! Since you changed the var to 1 above, the cond is true. You end up back where you started: 0.
    --If StanPaula = 1
    ----set stan paula to 0
Instead, you want to add an 'else' to the second if statement, so it reads like this:

    //this is true, so var is changed from 0 to 1
    --If StanPaula = 0
    ----set stan paula to 1

    //...and this event doesn't run! In the inverse scenario, the top event runs, and this one doesn't.
    --ELSE
    --If StanPaula = 1
    ----set stan paula to 0
Don't lose your work. Backup your game with Dropbox.
B
44
S
10
G
10
Posts: 1,106
Reputation: 9,187

Post » Mon Dec 15, 2014 9:07 am

Ooooooooh. *FACEPALM*

I completely missed that there was a way to insert an ELSE statement into an event sequence.

Thanks. That solved the problem.
B
5
Posts: 17
Reputation: 259

Post » Mon Dec 15, 2014 9:11 am

Glad that sorted things out.

Oh, another thing messing you up: platformer has default controls enabled. If you try to control w/ the keyboard, both chars will move, despite your now corrected logic.

Save yourself a future headache: Go to both stanley and paulina, look under their platform behaviors, and disable Default Controls.
Don't lose your work. Backup your game with Dropbox.
B
44
S
10
G
10
Posts: 1,106
Reputation: 9,187

Post » Mon Dec 15, 2014 9:13 am

TiAm wrote:Glad that sorted things out.

Oh, another thing messing you up: platformer has default controls enabled. If you try to control w/ the keyboard, both chars will move, despite your now corrected logic.

Save yourself a future headache: Go to both stanley and paulina, look under their platform behaviors, and disable Default Controls.


Roger that. Thanks!
B
5
Posts: 17
Reputation: 259


Return to How do I....?

Who is online

Users browsing this forum: Rudi55, varr and 5 guests