Manually breaking out of an endless loop.

Discuss macro implementations, ask for macro help (to share your creations, see User Creations, probably either Campaign Frameworks or Drop-in Resources).

Moderators: dorpond, trevor, Azhrei, giliath, jay, Mr.Ice

Post Reply
Shadow Wizard
Giant
Posts: 192
Joined: Mon Apr 11, 2011 8:11 pm

Manually breaking out of an endless loop.

Post by Shadow Wizard »

I think I may have figured out hot to so something, but am afraid I may make a mistake and get caught in and endless loop. How would I get out?


For example, lets say I would write this code:
while a==1 do(
a=1
)

how would I manually break out of it?

User avatar
aliasmask
RPTools Team
Posts: 9031
Joined: Tue Nov 10, 2009 6:11 pm
Location: California

Re: Manually breaking out of an endless loop.

Post by aliasmask »

Make sure you have a condition that will always break the loop. Otherwise, it will loop 10,000 times and then error out.

Shadow Wizard
Giant
Posts: 192
Joined: Mon Apr 11, 2011 8:11 pm

Re: Manually breaking out of an endless loop.

Post by Shadow Wizard »

Oh, I will once the macro is finished. However if I accidently run a while loop, that is based on a variable that I accidently forget to change somewhere, or thought it would change but didn't I needed a way to stop it.
However if it will run 10,000 times and then error out, then I guess that will work. Its only for during the debugging stage, the equivalent of a ctrl-c
And about how long will it take to error out (I know, will vary depending on computer power) but are we talking almost instant, 5-10 min? I just don't want to be ending task on maptool just because I am not being patient.

User avatar
aliasmask
RPTools Team
Posts: 9031
Joined: Tue Nov 10, 2009 6:11 pm
Location: California

Re: Manually breaking out of an endless loop.

Post by aliasmask »

Depends on what is being processed, ie how many lines. If it would normally take 15 ms to run, then that would be about 2 1/2 minutes.

Jmr3366
Cave Troll
Posts: 82
Joined: Fri Feb 04, 2022 1:08 pm

Re: Manually breaking out of an endless loop.

Post by Jmr3366 »

Shadow Wizard wrote:
Thu Nov 03, 2022 10:42 pm
Oh, I will once the macro is finished. However if I accidently run a while loop, that is based on a variable that I accidently forget to change somewhere, or thought it would change but didn't I needed a way to stop it.
However if it will run 10,000 times and then error out, then I guess that will work. Its only for during the debugging stage, the equivalent of a ctrl-c
And about how long will it take to error out (I know, will vary depending on computer power) but are we talking almost instant, 5-10 min? I just don't want to be ending task on maptool just because I am not being patient.
Almost any while loop I use includes this technique.

Code: Select all

[h: sLoop = 0]
[h, while(this!=that && sLoop<250),CODE:{
	 < normal code here>
	[h: sLoop = sLoop + 1]
}]

User avatar
aliasmask
RPTools Team
Posts: 9031
Joined: Tue Nov 10, 2009 6:11 pm
Location: California

Re: Manually breaking out of an endless loop.

Post by aliasmask »

You could get rid of sLoop and just use roll.count. That gives you the current iteration. I usually only reference roll.count at the top of the loop because there things that can affect it like other function calls. roll.count starts at 0.

Jmr3366
Cave Troll
Posts: 82
Joined: Fri Feb 04, 2022 1:08 pm

Re: Manually breaking out of an endless loop.

Post by Jmr3366 »

aliasmask wrote:
Fri Nov 04, 2022 10:05 am
You could get rid of sLoop and just use roll.count. That gives you the current iteration. I usually only reference roll.count at the top of the loop because there things that can affect it like other function calls. roll.count starts at 0.
That's actually part of why I use that s(afety)Loop because I got burned by roll.count resets :p and wanting to use the variable throughout the While :p

User avatar
aliasmask
RPTools Team
Posts: 9031
Joined: Tue Nov 10, 2009 6:11 pm
Location: California

Re: Manually breaking out of an endless loop.

Post by aliasmask »

Jmr3366 wrote:
Fri Nov 04, 2022 2:20 pm
aliasmask wrote:
Fri Nov 04, 2022 10:05 am
You could get rid of sLoop and just use roll.count. That gives you the current iteration. I usually only reference roll.count at the top of the loop because there things that can affect it like other function calls. roll.count starts at 0.
That's actually part of why I use that s(afety)Loop because I got burned by roll.count resets :p and wanting to use the variable throughout the While :p
Yeah, that's a good precaution, but if you're only checking inside the condition, nothing is going to mess with that value. Typically when referencing roll.count, the first line in my loop is "[H: index = roll.count]" and I use index throughout the loop. Obviously with a while loop whatever you use has to be defined before the loop starts, but using roll.count directly is pretty safe in this instance.

Shadow Wizard
Giant
Posts: 192
Joined: Mon Apr 11, 2011 8:11 pm

Re: Manually breaking out of an endless loop.

Post by Shadow Wizard »

I ended up accidently programming and endless loop at one point. Took less then 10 seconds to error out.

Post Reply

Return to “Macros”