Help proofreading converted macro

Need some help with that macro you're working on or aren't quite sure how to get your macro to do something? Ask here!

Moderator: MacroQuest Developers

Mckorr
Developer
Developer
Posts: 2326
Joined: Fri Oct 18, 2002 1:16 pm
Location: Texas

Help proofreading converted macro

Post by Mckorr » Mon Oct 06, 2003 11:13 am

Working on converting my old routines to the new variable formats. Could someone please proofread this and help me correct any mistakes?

Code: Select all

 removed, see below
Thanks
Last edited by Mckorr on Tue Oct 07, 2003 10:56 am, edited 1 time in total.
MQ2: Think of it as Evolution in action.

MacroFiend
a grimling bloodguard
a grimling bloodguard
Posts: 662
Joined: Mon Jul 28, 2003 2:47 am

Post by MacroFiend » Mon Oct 06, 2003 3:28 pm

One thing I've found that may or may not apply (since I'm not sure if that was the whole macro file) is that the /declares need to be inside a Sub.

Not sure if that is by design or not but when I tried to /declare with my #defines, the variables weren't initialized (even though they were global)

Mckorr
Developer
Developer
Posts: 2326
Joined: Fri Oct 18, 2002 1:16 pm
Location: Texas

Post by Mckorr » Tue Oct 07, 2003 9:58 am

I just noticed that. Also an overuse of global instead of local variables, which works... but is a bad programming habit. Will correct and repost. Thanks.
MQ2: Think of it as Evolution in action.

Mckorr
Developer
Developer
Posts: 2326
Joined: Fri Oct 18, 2002 1:16 pm
Location: Texas

Post by Mckorr » Tue Oct 07, 2003 11:00 am

Okay, after a quick rewrite:

Code: Select all

sub Attack

  /declare ObstacleCount global
  /declare targetarray array

  /varset targetarray(0) "$target(name,clean)"
  /varset targetarray(1) $target(level)
  /varset targetarray(2) $target(name)
  /varset targetarray(3) $target(id)
  /varset ObstacleCount 0

  /echo Fighting a level @targetarray(1) @targetarray(0)
  /face look
  /call MovetoMob

  :CloserAF
    /if "$target(id)"!=@targetarray(3) /goto :EndAF
    /if n $target(distance,nopredict)>10 /press up
    /if n $target(distance,nopredict)<10 /press down
    /if n $target(distance,nopredict)<15 /attack on
    /if n $target(distance,nopredict)>15 /attack off
    /if n $target(distance,nopredict)>15 /call MovetoMob
    /face fast nopredict look
    /if n $target(distance,nopredict)<11 /if n $char(ability,"Bash")>0 /doability "Bash"
    /if n $target(distance,nopredict)<11 /if n $char(ability,"Kick")>0 /doability "Kick"
    /goto :CloserAF

  :EndAF
    /echo The level @targetarray(1) @targetarray(0) is dead...
    /sendkey up up
    /sendkey up down
    /attack off
    /varset targetarray(3) 0
/return

sub MoveToMob

  /declare MyXLOC global
  /declare MyYLOC global
   
  /varset MyXLOC $char(x) 
  /varset MyYLOC $char(y) 

  /if n $target(distance,nopredict)<=15 { 
    /face look
    /return 
  } 
  /sendkey down up 

  :Movementloop 
    /varadd ObstacleCount 1 
    /if $target()=="FALSE" /return
    /face look
    /if n $target(distance,nopredict)<=10 { 
      /face look
      /sendkey up up 
      /return 
    } 
    /if @ObstacleCount>=3 { 
      /call CheckObstacle 
      /goto :Movementloop 
    } 
    /if n $target(distance,nopredict)>10 /goto :MovementLoop 
/return

sub CheckObstacle 
  /if n @MyXLOC==$char(x) /if n @MyYLOC==$char(y) /call HitObstacle 
  /varset MyXLOC $char(x) 
  /varset MyYLOC $char(y) 
  /varset ObstacleCount 0 
/return 

sub HitObstacle 
  /sendkey up up 
  /sendkey down down 
  /delay 3
  /sendkey up down 
  /sendkey down ctrl 
  /if n $rand(99)>50 { 
    /sendkey down right 
  } else { 
    /sendkey down left 
  } 
  /delay 5
  /sendkey up right 
  /sendkey up left 
  /sendkey up ctrl 
  /sendkey down up 
/return
I'm not sure if this line

Code: Select all

   /if "$target(id)"!=@targetarray(3) /goto :EndAF
should be

Code: Select all

   /if "$target(id)"!="@targetarray(3)" /goto :EndAF
or possibly

Code: Select all

   /if $target(id)!=@targetarray(3) /goto :EndAF
MQ2: Think of it as Evolution in action.

MacroFiend
a grimling bloodguard
a grimling bloodguard
Posts: 662
Joined: Mon Jul 28, 2003 2:47 am

Post by MacroFiend » Tue Oct 07, 2003 1:26 pm

If you are doing a numeric comparison like $target(id), you could do:

Code: Select all

    /if n $target(id)!=@targetarray(3) /goto :EndAF
*Edited for poor grammar