Jump to content
  • 0

I need a loop for a script


SOF2Fragger

Question

6 answers to this question

Recommended Posts

  • 1

Several ways to do it.

 

You can just have your actions inside your script and then just use Restart;

Or make while or for loops.

You could even use conveyor belts and teleportation lines if not using ACS

Share this post


Link to post
  • 0

I need it to run a limited number of times, and restart would just keep it going. I know I need a loop, but my knowledge is very limited.

Share this post


Link to post
  • 0

That's why I put the links to the while and for loop... Everything's explained there on how to make a script run a certain amount of times.

Share this post


Link to post
  • 0

Here you go. Three different ones:
 

Spoiler

 


#include "zcommon.acs"

/* declare some variables used by script 2 */
bool triggered = 0;
int counter = 0;

/* start a loop that checks for imp count being greater than zero */
script 2 OPEN{
    while(ThingCount(T_IMP,0) > 0){
        log(s:"Still ",i:ThingCount(T_IMP,0),s:" imps left!");
        delay(35);
    }
    // loop exited when all imps killed:
    print(s:"All Dead! Get the fuck out!!!!");
}

/* a counter that tracks whether all platforms are lowered. */
script 1 (void){
    counter++;
    print(i:counter);
    /* lower plats on each increment: */
    int tagnum = -1;
    switch(counter){
        case 1:
            tagnum=2;
            break;
        case 2:
            tagnum=3;
            break;
        case 3:
            tagnum=4;
            break;
        case 4:
            tagnum=5;
            break;
        default:
            break;
    }
    /* lowers platform identified by tagnum by 56 units */
    floor_lowerbyvalue(tagnum,16,56);
}

/* and a simple 'for' loop. doesn't do anything much... */
script 3(void){
    for (int x=0; x < 5; x++){
        log(s:"iteration ",i:x);
    }
}

 

 

 

 

WHILE: Continues until condition is not met. Counts imps, and prints a message when all dead (the ENTER script)

 

VARIABLE COUNTER: script 1 - increments a counter on each script call and does something (lowers the platforms in turn)

 

FOR: loops for specified number of times. You can use a variable as well if you need to.

 

Simple map (DiHF)

acs_loops.zip

 

Edited by smeghammer
removed irrelevant code

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...