• 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 - Determining total number of parameters/variables for a /for loop

foromoro

Well-known member
Howdy all! I've seen various macros that are able to define a range of variables and then calculate/define another variable which is, itself, just the sum total of the NUMBER of variables previously set. For example, this snippet here in a macro that checks an ini for how many merchants are listed in it, and defines the total merchant count which is then later used in a /for loop:

example
Code:
/declare MerchantCount int local ${Ini[${IniFile},${Zone.ShortName}-Merchants].Count[|]}
/declare MerchantCount2 int local ${Ini[${IniFile},${Zone.ShortName}-Merchants2].Count[|]}
/declare MerchTotal int local 0
/varcalc MerchTotal ${Math.Calc[${MerchantCount}+${MerchantCount2}]}

Two questions about this. First, just so I have a better knowledge of all this stuff, in the /declare MerchantCount lines what is the purpose of the [|] being placed after "Count" ??

But to my more specific question, can you only count up the number of variables if pulling the information from an ini? Stated otherwise, can I achieve this same thing from within--and ONLY within--a macro? I don't mind the answer being no, just trying to find out if I can do like a "Item1" "item2" "item3" etc. from within a macro and then run the macro from a /for loop instead of having 10 placeholder variables where 7 are named NULL
 
Through your answer I think I should be able to achieve what I am trying to do by setting it all up as an ItemName array instead of what I was previously doing. I will tinker with it!
 
1731259710152.png
Nah I found it. Just because it looks like my code doesn't mean it was :-). There are plenty of talented macro authors out and about somewhere.
I was on my phone when I first responded.

So ${Ini{Filename, Section]} by itself would get all keys in the section of the INI with that file name. It's automatically separated by |. So when you do a .Count[|] it's counting how many | there are. You can then use that to loop efficiently through all the different keys. This does have it's limits, but as long as the list of keys doesn't exceed 2048 characters (also known as MAX_STRING) then you can effectively cycle through all the merchants in the INI without needing to keep a separate key for the number of merchants.
 
But to my more specific question, can you only count up the number of variables if pulling the information from an ini? Stated otherwise, can I achieve this same thing from within--and ONLY within--a macro? I don't mind the answer being no, just trying to find out if I can do like a "Item1" "item2" "item3" etc. from within a macro and then run the macro from a /for loop instead of having 10 placeholder variables where 7 are named NULL

any logic requiring more than a line of code (for loops for example) need to be handled within a Lua/macro/plugin. You cannot do a for loop without a macro.

That said unless you mean literally "item1", "item2", "item3" and not "Greatsword of Happy Killing", "Robe of All The Mana", "Breakfast Sandwich of Spoiled Eggs" then it would be a bit more complicated to loop that way.
for example
Code:
Sub Main
    /declare i int local 0
    /for i 1 to 20
        /if (item${i}) {
            /blah
        }
    /next i
/return

Code:
|Add more items as needed, put a | at the end of each entry to keep the count accurate.
/declare itemlist string local "Greatsword of Happy Killing|Robe of All The Mana|Breakfast Sandwich of Spoiled Eggs|"
/declare itemcount int local ${itemlist.Count[|]}
/echo Checking out ${itemcount} items.

/declare i int local 0
/for i 1 to ${itemcount}
    /if (!${FindItem[${itemlist.Arg[1,|]})]}) {
        /echo I don't have ${itemlist.Arg[1,|}
    } else {
        /echo I have ${itemlist.Arg[1,|]}
    }
/next i

these are examples of just making up stuff off the top of my head. It's been a while since I've messed with macros so the code should work but also might not lol.

With that said, knowing macro logic is generally fine if you're editing an existing project. But if you're going through the trouble to learn coding for the purpose of EQ I recommend looking into Lua. It's a proper language and it'll have uses beyond just MQ.
 
Question - Determining total number of parameters/variables for a /for loop

Users who are viewing this thread

Back
Top
Cart