Jump to content
Macro Express Forums

Help with variables


Recommended Posts

Hey guys,

 

I'm using macro express pro demo and trying to build a macro that automates some clicks and keystrokes depending on pixel color, however, testing the script with notepad in the foreground it doesn't work as expected. 

Logic is check pixel color and place the value inside a variable, then use if statement to check the variable value vs the color. What am I doing wrong please?

Also, once I start the script with hotkey or from menu, is there a way to stop it using a hotkey aswell?

Once I get this the right way, I also need to implement some timer variable that every 30 min to jump to a loop steps collection and then resume the main sequence, and finally after 2h of running to jump to another loop that actually exits the program and stops the macro.

Please please help me. 

Dan

Link to comment
Share on other sites

Please export your macro to an MEX file so we can look at what you're doing.

 

In the future you might consider making one post per issue. 

 

Hotkeys are for activating a macro and not a normal functional thing in the macro. You should have error handling, or other checks in your code to handle termination in the cases it needs to. Please explain what you want to get out of and I might be able to offer a suggestion on how to do that when needed.
Having said that, look at the categories pane at the left of the Macro Explorer look at System Macros. You can see there are built in macros to do things like suspending execution, Resume/pause terminate MEP. 

You can also stop a macro by clicking the running man, I call him Forrest, in the System Notification area. 

Link to comment
Share on other sites

Hey Cory, 

 

Thanks for your answer, sorry for placing all my issues in same post, I am new to macro building and got close to 0 skill in coding/variables.

I've attached the mex file, please take a look. Simply put, I'm trying to automate hunting/healing and repairing inside a game. 

Start, select game window, check health, heal if wounded, start hunting otherwise, check health again and keep hunting if health is there (doing this with pixel color about 45% in the life bar, trying to place that pixel color inside variable and compare it to what color code should be when healthy, not sure I'm using the right colorcode number though).

Debugging the macro with notepad in the foreground it starts with 1 and keeps hitting 4 forever, even if I cycle notepad in fullscreen or 50% of screen to let the life bar be visible (simulating lifebar color change).

Game runs in fullscreen so I'm not able to click the running man :), I need a key combination to stop the macro.

Repairing should occur every 30min and loop a different set of keystrokes (I've not configured yet) and finally, after 2h of runtme, to execute some steps to exit game and stop script (I've not configured yet).

Is all this doable with Macro Express Pro?

 

auto-hunt-heal-repair.mex

Link to comment
Share on other sites

I'll look at this later when I have time. In the mean time you might check to see if yoru Get Pixel is relative to a window, absolute or what. 

 

Don't be sorry, it's cool if you want to do it, I only suggest it so you get better results. I've seen it often when there are multiple issues responders focus on one and the others get forgotten. 

 

BTW many have posted here trying to automate games and often the problem is that the programs have bot countermeasures that will thwart MEP. 

 

To terminate the macro I would make another macro that places a token in the registry or in a file when you run it. Then in your loop in the main macro, check to see if that token exists and abort if so. 

Link to comment
Share on other sites

Another way to stop a macro:
Options | Preferences | Playback | Miscellaneous tab allows you to set one of several hotkey combinations that stop running macros.  
I think using this option stops ALL running macros.  So if you have others that you want to keep running, then some method like Cory describes is your best bet. 

  • Thanks 1
Link to comment
Share on other sites

9 hours ago, Cory said:

I'll look at this later when I have time. In the mean time you might check to see if yoru Get Pixel is relative to a window, absolute or what. 

Selected absolute, I've typed in the coords.

 

9 hours ago, Cory said:

To terminate the macro I would make another macro that places a token in the registry or in a file when you run it. Then in your loop in the main macro, check to see if that token exists and abort if so. 

Could this be done in the same macro? At the very beginning place token in registry, then, inside if statements check time since that token was created, would this work?

 

6 hours ago, rberq said:

Another way to stop a macro:
Options | Preferences | Playback | Miscellaneous tab allows you to set one of several hotkey combinations that stop running macros.  

Thanks for the idea, stop all macros does exactly what I'm looking for.

 

I've got no xp with variables, specially with this macro recorder, what color code would be stored inside the variable? Am I checking for the wrong one?

image.png.3855cf7881c48f39dabad4937339d019.png

Link to comment
Share on other sites

The logic looks like it should work. You're making good headway with Macro Express!

 

I've always used the numeric value rather than the hex value when checking pixel colours, so I don't know that's the source of the problem. I would do it like this:

 

Get Pixel Color at (1577, 961) Relative to Screen into %Healthlevel%
If Variable %Healthlevel% Does not Equal "756951"

etc.

 

To debug your script, consider moving the mouse cursor to the pixel you're checking. This will help you confirm the pointer is exactly over the correct pixel:

 

Mouse Move: 1577, 961 Relative to Screen

Get Pixel Color from Beneath the Mouse into %Healthlevel%

If Variable %Healthlevel% Does not Equal "756951"

etc.

 

Once you get your macro working, you can revert back to your original method, if you want.

 

Cory is right: some applications prevent other applications, such as Macro Express, from interacting with them. If you discover that's your situation, the task you're wanting to automate will be much harder, and maybe impossible!

Link to comment
Share on other sites

7 hours ago, Wingman said:

Could this be done in the same macro? At the very beginning place token in registry, then, inside if statements check time since that token was created, would this work?

No. You need something to set the token. That's what I'm suggesting. It could be a completely invisible macro or other type of script. 

Link to comment
Share on other sites

1 hour ago, acantor said:

To debug your script, consider moving the mouse cursor to the pixel you're checking. This will help you confirm the pointer is exactly over the correct pixel:

 

Mouse Move: 1577, 961 Relative to Screen

Get Pixel Color from Beneath the Mouse into %Healthlevel%

If Variable %Healthlevel% Does not Equal "756951"

etc.

Thanks for the debug idea workaround, sparked a lightbulb in there :)

Managed to fix it by adding the selected line (Get pixel color and rewrite variable) and works ingame also.

Only have to figure out the timing now, to pause these steps @ 30min interval and run other set of commands (I'll configure below these lines) and finally, @ 2h10min marker run other steps I'll configure and stop macro.

 

image.png.8629fc8c2b2a7bb46a143bbbb18d15b2.png

Link to comment
Share on other sites

I was just starting to review your code when the alert popped up. Auspicious timing and saved me some time. I'm happy you got it working. 

 

Whenever I have something with very long delays and several (Meaning distinct and different) tasks, I make multiple macros that work in concert. So instead of having a macro that sits around 30 minutes and then does something, I would instead schedule it to run every 30 minutes. See the "Schedule" activation options. Also I will often have one master macro respond to and control the others. Sometimes passing information in the registry or using the controls of actual macro dialog boxes. Sometimes really handy to pass a result back from a control of a MessageBox, and one can use the "Wait for control" command. 

 

Aside: I often use the Windows Scheduler to start macros. If you ever find MEP's scheduled activations lacking, check in there. 

Link to comment
Share on other sites

14 hours ago, rberq said:

Options | Preferences | Playback | Miscellaneous tab allows you to set one of several hotkey combinations that stop running macros.

Yes! Good catch. I can't believe I forgot to mention that one. I had it in mind then... Well I must have forgotten. 

Link to comment
Share on other sites

15 minutes ago, Cory said:

Whenever I have something with very long delays and several (Meaning distinct and different) tasks, I make multiple macros that work in concert. So instead of having a macro that sits around 30 minutes and then does something, I would instead schedule it to run every 30 minutes. See the "Schedule" activation options. Also I will often have one master macro respond to and control the others. Sometimes passing information in the registry or using the controls of actual macro dialog boxes. Sometimes really handy to pass a result back from a control of a MessageBox, and one can use the "Wait for control" command. 

 

I'll try your suggestion later, bit busy @work now, I'll create a master macro that controls the other tasks (the hunt/heal, repair and exit game macros).

How should I tackle the token idea? 

Is there no time variable to work with?

Link to comment
Share on other sites

How you manage a token depends on what you are doing and how you want to manage them. I could only waste time wildly speculating. Give us some idea of the flow and control and maybe I could give you some ideas. I think the last one I did the master would check multiple registry values in a loop with a one second delay if it needed to react quickly, and as a scheduled macro if it was longer than a few minutes.  

 

I don't understand "Is there no time variable to work with?" There are time variables in MEP, but it sounds like you probably know that already.

 

I don't know if you know this or not but macros can be created that are used like subroutines or an object in a OOP language. Back when I was writing a lot of macros I'd have large categories (as called in Macro Explorer) of macros that would be passed a variable and then do general purpose task, say sorting an array. This way I could use those function/subroutine macros in many macros. If you get into this there's some things you should understand about the scope of the variable. You can ask us then for an explanation. I think I still have a web page on that topic someplace...

Link to comment
Share on other sites

Asking because I don't know how to start on this timer I wish to add to my macro. 

In essence, the flow would be the steps below, with no other input from me hopefully.

- start the macro, timer1 and timer2 should start also

- loop steps I've declared already (attached in picture earlier),

- when timer1 reaches 30min tick > goto loopX then restart hunting and reset timer1

- when timer2 reaches tick > goto loopY (exit game and end macro)

I was thinking perhaps declaring a time variable @ the beginning of the macro and checking in each if statements whether time variable reached the tick, don't know how to do this though.

Link to comment
Share on other sites

There is nothing like a timer object in other programming languages. Much as you say when doing things like this one should always have a delay in the loop, say 1 minute or even 1 second. Just something to keep the loop from hammering your processor by running as fast as it can resulting in thousands of iterations a second. In practice if I want to check somehting for a limit of 30 minutes I'd just have a 1 minute delay and do 30 iterations. However there is some time to do the process so the actual time will be longer. In most cases I find this is not important. In cases where it was important or the process could run a long time, I'll creates a time variable for now, add 30 minutes, then in my loop have an excessive number of iterations but check each time if we are past the time limit in the variable.

 

Link to comment
Share on other sites

Unless ME has improved in versions later than mine, working with times is clumsy.  The "Variable Set Integer" command allows to you load month/day/year/hour/minute/second into variables.  One technique I have used is to convert the present date and time into an approximate number of seconds elapsed since the year zero and time zero.  That's simply a matter of multiplying minutes by 60, hours by 3600, days by 86400, and so on, and adding all the products together.  Of course this does not accurately account for leap years and the meddling of Pope Gregory, but for the 30 minutes you care about it's close enough.  You could do it at the beginning of your macro, and again during each repeat of the processing loop, thereby keeping all the logic within your single macro.  Simply subtract the initial stored value from the recomputed value, and you know how many seconds have elapsed.  

 

Another command to look at is "Wait for time to elapse".  That you would have to do in a secondary macro, which would set the token you and Cory have been discussing.  

A simple method is:

1) Main macro deletes (token) file "c:\temp\timer.txt"

2) Main macro starts secondary macro ("Macro Run" command -- don't wait for completion!!!)

3) Secondary macro waits for 30 minutes to elapse, then creates file "c:\temp\timer.txt"

4) Main macro checks periodically for the existence of file "c:\temp\timer.txt".  If the file exists, time's up

 

I'm assuming that you don't need your time right down to the milli-second, because these techniques will have a little slop one way or the other.   

Link to comment
Share on other sites

Was toying around with Cory's idea of a main macro and time delay triggers, would have to read more about the repeat statements and macro disable/enable.

 image.png.22a305358d9b636aae9bcee2ce2b4590.png

 

 

1 hour ago, rberq said:

The "Variable Set Integer" command allows to you load month/day/year/hour/minute/second into variables.  One technique I have used is to convert the present date and time into an approximate number of seconds elapsed since the year zero and time zero.  That's simply a matter of multiplying minutes by 60, hours by 3600, days by 86400, and so on, and adding all the products together.  Of course this does not accurately account for leap years and the meddling of Pope Gregory, but for the 30 minutes you care about it's close enough.  You could do it at the beginning of your macro, and again during each repeat of the processing loop, thereby keeping all the logic within your single macro.  Simply subtract the initial stored value from the recomputed value, and you know how many seconds have elapsed.

 Thanks rberq, I'll try that method tomorrow, if I can keep all login in one macro that would be swell. Can you please share a screenshot of how your "Variable Set Integer" command would look like?

 

 

Link to comment
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...