Page 1 of 1

Help with int variable in /for.

Posted: Mon May 31, 2004 12:42 pm
by NobodyImportant
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.

Posted: Mon May 31, 2004 1:30 pm
by Virtuoso65
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.

Posted: Tue Jun 01, 2004 4:52 am
by dman
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.

Posted: Tue Jun 01, 2004 5:26 am
by Chill
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

Posted: Tue Jun 01, 2004 5:31 am
by dman
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. :)