Help with int variable in /for.

Need help with a macro you are writing? Ask here!

Moderator: MacroQuest Developers

NobodyImportant
a lesser mummy
a lesser mummy
Posts: 46
Joined: Sun Nov 02, 2003 8:42 pm

Help with int variable in /for.

Post by NobodyImportant » Mon May 31, 2004 12:42 pm

Ok, so i have looked at countless AFK cleric macs, and just simply trying to convert my old one to MQ2 Data and this code keeps giving me an error.

Code: Select all

Sub Main 
/declare GroupMax int outer
/declare GroupMember int outer



:chkevent 

/call autoheal

/goto :chkevent


/return
There is alot more code but this is the only relavent stuff. So now out of that mac it calls autoheal out of a .inc file

Code: Select all

Sub Autoheal

/for GroupMember 0 to ${GroupMax}
     /delay 0
  /if (${String["${Me.Class}"].Equal["Cleric"]}) {
       /if (${Group[${GroupMember}].PctHPs}<60) {
         /call IF1
       }
     } else {
/if (${String[${Group[${GroupMember}].Class}].NotEqual[Cleric]}) {
         /if (${Group[${GroupMember}].PctHPs}<25) /call IF1
       }
   }
     /next GroupMember
/return
I tried pasting the code into the actual cleric mac but I get the same error.

Error : /for loops must use an int variable.

Then it spews out the lines that use /for.

Virtuoso65
a hill giant
a hill giant
Posts: 150
Joined: Wed Oct 15, 2003 2:29 pm

Post by Virtuoso65 » Mon May 31, 2004 1:30 pm

How about this, try defining your two vars as global.

afaik the var define system works like this.

local, only works in the main sub.
outer, works in the main and all subs in the macro.
global, works in this macro and any others that call on the same var this includes .inc files.

dman
a hill giant
a hill giant
Posts: 181
Joined: Fri Dec 05, 2003 12:54 pm

Post by dman » Tue Jun 01, 2004 4:52 am

afaik the var define system works like this.

local, only works in the main sub.
outer, works in the main and all subs in the macro.
global, works in this macro and any others that call on the same var this includes .inc files.
Local/inner works only within the sub that creates the variable.
Outer works within the complete macro as it is, including the includes.
Global is just that, global to macroquest, it stays and can be set/accessed until its manually deleted or macroquest ends (useful for keybinds/huds and stuff like that)


With that said, I see in the code you pasted as relevant that you have

Code: Select all

/declare GroupMax int outer 
/declare GroupMember int outer 
but nowhere have you set ${GroupMax} to a value, so could be the reason as to why the /for loop is crashing out.

Chill
Contributing Member
Contributing Member
Posts: 435
Joined: Fri May 07, 2004 5:06 pm
Location: Erie, PA

Post by Chill » Tue Jun 01, 2004 5:26 am

Okay, I cant say I understand the logic, but I think I see the problem: The number of people in a group is just ${Group}, not ${GroupMax}. Also, ${Group[x].Class.Name} is a string, so you can avoid the string conversion by adding .Name.

Code: Select all

Sub Autoheal 

/for GroupMember 0 to [b]${Group}[/b]
  /delay 1
  /if (${Me.Class.Name.Equal[Cleric]}) {
     /if (${Group[${GroupMember}].PctHPs}<60) /call IF1
  } else { 
     /if (${Group[${GroupMember}].Class.Name.NotEqual[Cleric]}) { 
        /if (${Group[${GroupMember}].PctHPs}<25) /call IF1 
     } 
  } 
/next GroupMember 

/return
Untested but should work

dman
a hill giant
a hill giant
Posts: 181
Joined: Fri Dec 05, 2003 12:54 pm

Post by dman » Tue Jun 01, 2004 5:31 am

I had considered saying to use ${Group} instead of ${GroupMax} but I then considered that he might not want to heal the last few members of the group and so GroupMax could be lower than Group in some cases so I went with the variables he had declared. :)