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?
Manually breaking out of an endless loop.
Moderators: dorpond, trevor, Azhrei, giliath, jay, Mr.Ice
-
- Giant
- Posts: 192
- Joined: Mon Apr 11, 2011 8:11 pm
Re: Manually breaking out of an endless loop.
Make sure you have a condition that will always break the loop. Otherwise, it will loop 10,000 times and then error out.
Downloads:
- Notepad++ MapTool addon
- RPEdit details (v1.3)
- Coding Tips: Modularity and Design
- Videos: Macro Writing Tools
-
- Giant
- Posts: 192
- Joined: Mon Apr 11, 2011 8:11 pm
Re: Manually breaking out of an endless loop.
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.
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.
Re: Manually breaking out of an endless loop.
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.
Downloads:
- Notepad++ MapTool addon
- RPEdit details (v1.3)
- Coding Tips: Modularity and Design
- Videos: Macro Writing Tools
Re: Manually breaking out of an endless loop.
Almost any while loop I use includes this technique.Shadow Wizard wrote: ↑Thu Nov 03, 2022 10:42 pmOh, 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.
Code: Select all
[h: sLoop = 0]
[h, while(this!=that && sLoop<250),CODE:{
< normal code here>
[h: sLoop = sLoop + 1]
}]
Re: Manually breaking out of an endless loop.
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.
Downloads:
- Notepad++ MapTool addon
- RPEdit details (v1.3)
- Coding Tips: Modularity and Design
- Videos: Macro Writing Tools
Re: Manually breaking out of an endless loop.
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
Re: Manually breaking out of an endless loop.
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.
Downloads:
- Notepad++ MapTool addon
- RPEdit details (v1.3)
- Coding Tips: Modularity and Design
- Videos: Macro Writing Tools
-
- Giant
- Posts: 192
- Joined: Mon Apr 11, 2011 8:11 pm
Re: Manually breaking out of an endless loop.
I ended up accidently programming and endless loop at one point. Took less then 10 seconds to error out.