• 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 - About exiting flow control (for/next, subs etc)

Bogreaper

Member
Joined
Feb 8, 2017
RedCents
113¢
I have always been taught to properly exit all routines or you might end up with a stack issue.
This was a great big deal back in my younger days (late 70s).

My question is.. I see some inc and macs doing this.

Sub checkitout

/if (${Target.ID<1}) /return
/if (${Target.Type.Equal[NPC]}) {
/echo NPC!
}

/return

I don't know if this is right or not.

I do know that I had seen people doing.

/for countemdown 1 to 100

/if (${Target.ID<1}) /next countemdown
/if (${Target.Type.Equal[NPC]}) {
/echo NPC!
}

/next countemdown

and with the last update those all stopped working due to it parsing out an extra /next with no for.

My question is this. Is it ok to exit the sub early like that? or is that a bad practice and we can expect issues in the future? (Me personally, I am expecting issues in the future)

Thanks and Peace
 
No. Doing a /return out of a subroutine is normal, but it does break the rules for top down programming. In most languages there is a way to exit a routine early and is allowable, but it should be avoided when possible.

MQ2 sub routines are defined as Sub SomeRoutine and closed using the /return so using a /return in the middle of a sub routine will POP the stack properly, well it did the last time I reviewed the source code. I am not the MQ2 expert here, but my assumption is that they haven't changed the way the /return works when used in a sub routine.
 
This would be fine:

Rich (BB code):
/if (${Target.ID<1}) /return
 /if (${Target.Type.Equal[NPC]}) {
     /echo NPC!
 }

This:

Rich (BB code):
/for countemdown 1 to 100

 /if (${Target.ID<1}) /next countemdown
 /if (${Target.Type.Equal[NPC]}) {
 /echo NPC!
 }

 /next countemdown

Should be done like this:

Rich (BB code):
/for countemdown 1 to 100

    /if (${Target.ID<1}) /continue
    /if (${Target.Type.Equal[NPC]}) {
        /echo NPC!
    }

/next countemdown

And if you need to exit the /for /next loop early use the /break command
 
Question - About exiting flow control (for/next, subs etc)

Users who are viewing this thread

Back
Top
Cart