Jump to content
Macro Express Forums
adamrl018

Macro Run if Pixel color changes

Recommended Posts

Hey guys,

 

Im having some trouble setting up a macro for the game i play.

Basically im tring to get a "Shadow Creeper" to run continually until a pixel changes "Health Bar"

And when that pixel changes then run "Heal".

 

I got both of the macros running good but i cant seem to get the "shadow creeper" to run "heal" if the pixel changes.

Anyway.. here's what i got.

 

Thanks in advance for you help :D

 

Script 1 "Shadow Creeper"

Get Pixel: Screen Coords: 324,197 into %N1%

Repeat Until %N1% <> %N1%

Get Pixel: Screen Coords: 324,197 into %N1%

If Variable %N1% <> variable %N2%

Break

End If

Repeat End

Delay 10 Milliseconds

Macro Playback Speed: Normal Speed

Mouse Move Screen 835, 426

Mouse Left Button Down

Mouse Left Button Up

Delay 2 Seconds

Mouse Move Screen 658, 742

Mouse Left Button Down

Mouse Left Button Up

Delay 2 Seconds

Mouse Move Screen 824, 745

Mouse Left Button Down

Mouse Left Button Up

Mouse Move Screen 775, 746

Mouse Left Button Down

Mouse Left Button Up

Delay 10 Seconds

Mouse Move Screen 775, 746

Mouse Left Button Down

Mouse Left Button Up

Delay 10 Seconds

Mouse Move Screen 775, 746

Mouse Left Button Down

Mouse Left Button Up

Delay 10 Seconds

Mouse Move Screen 775, 746

Mouse Left Button Down

Mouse Left Button Up

Delay 10 Seconds

Mouse Move Screen 1087, 749

Mouse Left Button Down

Mouse Left Button Up

Delay 15 Seconds

Macro Run: Heal

 

Script 2 "Heal"

Macro Playback Speed: Normal Speed

Delay 60 Milliseconds

Mouse Move Screen 857, 688

Mouse Left Button Down

Mouse Left Button Up

Delay 5 Seconds

Mouse Move Screen 917, 259

Mouse Left Button Down

Mouse Left Button Up

Delay 5 Seconds

Mouse Move Screen 1080, 751

Mouse Left Button Down

Mouse Left Button Up

Delay 25 Seconds

Macro Run: Shadow Creeper

Share this post


Link to post
Share on other sites

Why the 2nd macro isn't running:

 

My first guess is that you're trying to run a macro that doesn't exist.

 

The name of the macro you said you're trying to run is Run away and heal

 

Your posted code is: Macro Run: Heal

 

You'll need to change the Macro Run command to Macro Run: Run away and heal

 

Maybe I've misunderstood something, or maybe you have them named correctly in your actual macros, but what you've given us in this thread makes it look like this is the problem.

__________________

 

Once you get the second script to run, you may want to move the 5 second delays up one line each. That way you'll have:

 

Mouse button down

Delay 5 seconds

Mouse button up

 

This is, of course, assuming that the "mouse button down" command is what is causing you to run away. I don't know the game you're trying to automate, or its dynamics, so it is possible that clicking in one spot will cause your character to run to that spot, in which case your code is fine (though a "Mouse Left Click" command would be simpler in that case).

 

But if the dynamic is that your character will only run as long as the button is held down (a very good reason to use the Mouse button down / Mouse button up combination), then you'll want to make the change shown above.

Share this post


Link to post
Share on other sites

Get Pixel: Screen Coords: 324,197 into %N1%

Repeat Until %N1% <> %N1%

Get Pixel: Screen Coords: 324,197 into %N1%

If Variable %N1% <> variable %N2%

Break

End If

Repeat End

 

As Paul pointed out, variable N2 is not being set anywhere.

I think you want your second Get Pixel command to get into N2, not N1.

Share this post


Link to post
Share on other sites

Ok i think i fixed it... Does the "End if, End Repeat" need to be at the end of the actions?

 

Or do i even have this right? when i start it it does nothing..

 

Macro Playback Speed: Normal Speed

Get Pixel: Screen Coords: 324,197 into %N1%

Repeat Until %N1% <> %N1%

Get Pixel: Screen Coords: 324,197 into %N1%

If Variable %N1% <> variable %N1%

Break

Mouse Move Screen 835, 426

Mouse Left Button Down

Mouse Left Button Up

Delay 2 Seconds

Mouse Move Screen 658, 742

Mouse Left Button Down

Mouse Left Button Up

Delay 2 Seconds

Mouse Move Screen 824, 745

Mouse Left Button Down

Mouse Left Button Up

Mouse Move Screen 658, 742

Mouse Left Button Down

Mouse Left Button Up

Mouse Move Screen 775, 746

Mouse Left Button Down

Mouse Left Button Up

Delay 10 Seconds

Mouse Move Screen 775, 746

Mouse Left Button Down

Mouse Left Button Up

Delay 10 Seconds

Mouse Move Screen 658, 742

Mouse Left Button Down

Mouse Left Button Up

Mouse Move Screen 775, 746

Mouse Left Button Down

Mouse Left Button Up

Delay 10 Seconds

Mouse Move Screen 658, 742

Mouse Left Button Down

Mouse Left Button Up

Mouse Move Screen 775, 746

Mouse Left Button Down

Mouse Left Button Up

Delay 10 Seconds

Mouse Move Screen 1087, 749

Mouse Left Button Down

Mouse Left Button Up

Delay 15 Seconds

End If

Repeat End

Macro Run: Heal

Share this post


Link to post
Share on other sites
1 Macro Playback Speed: Normal Speed

2 Get Pixel: Screen Coords: 324,197 into %N1%

3 Repeat Until %N1% <> %N1%

4 Get Pixel: Screen Coords: 324,197 into %N1%

5 If Variable %N1% <> variable %N1%

6 Break

 

1) Every If needs an End If command as soon as you have completed processing the If statements

2) Same with Repeat

3) Line 4 should place its results into N2

4) Line 5 will never ever be true

5) Line 5 should compare N1 with N2

6) Line 5 needs an End If, probably after line 6

7) Your Repeat End should probably be after the End If which you inserted after Line 6

 

I think you have quite a lot of studying of programming, logic and Macro Express to do.

 

I personally would rewrite the above lines as follows:

1 Get Pixel: Screen Coords: 324,197 into %N1%
2 Copy N1 to N2
3 Repeat Until %N1% <> %N2%
4 Get Pixel: Screen Coords: 324,197 into %N2%
5 Repeat End

The danger with this code is that if, for some reason, the pixel colour never changes, your Repeat loop will never end. I would therefore insert a counter, which, when exceeded, causes the macro to return.

Share this post


Link to post
Share on other sites

Ok i changed the script like you said. but when i start it it still will not move.

And remember im tring to get the macro to run another macro if that pixel changes

 

Macro Playback Speed: Normal Speed

Get Pixel: Screen Coords: 324,170 into %N1%

Variable Modify Integer: Copy %N1% to %N2%

Repeat Until %N1% <> %N1%

Get Pixel: Screen Coords: 324,170 into %N2%

Repeat End

Mouse Move Screen 637, 516

Mouse Left Button Down

Mouse Left Button Up

Delay 2 Seconds

Mouse Move Screen 658, 742

Mouse Left Button Down

Mouse Left Button Up

Delay 2 Seconds

Mouse Move Screen 824, 745

Mouse Left Button Down

Mouse Left Button Up

Mouse Move Screen 658, 742

Mouse Left Button Down

Mouse Left Button Up

Mouse Move Screen 775, 746

Mouse Left Button Down

Mouse Left Button Up

Delay 10 Seconds

Mouse Move Screen 775, 746

Mouse Left Button Down

Mouse Left Button Up

Delay 10 Seconds

Mouse Move Screen 658, 742

Mouse Left Button Down

Mouse Left Button Up

Mouse Move Screen 775, 746

Mouse Left Button Down

Mouse Left Button Up

Delay 10 Seconds

Mouse Move Screen 658, 742

Mouse Left Button Down

Mouse Left Button Up

Mouse Move Screen 775, 746

Mouse Left Button Down

Mouse Left Button Up

Delay 10 Seconds

Mouse Move Screen 1087, 749

Mouse Left Button Down

Mouse Left Button Up

Delay 15 Seconds

Macro Run: Heal

Share this post


Link to post
Share on other sites

ok i kinda experimented with the first one i had and fixed the things you said. I got the macro to run but then N1 <> N2 it does not run "Heal"

 

Im tring to get it to run "Heal" right when that variable changes

 

 

Macro Playback Speed: Normal Speed

Get Pixel: Screen Coords: 324,170 into %N1%

Get Pixel: Screen Coords: 324,170 into %N2%

Repeat Until %N1% <> %N2%

If Variable %N1% <> variable %N2%

Macro Run: Heal

End If

Mouse Move Screen 637, 516

Mouse Left Button Down

Mouse Left Button Up

Delay 2 Seconds

Mouse Move Screen 658, 742

Mouse Left Button Down

Mouse Left Button Up

Delay 2 Seconds

Mouse Move Screen 824, 745

Mouse Left Button Down

Mouse Left Button Up

Mouse Move Screen 658, 742

Mouse Left Button Down

Mouse Left Button Up

Mouse Move Screen 775, 746

Mouse Left Button Down

Mouse Left Button Up

Delay 9 Seconds

Mouse Move Screen 775, 746

Mouse Left Button Down

Mouse Left Button Up

Delay 10 Seconds

Mouse Move Screen 658, 742

Mouse Left Button Down

Mouse Left Button Up

Mouse Move Screen 775, 746

Mouse Left Button Down

Mouse Left Button Up

Delay 10 Seconds

Mouse Move Screen 658, 742

Mouse Left Button Down

Mouse Left Button Up

Mouse Move Screen 775, 746

Mouse Left Button Down

Mouse Left Button Up

Delay 10 Seconds

Mouse Move Screen 1087, 749

Mouse Left Button Down

Mouse Left Button Up

Delay 15 Seconds

Repeat End

Share this post


Link to post
Share on other sites

The problem is that you are using a conditional statement at the front of the loop and then a bunch of commands. Think like the program here, you need to nest things correctly. There is a logical order to it all and whatever you want to repeat needs to be nested, from what I can tell you want something to fire when n1 and n2 are no longer the same color, and have it run this check constantly.

 

Repeat until is a nested statement just like If/End If, a simple repeat loop is like this:

 

Repeat _UNTIL_ n1 > n2

Variable set integer n2 = 10

Variable modify integer n1 = n1 + 1

Repeat _END_

Text type: repeat ended

 

Now, this loop will just continue to run forever until it satisfies the initial repeat requirement, i.e. N1 is 11 and it will return to the next part of the macro, the text type command, so, if you want something to repeat UNTIL something changes, and then stop, and then do something, but keep doing all of that forever, you will have to nest repeats... your sequential ordering needs to be more like this:

 

>REPEAT UNTIL N99 <> N99 (repeat everything nested in here FOREVER as N99 won't ever not equal itself, or add your own other condition to stop it)

>>Repeat Until %N1% <> %N2%

>>>Get Pixel: Screen Coords: 324,170 into %N1%

>>>Get Pixel: Screen Coords: 324,170 into %N2%

>>Repeat End

>MACRO RUN: HEAL

>REPEAT END

 

And so we have two nested repeat statements, one that runs the inner repeat forever, and the inner one which runs our other macro.

 

I have never tried to run macros from other macros before, but failing that it doesn't work right in nested repeats, you can just put your other code in instead of macro run: heal...

 

Hope this helps

 

Rand

 

Edit: something topologically more like this is probably faster (twice, in fact) but I'm not sure how necessary that is....

 

>REPEAT UNTIL N99 <> N99 (repeat everything nested in here FOREVER as N99 won't ever not equal itself, or add your own other condition to stop it)

>Get Pixel: Screen Coords: 324,170 into %N2%

>>Repeat Until %N1% <> %N2%

>>>Get Pixel: Screen Coords: 324,170 into %N1%

>>Repeat End

>MACRO RUN: HEAL

>REPEAT END

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...