Jump to content

Variable transferring over to another Function?


Recommended Posts

Maybe I just never caught this part of learning AutoIt, but when I say have

Func ads()
$i = 1
bsd()
EndFunc

Func bsd()
If $i = 1 Then
;--
endIf
EndFunc

It don't work for me. I'm trying to create something that knows when the pot key has been pressed 3 times, once it has, then it goes to a different Func.... heres my script, do you guys see anything wrong? :S

Opt("GUIOnEventMode", 1)
Opt("MouseCoordMode", 0)
Opt("PixelCoordMode", 0)
#include <GUIConstants.au3>

HotKeySet("{ESC}", "Terminate")
HotKeySet("^p", "_ToggleRun")
HotKeySet("^o", "stop")

Global $Running = 0, $MPos, $PixelColor, $i = 1



While 1
    If $Running Then
     Pot()
     Box()
    EndIf
WEnd



Func Box()
    If $i = 4 Then
        Send("{F3}")
        $i = 1
    EndIf
    
EndFunc
        
        


Func Pot()
    If $PixelColor <> PixelGetColor($MPos[0], $MPos[1]) Then
        Send("{F2}")
        Sleep(1000)
        $i = $i + 1
    EndIf
EndFunc

Func _ToggleRun()
    $Running = NOT $Running
    If $Running Then
        $MPos = MouseGetPos()
        $PixelColor = PixelGetColor($MPos[0], $MPos[1])
    EndIf
EndFunc

Func stop()
    $Running = NOT $Running
    MsgBox(0, "", "Press Ctrl+p AGAIN to record your new pixel spot!")
EndFunc



Func Terminate()
    Exit
EndFunc

P.S. this code: If $PixelColor <> PixelGetColor($MPos[0], $MPos[1]) Then Just means if the spot recorded color changes, Then: blah blah...

Link to comment
Share on other sites

Set $i as global variable.

It is at the top... $i = 1... And from what I think, that means the variable can be changed throughout the script... So $i = 1 would turn into $i = 2, etc etc, until it reaches $i = 4 and then Box() would activate... But it's not -.-

Ps/Edit - In this line:

If $PixelColor <> PixelGetColor($MPos[0], $MPos[1]) Then

I used to use just

If $PixelColor <> $PixelColor Then

But that didn't work, until my friend told me to switch the 2nd PixelColor with what PixelColor actually is... What I don't get, why doesn't $PixelColor <> $PixelColor work the same as $PixelColor <> PixelGetColor($MPos[0], $MPos[1])... Because in here:

Func _ToggleRun()
    $Running = NOT $Running
    If $Running Then
        $MPos = MouseGetPos()
        $PixelColor = PixelGetColor($MPos[0], $MPos[1])
    EndIf
EndFunc

PixelColor IS PixelGetColor($MPos[0], $MPos[1])... So what is the difference between using PixelGetColor($MPos[0], $MPos[1]) and just PixelColor... And why don't PixelColor <> PixelColor work? ><

Edited by UnknownWarrior
Link to comment
Share on other sites

Opt('MustDeclareVars', 1)

Dim $i = 0

_First()
MsgBox(0x40, 'Title', '$i = ' & $i)

Func _First()
    $i += 1
    _Third()
EndFunc

Func _Second()
    $i *= 2
EndFunc

Func _Third()
    $i += 5
    _Second()
EndFunc

MsgBox indeed confirm the result was calculated properly and the result is 12 as you can see so it's probably your HotKey UDF get called more than once even if you press CTRL+p once, also I believe that ^p and ^P are different. Try to use #AutoIt3Wrapper_Run_Debug_Mode=Y and ConsoleWrite with your format to see what is going on.

Link to comment
Share on other sites

Opt('MustDeclareVars', 1)

Dim $i = 0

_First()
MsgBox(0x40, 'Title', '$i = ' & $i)

Func _First()
    $i += 1
    _Third()
EndFunc

Func _Second()
    $i *= 2
EndFunc

Func _Third()
    $i += 5
    _Second()
EndFunc

MsgBox indeed confirm the result was calculated properly and the result is 12 as you can see so it's probably your HotKey UDF get called more than once even if you press CTRL+p once, also I believe that ^p and ^P are different. Try to use #AutoIt3Wrapper_Run_Debug_Mode=Y and ConsoleWrite with your format to see what is going on.

So exactly, why is it not working in MY script... Any idea? :S

Link to comment
Share on other sites

Yeah You COULD use $i as a parameter, But COULD you use it as

Global Const $i
im pretty sure you CAN

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...