Jump to content

Re-entering a function


Recommended Posts

Alright so heres what I got

#include <misc.au3>

Global $x = false, $y = false, $count = 1, $diff = 1

While 1
HotKeySet("{F1}","one")
HotKeySet("{F2}","second")
Wend

Func second()
    If $y = true Then
        $y = false
                $x = true
        MsgBox(0,"","off")
        IniWrite("Counter.ini", "Count", "count"&$count, "end")
    Elseif $y = false Then
        $y=true
        $x = true
        IniWrite("Counter.ini", "Count", "count"&$count, "start")
        Sleep(100)
    EndIf
    While $y = true
    ;Do clicks, etc
        MsgBox(0, "", "Done")
        IniWrite("Counter.ini", "Different", "doner"&$diff, ""); - not important
        Sleep(1000)
        $x = false
        $diff=$diff+1
        one()
    WEnd
EndFunc



Func one()
    If $x = true Then
        $x = false
        MsgBox(0,"","off")
    Elseif $x = false Then
        $x=true
    EndIf
    While $x = true
        MsgBox(0,"", "On")
        Sleep(2000)
        IniWrite("Counter.ini", "Count", "count"&$count, "blah")
        $count = $count + 1
    WEnd
EndFunc

Thats just a quick (15 minutes ><) script I constructed to show my problem in a slimmed down view.

Now heres what my .ini is showing:

[Count]
count1=blah
count2=blah
count3=blah
count4=blah
count5=blah
[Different]
doner1=

1. It isn't writing down 'end' or 'start' when I press F2.

2. It's like it is bringing the value of $count over into Func second()... If $count is in the Global scope, it should bring whatever $count = $count + 1; it is at to a different Func?

3. When I press F2 the second time (to issue 'end') it still continues to loop the loop in Func one()...

3a. Does the loop from Func one() continue going even if another Func is called?

3b. When F2 is pressed the second time, $x=true, if this is in the Global scope, shouldn't $x = true now and Func one() should be stopped anyways... Now when I press F1 again $x will = true so the bot will be off altogether because If $x = true then MsgBox(off)

Maybe I've just never understood these noob concepts, I hope someone can shed some light on it :S.

Link to comment
Share on other sites

Just real quick, here's one thing.

This:

While 1
   HotKeySet("{F1}","one")
   HotKeySet("{F2}","second")
Wend

Should be this:

HotKeySet("{F1}","one")
HotKeySet("{F2}","second")
While 1
  Sleep(100)
Wend

Otherwise you're constantly resetting your hotkey.

Fix that first and see if anything gets better.

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...