How do I 'if-then' (super newb)

0 favourites
  • 4 posts
From the Asset Store
Make your dream action platformer game effortlessly with this template!
  • I am brand new to Construct 2 (been using it since Friday). I'm having a heck of a time getting if-then statements to work. The simple version:

    -I'm in a repeat loop that goes to 5.

    -Each time through the loop, I am randomly assigning a number between 1 and 15 to the variable 'Pick'.

    -I want to assign the contents of 'Pick' to one of 5 text fields. The text fields are labeled B1, B2, B3, B4, B5.

    -Each time through the loop, I want to detect what the loop index # is and assign 'Pick' to a specific field. So if the loopindex = 1, I would assign Pick to B1. If loopindex = 2, I would assign Pick to B2, etc...

    If I was writing this in other scripting languages, I would write something like this:

    if (loopindex == 1) then

    B1.text = Pick;

    if (loopindex == 2) then

    B2.text = Pick;

    Basically, an if-then, with no 'else'. But, from what I can tell, the conditional statements in Construct 2 keep forcing me to add an 'else' to it (really frustrated with this). So, when I'm in the loop, I put in an action to set the B1 text to:

    loopindex = 1 ? Pick : ""

    However, when loopindex doesn't equal 1, it obviously erases what is in B1. How do I not put something after the colon? Is there a 'null' or 'do nothing' command I can put there (couldn't find find one)?

    Thanks in advance for any help!

    -Matt

  • Use the 'else' condition. Construct2 has 'else' condition under 'system'

    It will look like this:

    if ( loopindex ==1) //do something

    else if (loopindex ==2) //do something2

    else if... // and so on

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • simple use subevent like this

  • Thank you! Great suggestions. Subevents did it. Thanks!

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