Loops with multiple conditions and effects

Get help using Construct 2

Post » Thu Mar 20, 2014 3:49 am

Hey all,

Firstly, my apologies if this question has been asked before, but my cursory forum search did not turn up what I am looking for.

I am trying to do one loop with multiple conditions, something like:

Code: Select all
for(i = 0; i < array.size(); i ++){
    if(param=1)  Create Object 1;
    else if(param=2) Create Object 2;
    else if(param=3) Create Object 3;
    else if(param=4) Create Object 4;
    else if(param=5) Create Object 5;
    else if(param=6) Create Object 6;
    else if(param=7) Create Object 7;
... so on.
}


I tried doing a series of For loops, but that hangs my program since I have a large number of objects to loop through.

Ideas?
https://www.ravenheart.ca/home
Company name changed to avoid Facebook-type shenanigans

"Someone once told me I bite off more than I can chew...

I told them I would rather choke on greatness than nibble on mediocrity."
B
22
S
6
G
1
Posts: 1,414
Reputation: 4,822

Post » Thu Mar 20, 2014 5:53 am

I don't see a problem with it, this should work fine:

Code: Select all
For "loop" from 0 to 100
    Condition A - Do stuff
    Condition B - Do stuff
    Condition C - Do stuff
B
83
S
22
G
15
Posts: 1,039
Reputation: 15,219

Post » Thu Mar 20, 2014 10:29 pm

The for loop that is readily available in Construct Events does not support that though, at least not that I have found.

You either have:

Code: Select all
for 0 :100{
    if(condition)
    if(condition)
    if(condition)
    if(condition)
    if(condition)
    actions
}


Which will execute all of the actions upon any one of the conditions being true, or you have:
Code: Select all
for 0:100{
    if(condition) action
    for 0:100{
        if(condition) action
        for 0:100{
            if(condition) action
            for 0:100{
                if(condition) action
            ...
            }
        }
    }
}


Which logically should do what I need, but hangs.

Could I write a custom JS block to do exactly what I put above? Yea, but I would like to avoid that as a first option.
https://www.ravenheart.ca/home
Company name changed to avoid Facebook-type shenanigans

"Someone once told me I bite off more than I can chew...

I told them I would rather choke on greatness than nibble on mediocrity."
B
22
S
6
G
1
Posts: 1,414
Reputation: 4,822

Post » Thu Mar 20, 2014 10:40 pm

You're either failing to explain what you want or you can't see the obvious solution

You can have an action for each condition inside the loop
Untitled-1.png
You do not have the required permissions to view the files attached to this post.
B
83
S
22
G
15
Posts: 1,039
Reputation: 15,219

Post » Fri Mar 21, 2014 1:55 am

I got the "Else" working now. I was layering the events incorrectly as subevents of the subevents. Thanks for your help.
https://www.ravenheart.ca/home
Company name changed to avoid Facebook-type shenanigans

"Someone once told me I bite off more than I can chew...

I told them I would rather choke on greatness than nibble on mediocrity."
B
22
S
6
G
1
Posts: 1,414
Reputation: 4,822

Post » Fri Mar 21, 2014 2:29 am

gumshoe2029 wrote:I got the "Else" working now. I was layering the events incorrectly as subevents of the subevents. Thanks for your help.


Construct 2's logic is really weird if you're used to other languages but I have yet to find anything I can't do with a proper ordering of events and subevents. Seems like you already figured this one out though.
B
9
S
3
Posts: 37
Reputation: 749


Return to How do I....?

Who is online

Users browsing this forum: digitalsoapbox, RetrocadeMedia and 1 guest