Welcome to the Builder Academy

Question Trigger VNum 40603 has looped 100 times!!!

More
21 Feb 2014 21:51 #4710 by Parnassus
Is there a way to let a trigger loop more than 100 times? Without getting into specifics, I have a trigger that has four sections. Each section loops about 40 times. What I'm finding is that the first section runs, the second section runs and the third section breaks about halfway in when the 100th loop hits.

The loop thing has often helped me when the loops are accidental. I did think, however, that the (successful) done would keep the message from happening. I've tried moving section one and two down to see if the problem was in section three itself but section three and four ran while section one broke.

In my opinion, the trigger has not looped over 100 times, it has looped 40 times and stopped, then it has looped 40 times and stopped, then it has looped 20/40 times and broke. After each set of loops is an echo and the set up to the next set of loops so it isn't exactly continuing the loops. Is there a way to get all my 160 loops?

Please Log in or Create an account to join the conversation.

More
23 Feb 2014 18:06 #4712 by thomas
out of curiousity: what's the purpose of the many loops?

The limit is there to prevent a trigger from occupying too much cpu time. You should seriously consider altering your logic if you hit the ceiling.

Please Log in or Create an account to join the conversation.

More
23 Feb 2014 19:06 #4713 by Parnassus
I'm making a 90 room maze with variable layouts. I really like Random's Mist Maze (it was written by Random, wasn't it? as well as being random?) but I wanted a more stable layout. It's actually working really well, except for that looping part which is taking care of 90 rooms with 2 to 4 exits per room. This would not be a trigger in constant use because I wanted it stable, not resetting all the time.

What would be the outcome of the cpu time? On my computer, I think it's less than a second (it's hard to tell exactly but it might be more accurate to say about 4 prompts of time for whatever that's worth) but it would probably be more on a working game.

It'll be in a format where I can switch it over to the build port soon if you want to check it out. In your opinion though, a trigger with that many loops isn't worth doing because it would be inefficient use of cpu? Does it make a difference if it runs once an hour, once a day or at reboot?

Thanks for info :)

Please Log in or Create an account to join the conversation.

More
24 Feb 2014 22:24 - 24 Feb 2014 22:30 #4715 by thomas
The main issue isn't the time it takes, but that - since the server is singlethreaded - it only has a limited time to perform its duties before people percieve the delay as lag.

There's some safeguards built in to prevent this:
If you loop more than 30 times in a while loop, you're broken out of it immidiately.
Code:
} else if (!strn_cmp("while ", p, 6)) { temp = find_done(cl); if (!temp) { script_log("Trigger VNum %d has 'while' without 'done'.", GET_TRIG_VNUM(trig)); return ret_val; } if (process_if(p + 6, go, sc, trig, type)) { temp->original = cl; } else { cl = temp; loops = 0; } } else if (!strn_cmp("switch ", p, 7)) { cl = find_case(trig, cl, go, sc, type, p + 7); } else if (!strn_cmp("end", p, 3)) { /* If not in an if-block, ignore the extra 'end' and warn about it. */ if (GET_TRIG_DEPTH(trig) == 1) { script_log("Trigger VNum %d has 'end' without 'if'.", GET_TRIG_VNUM(trig)); continue; } GET_TRIG_DEPTH(trig)--; } else if (!strn_cmp("done", p, 4)) { /* if in a while loop, cl->original is non-NULL */ if (cl->original) { char *orig_cmd = cl->original->cmd; while (*orig_cmd && isspace(*orig_cmd)) orig_cmd++; if (cl->original && process_if(orig_cmd + 6, go, sc, trig, type)) { cl = cl->original; loops++; GET_TRIG_LOOPS(trig)++; if (loops == 30) { process_wait(go, trig, type, "wait 1", cl); depth--; return ret_val; } if (GET_TRIG_LOOPS(trig) >= 100) { script_log("Trigger VNum %d has looped 100 times!!!", GET_TRIG_VNUM(trig)); break; } } else { /* if we're falling through a ...

But your solution: start new while loops - they reset the counter.
Last edit: 24 Feb 2014 22:30 by thomas.

Please Log in or Create an account to join the conversation.

More
24 Feb 2014 23:29 #4716 by Parnassus
That sort of confuses me more. There's about 40 loops in each section. The first section finishes, so that's over 30 loops between the while and done. So now I set up the new loop with echos and sets between the previous done and the new while. Isn't that considered a new while loop? So now the second section runs, with about 40 loops again. So now I have a second done, a few echos and a few more sets and then a third while. This one goes about halfway and sets up the message that it's looped 100 times. By this time, yeah, it's probably looped 100 times: 40 between the while and done, 40 between the second while and second done and 20 more between the third while and third done but this section can't finish because the other 20 loops are over 100 total.

So now I'm more confused than ever since I've gone more than 30 loops (and I've just checked one of my tarot triggers which loops 78 times, one for each card) and, as far as I can tell, I'm starting new while loops. Am I misunderstanding the terms? I can't put halts into this trigger because that would keep it from going into the next section, wouldn't it? Does it need ends to end the loop as well as the dones? Because I think that gives me error messages that I have ends without ifs or something. On the other hand, I know there's some configuration of ifs and whiles that generates a bug message and refuses to /fi even though there's actually nothing wrong with the syntax. I just keep forgetting what that is. I don't think that should happen with no ifs though.

Please Log in or Create an account to join the conversation.

More
25 Feb 2014 03:17 - 25 Feb 2014 03:18 #4717 by krell
Without seeing the script it's hard for me to picture how your trigger is written. Are your while loops nested?

eg:
Code:
while x < a ... while y < b ... while z < c ... done done done

I'm just wondering if the subsequent iterrations contribute to the overall loop count.
Last edit: 25 Feb 2014 03:18 by krell. Reason: grammer correction

Please Log in or Create an account to join the conversation.

Time to create page: 0.218 seconds