 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
anil_robo
Joined: 09 May 2008 Posts: 8
|
Posted: Sat May 31, 2008 1:13 am Post subject: Simple maths fails in a script |
|
|
I'm very new to scripting and can't do even simple functions. Here is a glaring example of this:
| Code: |
;Search for the image in the window area
Imagesearch, x1, y1, 10,300, 990, 650, *100 cw.bmp
if errorlevel
Msgbox, Image not found in the window.
else
{
x2 = %x1%+100
x2 = %y1%+200
;Once image is matched, we will later search for yellow color in a box drawn 100 pixels wide and 200 pixels high from the upper left corner of image location found earlier.
Msgbox, Image was found at %x1%, %y1%. Yellow color must be found at %x2%, %y2%.
}
|
What I want to do:
1. Search an area in the active window to match an image
2. Store the upper left location of the image searched as variables x1,y1
3. Make new variables where x2 is 100 more than x1, and y2 is 200 more than y1.
The script is able to detect the image, and gives a message box on the screen, which is able to display the values of x1 and y1 accurately. However, in place of x2 and y2, instead of seeing a calculated number, I still see a string-type variable (e.g. 123+100, 234+200).
I am totally dependent on the reference given in help as I have no existing knowledge of scripting. Why isn't the script showing the calculated number? Thanks! |
|
| Back to top |
|
 |
Guest1 Guest
|
Posted: Sat May 31, 2008 1:17 am Post subject: |
|
|
x2 = %x1%+100
x2 = %y1%+200
Adding to the same variable twice, "x2". |
|
| Back to top |
|
 |
anil_robo
Joined: 09 May 2008 Posts: 8
|
Posted: Sat May 31, 2008 1:22 am Post subject: |
|
|
Changed the variable names now, this doesn't seem to work either:
| Code: |
;Search for the image in the window area
Imagesearch, xa, ya, 10,300, 990, 650, *100 cw.bmp
if errorlevel
Msgbox, Image not found in the window.
else
{
xb = %xa%+100
xb = %ya%+200
;Once image is matched, we will later search for yellow color in a box drawn 100 pixels wide and 200 pixels high from the upper left corner of image location found earlier.
Msgbox, Image was found at %xa%, %ya%. Yellow color must be found at %xb%, %yb%.
}
|
|
|
| Back to top |
|
 |
PurloinedHeart
Joined: 04 Apr 2008 Posts: 159 Location: Canada
|
Posted: Sat May 31, 2008 1:24 am Post subject: |
|
|
| Code: |
;Search for the image in the window area
Imagesearch, xa, ya, 10,300, 990, 650, *100 cw.bmp
if errorlevel
Msgbox, Image not found in the window.
else
{
xb = %xa%+100
xb = %ya%+200
;Once image is matched, we will later search for yellow color in a box drawn 100 pixels wide and 200 pixels high from the upper left corner of image location found earlier.
Msgbox, Image was found at %xa%, %ya%. Yellow color must be found at %xb%, %yb%.
}
|
I don't get it  |
|
| Back to top |
|
 |
Guest1 Guest
|
Posted: Sat May 31, 2008 1:28 am Post subject: |
|
|
| Code: |
xb = %xa%+100
xb = %ya%+200
|
should be
| Code: |
xb = %xa%+100
yb = %ya%+200
|
Without it, that yb variable is useless since not specified before. |
|
| Back to top |
|
 |
anil_robo
Joined: 09 May 2008 Posts: 8
|
Posted: Sat May 31, 2008 1:31 am Post subject: |
|
|
| Code: |
;Search for the image in the window area
Imagesearch, xa, ya, 10,300, 990, 650, *100 cw.bmp
if errorlevel
Msgbox, Image not found in the window.
else
{
xb = %xa%+100
yb = %ya%+200
;Once image is matched, we will later search for yellow color in a box drawn 100 pixels wide and 200 pixels high from the upper left corner of image location found earlier.
Msgbox, Image was found at %xa%, %ya%. Yellow color must be found at %xb%, %yb%.
}
|
Sorry for the typo, I should have looked. Script now changed, msgbox says:
Image was found at 196, 402. Yellow color must be found at 196+100, 402+200. |
|
| Back to top |
|
 |
Guest1 Guest
|
Posted: Sat May 31, 2008 1:33 am Post subject: |
|
|
thats because your just specifying that xb and yb are the text that follows
try
| Code: |
xb := %xa%+100
xb := %ya%+200
|
Regular = doesn't handle expressions. Just sets variables to whatever you put after the = |
|
| Back to top |
|
 |
Guest1 Guest
|
Posted: Sat May 31, 2008 1:36 am Post subject: |
|
|
| sorry, don't put % signs in the expression |
|
| Back to top |
|
 |
Guest1 Guest
|
Posted: Sat May 31, 2008 1:37 am Post subject: |
|
|
sorry again lol
try like this
| Code: |
xb := xa+100
yb := ya+200
|
Im so sloppy today |
|
| Back to top |
|
 |
anil_robo
Joined: 09 May 2008 Posts: 8
|
Posted: Sat May 31, 2008 1:49 am Post subject: |
|
|
Yay! It works! I learned something new Thanks!
| Code: |
;Search for the image in the window area
Imagesearch, xa, ya, 10,300, 990, 650, *100 cw.bmp
if errorlevel
Msgbox, Image not found in the window.
else
{
xb := xa+100
yb := ya+200
;Once image is matched, we will later search for yellow color in a box drawn 100 pixels wide and 200 pixels high from the upper left corner of image location found earlier.
Msgbox, Image was found at %xa%, %ya%. Yellow color must be found at %xb%, %yb%.
|
|
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|