Jump to content
Macro Express Forums

Divide by decimal ?

Recommended Posts



I wan't to detect some elements in a grid of a zone, so I use the pixel color detection, for that I use arrays to generate coordinates where to detect.


It works well but I do dynamics macros, then the coordinates are obtained by dividing the width and height of the concerned window.


It needs a high precision, because it's a grid so I multiply the first number to obtain all the other cordinates. But I saw that this function can't use decimals :


<VARIABLE MODIFY INTEGER Option="\x03" Destination="%cell_decalage[1]%" Value1="%map_x%" Value2="29"/>
"29.54" for exemple...
Oh wait, I think this is this function that can't use it :
<MOUSE MOVE Option="\x03" X="%cells_x_type1[%x_array%]%" Y="%cells_y_type1[%y_array%]%" _PROMPT="0x000A"/>
Because the mouse move on "29" if I put "29.54"

The two variables underlined are decimals numbers, like 29.54. I use this function above to debug, but in the end, I will use this variable ("29.54") in a :


<GET PIXEL COLOR Option="\x01" Rel_To_Screen="TRUE" X="%cells_x_type1[%x_array%]%" Y="%cells_x_type1[%x_array%]%" Destination="%color_type1[%x_array%]%"/>
Someone knows how to get this precision ?
Link to comment
Share on other sites

When you use your mouse, you always move to a fraction of pixels...


Recognizing the elements is already difficult with Macro Express, this becomes impossible if we can not divide by a fraction ...
Because of this, over the grid, cell by cell, my cursor leaves the center of the cells ...
Link to comment
Share on other sites


When you use your mouse, you always move to a fraction of pixels...


I don't believe that's true. As I understand it the mouse cursor is always positioned on the center of a pixel. I mean think about what you're saying for a moment. The icon that represents the mouse cursor is made up of pixels the pixel at the point can only move one pixel at a time. Not only is there no fraction but if there was there would be no point in it because you could not see it.


If you don't believe me check out literature like this in the MSDN. Mouse movement is a series of messages in Windows. 16 bits by 16 bits or a grid 65,536 square. Theoretically there could be a fraction of a pixel and maybe the mouse hardware sees something smaller, but once the mouse driver submits the data to the message stream it's a 16 bit message each a whole unit of a pixel.


Now in MEP you can use decimals in Variable Modify Integer. EG divide an integer by decimal, integer by integer that results in a fraction, and so forth. So you can still do what you want, you just need to mind the rounding rules. If they don't work the way you want use decimal math then round the way you want.

Link to comment
Share on other sites

Try something like this:


Variable Modify Decimal: %DecimalOut% = %Decimal1% / %Decimal2% // divide decimal variables
Variable Modify Decimal: Round %DecimalOut% to 0 decimal places // Round
Variable Modify Decimal %DecimalOut%: Truncate to Integer (%Integer1%) // Convert to an integer

You may or may not want to round the decimal value before converting it to an integer. If you do not care about rounding it you can leave out the "Variable Modify Decimal: Round" command.


When trying this out I discovered a bug. When variable names, that do not already exist, are entered into the "Value 1" and "Value 2" fields of the "Variable Modify Decimal: Multiply" command Macro Express Pro only offers to create them as Integer or Large Integer variable types. It should also offer to create them as Decimal variables.


To get around this you can either use the Variables tab to create the variables or you can use "Variable Set Decimal" commands to create the Decimal variables and give them a value. Something like this would work:


Variable Set Decimal %Decimal1% to 29.578
Variable Set Decimal %Decimal2% to 1.2

Variable Modify Decimal: %DecimalOut% = %Decimal1% / %Decimal2%
Variable Modify Decimal: Round %DecimalOut% to 0 decimal places
Variable Modify Decimal %DecimalOut%: Truncate to Integer (%Integer1%)


I will be reporting this bug to Insight Software.

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.

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.

  • Create New...