AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How to check if a function returns a certain number?

 
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
lordliquid



Joined: 29 Jul 2009
Posts: 8

PostPosted: Wed Jul 29, 2009 4:32 pm    Post subject: How to check if a function returns a certain number? Reply with quote

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
View user's profile Send private message
sinkfaze



Joined: 18 Mar 2008
Posts: 5043
Location: the tunnel(?=light)

PostPosted: Wed Jul 29, 2009 4:36 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
SKAN



Joined: 26 Dec 2005
Posts: 8688

PostPosted: Wed Jul 29, 2009 4:41 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
lordliquid



Joined: 29 Jul 2009
Posts: 8

PostPosted: Wed Jul 29, 2009 5:01 pm    Post subject: Reply with quote

Wow, thanks guys! Both ways worked great! Was not expecting such a quick response. Thanks so much.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group