• You've discovered RedGuides, an EverQuest multi-boxing and scripting community 🧙‍♀️⚙️. We want you to play several EQ characters at once, come join us and say hello! 👋

  • A TLP without truebox has thawed (Very Vanilla ready)
    Frostreaver

Question - Looping in a maco . . .

Joined
Feb 28, 2017
RedCents
108¢
Trying to loop a macro eight times and then end. How do I limit the loop to eight?

:loop

/goto :loop

my knowledge is very limited.

Appreciate the help
 
There are a few ways. A for loop (easiest, most convenient for this scenario), a while loop, and adding an iterator to your alreadymade goto.

For Loop:
[CODE title="for loop"]Sub Main
/declare i int local 0
/for i 1 to 8
/whateveryouwanttodo8times
/next i
/code after
/return[/CODE]

While Loop:
[CODE lang="ini" title="while loop"]Sub Main
/declare i int local 0
/while (${i} < 8) {
/docode8times
/varcalc i ${i} + 1
}
/code after
/return[/CODE]

Adding an iterator to what you have already
[CODE lang="ini" title="goto"]Sub Main
/declare i int local 0
:loop
/dowhatever you want here
/varcalc i ${i} + 1
/if (${i} < 8) /goto :loop
/code after
/return[/CODE]

Standard coding practices say to use a for loop for this scenario. While loops are also acceptable (like if you want to create 8 of an item but fail once, you can say while(item I want < 8). Goto loops make your code look a little sloppy and once you start calling subs and trying to navigate your subs with gotos, it can (and probably will) get really messy really quick.
 
Question - Looping in a maco . . .

Users who are viewing this thread

Back
Top
Cart