• 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 - Array - Loop - Goto

So I'm attempting to dabble a bit more into macro writing and thought I'd jump into Arrays. I have built an array that populates just fine, and I thought I'd add a bit more code and started running into issues. So first my "working" array code:
Rich (BB code):
Sub MainGotoArrayTest
  /declare EquipID[33] int local
  /declare loop1 int local 0
  /declare array1 int local 1
  :TakeOffGear
	/delay .5s
	/echo ${Me.Inventory[${loop1}]} ${Me.Inventory[${loop1}].ID}
	|/unequip ${loop1}
	/varset EquipID[${array1}] ${Me.Inventory[${loop1}].ID}
	/varcalc loop1 ${loop1}+1
	/varcalc array1 ${array1}+1
	/delay 1s
	/echo Unequiping ${Me.Inventory[${loop1}]} now!
|	/unequip ${loop1}
/if (${loop1}<=20) /goto :TakeOffGear


 /declare loop2 int local 0
 /declare array2 int local 1
 :PutOnGear
       |/exchange EquipID[${array2}] ${loop2}
       /echo Array2 item number: ${EquipID[${array2}]}, slot number: ${loop2}
       /varcalc loop2 ${loop2}+1
       /varcalc array2 ${array2}+1
       /delay 1s
 /if (${loop2}<=20) /goto :PutOnGear

/return

So as I said, this worked fine (other than the commented out section which is my problem). Basic jest of what I originally was doing with the array stuff. I wanted to populate an array with all my worn equipment, then turn around and spit out the data. This all worked as intended. Then I wanted to add some more function to the code and unequip each piece and then reequip the equipment. And this is where I ran into issues. The code doesn't throw any errors, but what keeps happening is that the first item in the array is identified, but isn't unequiped, but each and every other piece does get unequip'd as the GOTO statement continues. I basically stopped there and have been trying to do various other things to see if I can't get this working right (I just plain commented out the /exchange portion and didn't even try it yet)

So I rewrote the code using For Loops and got the same thing.... the first items is populated into the array, but is skipped for unequiping. So you guru's please let me know what I'm doing wrong, I'm sure it is something simple in regards to the way I'm writing this and attempting to do the /unequip command within the loop.
 
In Sub MainGotoArrayTest you are incrementing your loop variables before you /echo unequip ...

If you alter the sub slightly to the following, it echoes for all items.
Rich (BB code):
Sub Main
  /declare EquipID[33] int local
  /declare loop1 int local 0
  /declare array1 int local 1
  :TakeOffGear
	/delay .5s
	/echo ${Me.Inventory[${loop1}]} ${Me.Inventory[${loop1}].ID}
	|/unequip ${loop1}
	/varset EquipID[${array1}] ${Me.Inventory[${loop1}].ID}
	/delay 1s
	/echo Unequiping ${Me.Inventory[${loop1}]} now!
|	/unequip ${loop1}
	/varcalc loop1 ${loop1}+1
	/varcalc array1 ${array1}+1
/if (${loop1}<=20) /goto :TakeOffGear


 /declare loop2 int local 0
 /declare array2 int local 1
 :PutOnGear
       |/exchange EquipID[${array2}] ${loop2}
       /echo Array2 item number: ${EquipID[${array2}]}, slot number: ${loop2}
       /varcalc loop2 ${loop2}+1
       /varcalc array2 ${array2}+1
       /delay 1s
 /if (${loop2}<=20) /goto :PutOnGear

/return

Because MQ has built in support for for loops, I would suggest doing the following:
Rich (BB code):
Sub Main
  /declare EquipID[33] int local
  /declare slot int local
  /declare arrayIndex int local

  /for slot 0 to 20
    /varcalc arrayIndex ${slot}+1
    /delay .5s
    /echo ${Me.Inventory[${slot}]} ${Me.Inventory[${slot}].ID}
    /varset EquipID[${arrayIndex}] ${Me.Inventory[${slot}].ID}
    /delay 1s
    /echo Unequiping ${Me.Inventory[${slot}]} now!
    /unequip ${slot}
  /next slot

  /for slot 0 to 20
    /varcalc arrayIndex ${slot}+1
| EquipID[${...}] needs to be inside of ${}
    /exchange ${EquipID[${arrayIndex}]} ${slot}
    /echo Array2 item number: ${EquipID[${arrayIndex}]}, slot number: ${slot}
    /delay 1s
  /next slot

  /deletevar slot
  /deletevar arrayIndex
/return

To me, anyway, this is a little more readable, and you don't have to worry about incrementing the loop yourself. Hope it helps, if not let me know.

Edit: A couple notes - I think inventory slots are in the range 0-22, so EquipID can be of size [23], and the loop can go /for slot 0 to 22 to loop through all inventory (non-bag) slots.
 
Edit: A couple notes - I think inventory slots are in the range 0-22, so EquipID can be of size [23], and the loop can go /for slot 0 to 22 to loop through all inventory (non-bag) slots.
Yeah, I was just initially just playing with arrays so I was using the whole array size for the command. I will neck it down now that I see something I would like to contribute to community via a macro to all but the ammo slot for worn items.
 
Question - Array - Loop - Goto

Users who are viewing this thread

Back
Top
Cart