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

foromoro

Well-known member
Joined
Dec 2, 2019
RedCents
233¢
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:

[CODE title="example"]/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}]}[/CODE]

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
 
[#] is usually a position in an array. I don't know what [|] is supposed to be
 
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