SIMPLE question - I must be dense

Help section from before the user variable changes that broke all macros

Moderator: MacroQuest Developers

BorealisSunbinder
orc pawn
orc pawn
Posts: 12
Joined: Thu Oct 17, 2002 6:28 pm

SIMPLE question - I must be dense

Post by BorealisSunbinder » Tue Oct 22, 2002 4:51 pm

I've gone through the system documentation and managed to confuse myself and I'm hoping someone might have the inclination to help me out. Here is a simple part of the combine.mac that I've been successful in implementing, at least enough to know that it works fine, however in picking it apart to understand how MQ works in general, I've come across a gaping hole in my basic understanding......MQ variables.

1. Sub FindCombiner
2. /varset v10 99
3. /for v99 0 to 7
4. /if "$pack($v99,combine)"=="$p0" /varset v10 $v99
5. /next v99
6. /return $v10

In line 2. is a variable named v10 created with an initial value of 99? Or is a variable v99 created to be used as a step counter for the /for .. /next loop?

Assuming a variable named v99 is created, and the /for command initializes it's value at 0 in line 3., in the /if statement $v99 is used to identify the position in which a pack might be. Does $v99 represent the value in variable v99? Is it a string literal substitution for the variable? And then if the /if evaluates TRUE the variable v10 is set to the value in v99?

As you can see, I'm confused I guess as the way the /varset command is working and the way the values in a variable are being represented. I think I understand what ultimately is happening, this subroutine is locating the pack with the name specified in the first pass variable on the command line ("$p0"?), and then returning the inventory position that pack is in. I'm just a tad confused about how it's doing it.

If anyone has a chance to step through these 6 lines and let me know specifically what is happening, I'd be very appreciative.

eqaddict
a lesser mummy
a lesser mummy
Posts: 74
Joined: Sun Sep 15, 2002 10:05 pm

Post by eqaddict » Tue Oct 22, 2002 5:15 pm

1. Sub FindCombiner
2. /varset v10 99
3. /for v99 0 to 7
4. /if "$pack($v99,combine)"=="$p0" /varset v10 $v99
5. /next v99
6. /return $v10
The objective of the routine is to find a container among your pack items. The pack items are the containers in your inventory. I am going to write some pseudo code to help explain whats going on. The use of 99 as a variable and 99 as a default error value is causing the confusion. They are seperate and distinct. The /varset v10 99 means v10=99

Code: Select all

1 Sub FindContainer ContainerType
2 PackLoc=99
3 for i = 0 to 7
4    if Pack(i)==ContainerType  then PackLoc=i
5 next i
6 return packLoc
Note: It does find the LAST occurance of the container type and not the first.


--EqAddict

p.s. If I caused more confusion I apologize up front :D

BorealisSunbinder
orc pawn
orc pawn
Posts: 12
Joined: Thu Oct 17, 2002 6:28 pm

Post by BorealisSunbinder » Tue Oct 22, 2002 6:18 pm

Ahh so the variable in line 2 -- v99 -- isn't predefined, it's defined as it's used in the /for loop. I was a little hung up on the idea that the variable had to be defined somewhere with a /varset prior to use; I guess some really old programming biases hampering me again.

So /varset v10 99 sets the default value of a variable called v10. The $v99 in line 4 is a macro substitution of the value in a variable called v99. So the first time through the /for ... /next loop the if statement, after substitution actually looks like (to the computer):

/if "$pack(0,combine)"=="$p0" /varset v10 0

ie. if you find a the pack named in the variable $p0 then set the v10 (PackLoc) varaible to the current position, first time through this is 0.

You're right, the default value of 99 and the variable name of 99 was confusing me.

Thanks Mr. Addict