 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
lordliquid
Joined: 29 Jul 2009 Posts: 8
|
Posted: Wed Jul 29, 2009 4:32 pm Post subject: How to check if a function returns a certain number? |
|
|
Here\s what I got so far and this is not working..
| Code: | SendMode Input
SetWorkingDir %A_ScriptDir%
#NoEnv
#Persistent
Menu, Mainmenu, Add, Start!, Select1
^!r::Pause
^!h::Menu, MainMenu, Show
Select1:
Setup()
WinActivate, ahk_id %idFirst%
Loop
{
CheckLowStam()
If LowStam = 1
break
Sleep, 500
}
MsgBox Out of Loop
Setup()
{
Global
WinGet, darkfallid, List, Darkfall Online
WinActivate, ahk_id %darkfallid1%
MsgBox, 4,, Is this your First window? (press Yes or No)
IfMsgBox Yes
idFirst = %darkfallid1%
else
idFirst = %darkfallid2%
If idFirst = %darkfallid1%
{
idSecond = %darkfallid2%
} else {
idSecond = %darkfallid1%
}
WinActivate, ahk_id %idFirst%
WinActivate, ahk_id %idSecond%
}
CheckLowStam()
{
Sleep, 100
PixelSearch, Px, Py, 676, 58, 676, 58, 0x134C62, 1, Fast
Sleep, 100
if !ErrorLevel
{
return
}
else
{
MsgBox Low Stamina!
LowStam := 1
return
}
} |
This example I am trying to use a variable to get out of a loop. I have also tried the while loop.
Am I missing something or should I return a number and just check the return if it finds that pixel?
Thanks |
|
| Back to top |
|
 |
sinkfaze
Joined: 18 Mar 2008 Posts: 5043 Location: the tunnel(?=light)
|
Posted: Wed Jul 29, 2009 4:36 pm Post subject: |
|
|
You have to declare the variable in your function as global if you want to check it outside of the function itself:
| Code: | CheckLowStam()
{
global LowStam
Sleep, 100
PixelSearch, Px, Py, 676, 58, 676, 58, 0x134C62, 1, Fast
Sleep, 100
if !ErrorLevel
{
return
}
else
{
MsgBox Low Stamina!
LowStam := 1
return
}
} |
_________________ Try Quick Search for Autohotkey or see the tutorial for newbies. |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 8688
|
Posted: Wed Jul 29, 2009 4:41 pm Post subject: |
|
|
| Code: | ...
Setup()
WinActivate, ahk_id %idFirst%
While ! CheckLowStam()
Sleep, 500
MsgBox Out of Loop
...
CheckLowStam() {
PixelSearch, Px, Py, 676, 58, 676, 58, 0x134C62, 1, Fast
Return ! ErrorLevel
} |
|
|
| Back to top |
|
 |
lordliquid
Joined: 29 Jul 2009 Posts: 8
|
Posted: Wed Jul 29, 2009 5:01 pm Post subject: |
|
|
| Wow, thanks guys! Both ways worked great! Was not expecting such a quick response. Thanks so much. |
|
| 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
|