Loops with multiple conditions and effects

0 favourites
  • 6 posts
From the Asset Store
6 looping tracks to use in your games and projects. These tracks are in the style of the 1960s detective movie genre.
  • 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:

    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.
    }[/code:dpgskplu]
    
    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?
  • I don't see a problem with it, this should work fine:

    For "loop" from 0 to 100
        Condition A - Do stuff
        Condition B - Do stuff
        Condition C - Do stuff
    [/code:273ur41b]
  • 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:

    for 0 :100{
        if(condition)
        if(condition)
        if(condition)
        if(condition)
        if(condition)
        actions
    }[/code:31xnz5q1]
    
    Which will execute all of the actions upon any one of the conditions being true, or you have:
    [code:31xnz5q1]
    for 0:100{
        if(condition) action
        for 0:100{
            if(condition) action
            for 0:100{
                if(condition) action
                for 0:100{
                    if(condition) action
                ... 
                }
            }
        }
    }[/code:31xnz5q1]
    
    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.
  • 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

    [attachment=0:31xg6ebe][/attachment:31xg6ebe]

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I got the "Else" working now. I was layering the events incorrectly as subevents of the subevents. Thanks for your help.

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

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