Help with Simple move mac

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

Moderator: MacroQuest Developers

User avatar
Stults
a lesser mummy
a lesser mummy
Posts: 52
Joined: Tue May 25, 2004 11:47 pm

Help with Simple move mac

Post by Stults » Wed May 26, 2004 7:20 am

I am new at writing macro's but I am atempting to write my own, just need a little guidance. With that being said what I want to create is, a simple square that my character will run instead of that silly circle. Now is this even possible to code? I am brand new at all of this MQ2 and programming stuff, and just need a little shove in the right direction.

I am thinking I need to set up usage like this: /Move.mac <YLoc, XLoc> <YLoc, XLoc> <YLoc, XLoc> <YLoc, XLoc>

This is to place in the 4 /loc's that are needed.

So I would declare like this maybe for each loc defined?

/declare aYLoc int outer
/declare aXLoc int outer
/declare bYLoc int outer
/declare bXLoc int outer
/declare cYLoc int outer
/declare cXLoc int outer
/declare dYLoc int outer
/declare dXLoc int outer

Now this is where I run into my problem. Can the above even be used? And if it can, how do I get it to place in each loc for the usage? Maybe something like this?

/mac Move.mac 100 -100 200 -200 300 -300 400 -400

That would define each loc I would like to run too and from. Now how do I go about setting each of those variables? This is the trouble I am having and any help would be appreciated. Just a little nudge in the right direction would help me a ton and help me to learn how to write this code. After all I am trying :wink:

Will this work at all for setting the loc's?

/varset aYLoc ${YLoc}
/if (!${Defined[aYLoc]}) {
/echo First Loc set at ${YLoc}
}
/varset aXLoc ${XLoc}
/if (!${Defined[aXLoc]}) {
/echo First Loc set at ${XLoc}
}
/varset bYLoc ${YLoc}
/if (!${Defined[bYLoc]}) {
/echo Second Loc set at ${YLoc}
}
/varset bXLoc ${XLoc}
/if (!${Defined[bXLoc]}) {
/echo Second Loc set at ${XLoc}
}
/varset cYLoc ${YLoc}
/if (!${Defined[cYLoc]}) {
/echo Thrid Loc set at ${YLoc}
}
/varset cXLoc ${XLoc}
/if (!${Defined[cXLoc]}) {
/echo Third Loc set at ${XLoc}
}
/varset dYLoc ${YLoc}
/if (!${Defined[dYLoc]}) {
/echo Fourth Loc set at ${YLoc}
}
/varset dXLoc ${XLoc}
/if (!${Defined[dXLoc]}) {
/echo Fourth Loc set at ${XLoc}
}

Again, please dont rip my head off, I am trying to learn this stuff and am looking for a nudge. Thanks guys!

Preocts
a snow griffon
a snow griffon
Posts: 312
Joined: Thu Jan 29, 2004 1:02 pm

Post by Preocts » Wed May 26, 2004 12:00 pm

Code: Select all

Sub Main(int AXLoc,int AYLoc, int BXLoc,int BYLoc, on and on and on)
Puts all eight values you pass to the macro into the said var names. If you don't pass eight values it fills the parameters from left to right, declaring them as it goes as int (because of the int before the name). Should there be no value to put in the parameter it is not declared. Hence:

Code: Select all

|Were all eight values given
  /if (!${Defined[DYLoc]}) {
    /echo You didn't fill in all eight needed values
    /endmacro
  }

s16z
a ghoul
a ghoul
Posts: 97
Joined: Thu Apr 01, 2004 12:03 pm

Post by s16z » Wed May 26, 2004 1:16 pm

Or you could use the nifty Macro top level object:

Code: Select all

/if (${Macro.Params}!=8) {
    /echo Need 8 parameters
    /endmacro
}

User avatar
Stults
a lesser mummy
a lesser mummy
Posts: 52
Joined: Tue May 25, 2004 11:47 pm

Re:

Post by Stults » Wed May 26, 2004 5:50 pm

Preocts thanks alot :D

When I thought this mac up I never thought it would be able to do that!!!
And what you gave me is the nudge I needed.

User avatar
Stults
a lesser mummy
a lesser mummy
Posts: 52
Joined: Tue May 25, 2004 11:47 pm

Re:

Post by Stults » Wed May 26, 2004 10:30 pm

Ok just a few things...

Code: Select all

Sub Main(int AXLoc, int AYLoc, int BXLoc, int BYLoc, int CXLoc, int CYLoc, int DXLoc, int DYLoc)

   /declare AXLoc int outer
   /declare AYLoc int outer
   /declare BXLoc int outer
   /declare BYLoc int outer
   /declare CXLoc int outer
   /declare CYLoc int outer
   /declare DXLoc int outer
   /declare DYLoc int outer

   | Check for correct locations used.
   /if (!${Defined[DYLoc]}) {
      /echo Usage: /macro Move.mac <AXLoc, AYLoc> <BXLoc, BYLoc> <CXLoc, CYLoc> <DXLoc, DYLoc>
      /endmacro
   } 

   /varset AXLoc ${AXLoc}
   /varset AYLoc ${AYLoc}
   /varset BXLoc ${BXLoc}
   /varset BYLoc ${BYLoc}
   /varset CXLoc ${CXLoc}
   /varset CYLoc ${CYLoc}
   /varset DXLoc ${DXLoc}
   /varset DYLoc ${DYLoc}

   /echo Running a square with First Loc at ${AXLoc}, ${AYLoc}
   /echo Running a square with Second Loc at ${BXLoc}, ${BYLoc}
   /echo Running a square with Third Loc at ${CXLoc}, ${CYLoc}
   /echo Running a square with Fourth Loc at ${DXLoc}, ${DYLoc}

   | The main loop.

   /keypress autorun

   :Loop
   /call Sub First_Loc

Sub First_Loc

   /if (${Math.Distance[${AXLoc}, ${AYLoc}]}<${Math.Calc[$[color=red]{}[/color]/2]}) {
      /face heading ${Math.Calc[${Heading[${AXLoc}, ${AYLoc}].DegreesCCW}+180]}
   } else {
      /face heading ${Math.Calc[${Heading[${AXLoc, ${AYLoc}].DegreesCCW}+${Math.Calc[90*$[color=red]{}[/color]/${Math.Distance[${AXLoc}, ${AYLoc}]}]}]}
   }
   /if (${Math.Distance[${AXLoc}, ${AYLoc}]}=${Math.Calc[${Me.X}, ${Me.Y}]}) {
       /call Sub Second_Loc
   }

Sub Second_Loc

   /if (${Math.Distance[${BXLoc}, ${BYLoc}]}<${Math.Calc[$[color=red]{}[/color]/2]}) {
      /face heading ${Math.Calc[${Heading[${BXLoc}, ${BYLoc}].DegreesCCW}+180]}
   } else {
      /face heading ${Math.Calc[${Heading[${BXLoc, ${BYLoc}].DegreesCCW}+${Math.Calc[90*$[color=red]{}[/color]/${Math.Distance[${BXLoc}, ${BYLoc}]}]}]}
   }
   /if (${Math.Distance[${BXLoc}, ${BYLoc}]}=${Math.Calc[${Me.X}, ${Me.Y}]}) {
       /call Sub Third_Loc
   }

Sub Third_Loc

   /if (${Math.Distance[${CXLoc}, ${CYLoc}]}<${Math.Calc[$[color=red]{}[/color]/2]}) {
      /face heading ${Math.Calc[${Heading[${CXLoc}, ${CYLoc}].DegreesCCW}+180]}
   } else {
      /face heading ${Math.Calc[${Heading[${CXLoc, ${CYLoc}].DegreesCCW}+${Math.Calc[90*$[color=red]{}[/color]/${Math.Distance[${CXLoc}, ${CYLoc}]}]}]}
   }
   /if (${Math.Distance[${CXLoc}, ${CYLoc}]}=${Math.Calc[${Me.X}, ${Me.Y}]}) {
       /call Sub Fourth_Loc
   }

Sub Fourth_Loc

   /if (${Math.Distance[${DXLoc}, ${DYLoc}]}<${Math.Calc[$[color=red]{}[/color]/2]}) {
      /face heading ${Math.Calc[${Heading[${DXLoc}, ${DYLoc}].DegreesCCW}+180]}
   } else {
      /face heading ${Math.Calc[${Heading[${DXLoc, ${DYLoc}].DegreesCCW}+${Math.Calc[90*$[color=red]{}[/color]/${Math.Distance[${DXLoc}, ${DYLoc}]}]}]}
   }
   /if (${Math.Distance[${DXLoc}, ${DYLoc}]}=${Math.Calc[${Me.X}, ${Me.Y}]}) {
       /echo Square complete
   }
/goto :Loop
   
Basicly what I want this square to look like is not the perfect circle, and not a perfect square. So I took the circle code and made it check each Loc and goto it. Now the stuff listed in red is a varible that use to be CirR, and now I dont know what to turn it into. Will this code even work? I mean will it run to each Loc and not be a circle still? Or am I WAY off base...probably way off base as this is my first code I am trying to write lol :lol: Anyways much help again would be appreciated! Thanks!

User avatar
Stults
a lesser mummy
a lesser mummy
Posts: 52
Joined: Tue May 25, 2004 11:47 pm

Re:

Post by Stults » Thu May 27, 2004 9:39 pm

No love for my code out there? :cry:

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

Post by dman » Fri May 28, 2004 12:09 am

One thing that I see right away.

Code: Select all

Sub Main(int AXLoc, int AYLoc, int BXLoc, int BYLoc, int CXLoc, int CYLoc, int DXLoc, int DYLoc)
This will declare and set the variables for the 8 locs you are passing in as is, there is no need for all the.

Code: Select all

  /declare AXLoc int outer 
   /declare AYLoc int outer 
   /declare BXLoc int outer 
   /declare BYLoc int outer 
   /declare CXLoc int outer 
   /declare CYLoc int outer 
   /declare DXLoc int outer 
   /declare DYLoc int outer 

   /varset AXLoc ${AXLoc} 
   /varset AYLoc ${AYLoc} 
   /varset BXLoc ${BXLoc} 
   /varset BYLoc ${BYLoc} 
   /varset CXLoc ${CXLoc} 
   /varset CYLoc ${CYLoc} 
   /varset DXLoc ${DXLoc} 
   /varset DYLoc ${DYLoc} 

Also, you never /return from any of your subs, the purpose of a subroutine is to execute a block of code and return to the main code so as to allow you to reuse the subs code easier. The way you have it it looks to be just one big loop with one sub running into another and so on, this will cause problems and your macro won't parse past the first sub, if it gets that far. :)

User avatar
Stults
a lesser mummy
a lesser mummy
Posts: 52
Joined: Tue May 25, 2004 11:47 pm

Re:

Post by Stults » Fri May 28, 2004 12:24 am

Didnt know that, thanks!

I do want it to be one big loop though. When I first run the macro I want it to run to or check for the first location, and then run to or check for the second location so on so on. Once it completes the square I want it to go back to the first location and repeat. The only way I can figure to make it do that is to have each loc in a sub routine /shrug Any other suggestions?

s16z
a ghoul
a ghoul
Posts: 97
Joined: Thu Apr 01, 2004 12:03 pm

Post by s16z » Fri May 28, 2004 9:32 am

Code: Select all

Sub Main(blah blah blah)
| more blah setup

  :Loop
     /call First_Loc
     /call Second_Loc
     /call Third_Loc
     /call Fourth_loc
     /goto :Loop

/return

Sub First_Loc 
| Face the direction I want to go and start going there
  :FLLoop
    /if (I'm not where I want to end up) /goto :FLLoop

/return

Sub Second_Loc ....
Before anyone says, no this code isn't really code. It's to give you the idea of what you need to do.