• Hail, we're RedGuides. We want you to play six (yes, 6!) EverQuest characters at once. We have scripts and a friendly community to help, please join our playstyle and say hello! 👋
  • We've added LLM sections to our Terms & Rules and Resource Rules, for everyone's sanity & in-game safety.
    Read more
    a. Do not replace your voice with an LLM. This goes for your posts and your scripts. Drafting and editing with a tool is fine, but don't take you out of what you share.
    b. Do not replace your EQ character's voice with an LLM. We don't want scripts that speak over /ooc, /shout or other public channels. This has been an unwritten rule that's kept casino scripts off the site for decades, but we're now compelled to make it clear: keep automated communication private.

    Why Does RG Review Scripts?
    Nearly every LLM-written Lua script we see is making your character do impossible things, and rarely in a way that's beneficial to you. We've seen heavy server hammering, /target over impossible distances when /nav spawn would passively accomplish the same thing, a spawn search that fires 20+ times per second, and other pointless actions that are likely annoying GMs.

    You are welcome to use LLMs as a tool to structure, draft, and edit your work, but please read critically before hitting /lua run

Question - About exiting flow control (for/next, subs etc) (1 Viewer)

Bogreaper

Member
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