• You've discovered RedGuides 📕 an EverQuest multi-boxing community 🛡️🧙🗡️. We want you to play several EQ characters at once, come join us and say hello! 👋
  • IS THIS SITE UGLY? Change the look. To dismiss this notice, click the X --->

Guide - The forgotten macro language feature: /break and /continue (1 Viewer)

Joined
Mar 23, 2017
RedCents
1,560¢
Out of curiosity I counted how often /break and /continue are used in all macros in the RG distribution. To my surprise that number was just 1 each. Of course not beeing mentioned in the wiki until yesterday might have contributed to this situation. So what are these commands doing ? You can end a /for loop immediately with /break or try the next iteration with /continue. See: http://www.macroquest2.com/wiki/index.php/For. This might soon also be available for /while loops.
 
Out of curiosity I counted how often /break and /continue are used in all macros in the RG distribution. To my surprise that number was just 1 each. Of course not beeing mentioned in the wiki until yesterday might have contributed to this situation. So what are these commands doing ? You can end a /for loop immediately with /break or try the next iteration with /continue. See: http://www.macroquest2.com/wiki/index.php/For. This might soon also be available for /while loops.

The reason you don't see these used very often is anyone that has taken top-down programming was taught never to use these commands. You always want to end a for loop gracefully or change that to a while loop instead of using a break command. This school of thought was beating into any programmer prior to touching macroquest2. Now that said, those that didn't take programming in school will probably use them. I for one never do, just because I'm afraid my old teacher from 20+ years ago might jump out of nowhere and scold me for using such commands. Although he has probably passed away, he was like 60+ back in the 90s, but that makes it even scarier that his spirit would be disappointed if I used such commands. Same thing goes for goto command. That is another forbidden command that exists, but must never be used.

So if you are asking why not use the commands? The reason back then was if you programmed your code properly you wouldn't have to use such commands.

Its basically like the matrix
Neo: What are you trying to tell me? That I can dodge bullets?
Morpheus: No, Neo. I'm trying to tell you that when you're ready, you won't have to.
 
Can't say I was ever taught not to use break and continue, and use similar language features almost daily to no professional detriment. Definitely happy to find /break, i can replace a bunch of /goto :EndLoop calls in my own code.
 
The /break and /continue command are broken. The core code does NOT take into consideration Nested /for /next loops.

If your /for /next is not nested, then /break /continue works fine.

This is probably not relevant anymore, but this was my fix to the core back in June 2016:

Rich (BB code):
// ***************************************************************************
// Function:    Continue
// Description: Our '/continue' command
// Usage:       /continue
// ***************************************************************************
VOID Continue(PSPAWNINFO pChar, PCHAR szLine)
{
   int extraFors = 0;

   if (!gMacroBlock) 
   {
        MacroError("Can only use /continue during a macro.");
        return;
    }

   while (bRunNextCommand == TRUE) //FIX?
   {   
      if (!strnicmp(gMacroBlock->Line,"Sub ",4) || (!gMacroBlock->pNext))
      {
         FatalError("/continue without matching /for ... /next block");
         return;
      } 
     if (!strnicmp(gMacroBlock->Line,"/for",4)) {
        extraFors++;
     } else if (!strnicmp(gMacroBlock->Line,"/next",5)) {
           if (extraFors) 
            extraFors--;
          else
          {
               gMacroBlock = gMacroBlock->pPrev;         
               break;
          }
      }
      gMacroBlock = gMacroBlock->pNext;
   }
}

// ***************************************************************************
// Function:    Break
// Description: Our '/break' command
// Usage:       /break
// ***************************************************************************
VOID Break(PSPAWNINFO pChar, PCHAR szLine)
{
   int extraFors = 0;
   if (!gMacroBlock) 
   {
        MacroError("Can only use /break during a macro.");
        return;
    }

   while (bRunNextCommand == TRUE) //FIX?
   {   
      if (!strnicmp(gMacroBlock->Line,"Sub ",4) || (!gMacroBlock->pNext))
      {
         FatalError("/break without matching /for ... /next block");
         return;
      } 
     if (!strnicmp(gMacroBlock->Line,"/for",4)) {
        extraFors++;
     } else if (!strnicmp(gMacroBlock->Line,"/next",5)) {
        if (extraFors)
         extraFors--;
       else
            break;
     }
      gMacroBlock = gMacroBlock->pNext;
   }
}
 
I remember while conditions being a little flaky and not well documented last time I coded a new macro. Of course for loops had the same issue. I could see using a for loop for a buff routine and wanting to break it harshly if we got in combat. You could do the same with a well written while. Which is better? Who knows except whomever coded the mq2 interpreter. I'm very old-school, we still had goto's for our teachers to scold over, so then never got around to continues.

Hmm, any chance of switch {} conditionals in MQ2 ? Then I could write a proper state engine macro and watch it lag out my computer.

?
 
I remember while conditions being a little flaky and not well documented last time I coded a new macro. Of course for loops had the same issue. I could see using a for loop for a buff routine and wanting to break it harshly if we got in combat. You could do the same with a well written while. Which is better? Who knows except whomever coded the mq2 interpreter. I'm very old-school, we still had goto's for our teachers to scold over, so then never got around to continues.

Hmm, any chance of switch {} conditionals in MQ2 ? Then I could write a proper state engine macro and watch it lag out my computer.

?

Whiles work fine in MQ2. You just can't have any mismatched brackets with in the while loop. I have always wanted to get the /break, and /continue to work properly, that way we could get rid of a lot of /goto's in KA. /goto's are the slowest, since the /goto command causes to interpreter to go to the top of the current sub and search till it finds the /goto Label.
 
Whiles work fine in MQ2. You just can't have any mismatched brackets with in the while loop. I have always wanted to get the /break, and /continue to work properly, that way we could get rid of a lot of /goto's in KA. /goto's are the slowest, since the /goto command causes to interpreter to go to the top of the current sub and search till it finds the /goto Label.
That's the next thing I plan to look at once functions are sorted out. It should work for /while and /for with nesting.
 
The reason you don't see these used very often is anyone that has taken top-down programming was taught never to use these commands. You always want to end a for loop gracefully or change that to a while loop instead of using a break command.

You have a list of integers. You want to know if the list contains a 7. You're looping and find a 7. What do you do?
 
Guide - The forgotten macro language feature: /break and /continue

Users who are viewing this thread

Back
Top