Jump to content
Macro Express Forums

Macro continueing bfore "Repeat Until" is satisfied!


Recommended Posts

It sounds like from the documentation that if I use a "Repeat Until" command that the macro should not continue executing past the "End Repeat" line UNTIL ALL conditions are meet for the "End Repeat" condition. However, this is not working for me. My macro is obviously continueing past the "End Repeat" line before the REPEAT function is satisfied. Any ideas/comments on this or am I just not understasnding? Please see attached file for my file and the tags below for the same.

 

Thank you for your help in advance!

 

<VARIABLE SET INTEGER Option="\x00" Destination="%N1%" Value="0"/>
<REPEAT UNTIL Variable="%N1%" Condition="\x00" Value="1"/>
<DELAY Flags="\x01" Time="2"/>
<COMMENT Value="'Page' icon"/>
<GET PIXEL COLOR Option="\x01" Rel_To_Screen="FALSE" X="30" Y="88" Destination="%N2%"/>
<COMMENT Value="'Links' icon"/>
<GET PIXEL COLOR Option="\x01" Rel_To_Screen="FALSE" X="48" Y="107" Destination="%N4%"/>
<COMMENT Value="'Macros' icon"/>
<GET PIXEL COLOR Option="\x01" Rel_To_Screen="FALSE" X="48" Y="394" Destination="%N5%"/>
<IF VARIABLE Variable="%N2%" Condition="\x00" Value="14061138" IgnoreCase="FALSE"/>
<AND/>
<IF VARIABLE Variable="%N4%" Condition="\x00" Value="16241482" IgnoreCase="FALSE"/>
<AND/>
<IF VARIABLE Variable="%N5%" Condition="\x00" Value="16250871" IgnoreCase="FALSE"/>
<VARIABLE SET INTEGER Option="\x00" Destination="%N1%" Value="1"/>
<END IF/>
<DELAY Flags="\x02" Time="500"/>
<END REPEAT/>
<MOUSE MOVE Option="\x01" X="60" Y="87" _PROMPT="0x000A"/>
<MOUSE LEFT CLICK/>

 

 

 

COLOR test.mex

Link to comment
Share on other sites

You might want to consider using named variables in MEP instead of the old ME3 variable arrays. I'd like to suggest that in the future you create a succinct example for review that produces the behavior you wish us to consider. Also you might consider putting your code in Code tags. Thanks for attaching an MEX.

Repeat Until %N1% Equals "1"
  Variable Set Integer %N1% to 1
End Repeat

Distilled I see this for the repeat exit logic. And in fact it iterates only once. This means your condition isn't being met. I suggest you put a breakpoint at line 26 (If N5 equals) and look at what the variable value actually is. I bet it's not 16250871. The other thing you can do is enable logging for the macro and see where it's going.

  • Like 1
Link to comment
Share on other sites

The value of all 3 variables (N2, N4 and N5) are correct and N1 is set to 1! I obtained those by running script in debug mode (pushing the "Run Test" button) and then 'Show Variable Values' in the debug sub-menu. So it looks like all the values are set correctly but the last 2 lines of my test code:

 

<MOUSE MOVE Option="\x01" X="60" Y="87" _PROMPT="0x000A"/>
<MOUSE LEFT CLICK/>

and the execute BEFORE the "End Repeat" line is activated! How can you tell it iterates only once?

 

I am relatively new to ME (wadding through this the best i can for now) and not sure what you mean by using named variables (I don't see anything in the help file or manual)? Also, how do you create a succinct example (I imagine your talking about creating a fully working example) and put code in tags? I can see how to put tags around a single line but is there an easy way to put tags around all of your lines?

 

Thanks again for your help!

Link to comment
Share on other sites

It is easier if you post the text version of your script so we don't have to copy and paste it into a macro to help. To copy the commands to the clipboard highlight your macro commands, right-click and choose "Copy Command Text". Your macro looks like this:

Variable Set Integer %N1% to 0
Repeat Until %N1% Equals "1"
  Delay: 2 seconds
  // 'Page' icon
  Get Pixel Color at (30, 88) Relative to Current Window into %N2%
  // 'Links' icon
  Get Pixel Color at (48, 107) Relative to Current Window into %N4%
  // 'Macros' icon
  Get Pixel Color at (48, 394) Relative to Current Window into %N5%
  If Variable %N2% Equals "14061138"
    AND
  If Variable %N4% Equals "16241482"
    AND
  If Variable %N5% Equals "16250871"
    Variable Set Integer %N1% to 1
  End If
  Delay: 500 milliseconds
End Repeat
Mouse Move: 60, 87 Relative to Screen
Mouse Left Click

So, if ...

 

The value of all 3 variables (N2, N4 and N5) are correct and N1 is set to 1!

Then the macro is working correctly. It says when it is discovered that N2, N4 and N5 are set to specific values then set N1 to 1. When N1 is set to 1 the repeat loop stops.

 

It appears to me that %N2% = "14061138", %N4% = "16241482" and %N5% Equals "16250871" so it sets N1 to 1 and the repeat loop should stop.

Link to comment
Share on other sites

not sure what you mean by using named variables (I don't see anything in the help file or manual)?

 

This would be clearer:

  Get Pixel Color at (30, 88) Relative to Current Window into %PageIconColor%
  Get Pixel Color at (48, 107) Relative to Current Window into %LinksIconColor%
  Get Pixel Color at (48, 394) Relative to Current Window into %MacrosIconColor%

Note the descriptive variable names instead of N2, N4 and N5.

 

From the help (emphasis mine):

Types of Variables

Macro Express supports several different types of variables. These are Text, Integer, Large Integer, Decimal, Control, Date/Time, Boolean and Handle variables. Variable names may be up to 31 characters in length.

Link to comment
Share on other sites

and the execute BEFORE the "End Repeat" line is activated! How can you tell it iterates only once?

I can tell it only repeats once because I created a succinct example! For the purpose of your question all but a couple of lines were superfluous. Also N1 was being set in a condition that I can not reproduce so if I assume you're getting this value then I can remove the condition and assume N1 is getting set. It's called logical deduction. In the end I had 3 lines and it only iterates once. So this proves that the problem is not with the repeat commands behavior and that It must be something else which is what I suggested not knowing how the rest of this works. So I was correct, it was something else.

 

I often find that when I try to create a simple example for the forum it works where the more complex embedded version does not. I then compare all the differences and my problem is always someplace in there and I never end up making the post on the forum:-)

 

And I'm not about to loose a macro with a bunch of text types on my machine without analyzing exactly what it all do, setting up an environment, and... Well I'm just not going to spend that time.

 

So what I was suggesting was that you create a simple and succinct macro, not a snippet of a bigger picture, and create an MEX file for it and post it.. You can even make it even easier for your audience by adding message pop-ups and such displaying variable values, comments, and so forth. Also annotate your code. The easier you make it for your audience the more likely someone will take the time to review it. I'm very busy for instance so at times I have to limit how much time I spend here each day.

Link to comment
Share on other sites

I am relatively new to ME (wadding through this the best i can for now) and not sure what you mean by using named variables (I don't see anything in the help file or manual)? Also, how do you create a succinct example (I imagine your talking about creating a fully working example) and put code in tags? I can see how to put tags around a single line but is there an easy way to put tags around all of your lines?

 

ME3 only had a couple of predefined array variables of only 99 elements. T1, T2, and so forth. Very limiting. Also it's not intuitive. I would routinely keep a list in Notepad on another screen so I would know that T6 was the Client Name. But with MEP you can create a string variable and name it %ClientName%. That's one hell of a lot easier to remember than %T[6]%. Also one can create normal variables or arrays. So now I can have an array named %ClientID% that has hundreds of thousands of client IDs. And if you make %ClientName% and a few other arrays of similar size you can effectively make a table. So now you can do things like search the client ID array for a value and return the associated client name. Mush more useful! Try it now. Go into the script editor > Variables tab > and create a new variable named %ClientName%. Or better yet when you're in the Variable Set String dialog type %ClientName% into the field and when you leave you will be prompted to create it.

 

You can add comments to individual lines but there is also a "Comment" command. Just type "Comment" into the search bar at the bottom of the command list. I even insert blank comments to make spaces to break up my code into logical chunks. Also you can color your lines of code as well as changing the text color. For awhile there I even had a scheme for this. For instance all my normal execution code was green but error handling stuff was red and so forth. It's actually a nice and uncommon feature.

 

BTW if you ever get suck and need solutions faster than you can learn please feel free to contact me as I'm available for hire. And often when a client hires me I don't just create a macro for them as much as I teach them how to do it themselves and manage their own code.

Link to comment
Share on other sites

Cory said

You might want to consider using named variables in MEP instead of the old ME3 variable arrays.

 

In fact your example is not using the old ME3 variable arrays, it is instead using named variables - but the names have absolutely no meaning!

If you were using the old ME3 variable names, then, as an example, line 1 of your code would read

 

Variable Set Integer %N[1]% to 0

Instead, you have created a new integer variable called %N1%.

Link to comment
Share on other sites

Then the macro is working correctly. It says when it is discovered that N2, N4 and N5 are set to specific values then set N1 to 1. When N1 is set to 1 the repeat loop stops.

 

It appears to me that %N2% = "14061138", %N4% = "16241482" and %N5% Equals "16250871" so it sets N1 to 1 and the repeat loop should stop.

 

@ImpactGary: I agree with Samrae. Also, you can avoid the potential confusion of that extra variable N1 by writing the macro like this:

Repeat Until %N[99]% Does not Equal "%N[99]%" // Repeats indefinitely unless stopped by other logic tests.
// 'Page' icon
  Get Pixel Color at (30, 88) Relative to Current Window into %nPixColPage%
  // 'Links' icon
  Get Pixel Color at (48, 107) Relative to Current Window into %nPixColLinks%
  // 'Macros' icon
  Get Pixel Color at (48, 394) Relative to Current Window into %nPixColMacros%
  If Variable %nPixColPage% Equals "14061138"
    AND
  If Variable %nPixColLinks% Equals "16241482"
    AND
  If Variable %nPixColMacros% Equals "16250871"
    Repeat Exit // The 3 pixel colour conditions have been met, so no further repetitions are necessary.
  End If
End Repeat
Mouse Move: 60, 87 Relative to Screen
Mouse Left Click

Notes:

 

1. I prefix integer variables with 'n', text with 't', etc.

 

2. Of course, if those colours are not found, my macro (or your original) will run until it is stopped manually.

 

@Cory:

 

"I suggest you put a breakpoint at line 26..."

 

What are you putting in your coffee these days? There are only 20 lines in his macro! :)

 

--

Terry, East Grinstead, UK

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...
 Share

×
×
  • Create New...