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

0 favourites
  • 5 posts
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • 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.

  • 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
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Ooooooooh. *FACEPALM*

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

    Thanks. That solved the problem.

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

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

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