Jump to content

How to count


Recommended Posts

Hello,

How do I count how many times a function ran? For example: If the function exutes it changes for example the tooltip to

Function ran 1 time(s)

If it excutes a second time it changes the tooltip to

Function ran 2 time(s)

Link to comment
Share on other sites

  • Moderators

I've given a solution to this question before on here I believe somewhere:

;Put $CountFunctions[Number of Function] at the top of the function
Global $CountFunctions[3] = ['', 0, 0]

While 1
    Sleep(100)
    _FunctionOne()
    Sleep(100)
    If Mod($CountFunctions[1], 2) = 0 Then _FunctionTwo()
    ToolTip('Function 1 has ran ' & $CountFunctions[1] & ' Times' & @CR & _
        'Function 2 has ran ' & $CountFunctions[2] & ' Times', 0, 0)
WEnd

Func _FunctionOne()
    $CountFunctions[1] += 1
EndFunc

Func _FunctionTwo()
    $CountFunctions[2] += 1
EndFunc

Edit:

Don't concern yourself with the While/WEnd loop.

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

  • Moderators

Can you explain me how that works and what it does? (the code)

I've got a better idea.

You've been scripting in this forum for over 6 months now, why don't you "break" it down and tell me what you "think" it does, and I'll elaborate afterwards.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Here's the HotKey version of SmOke_N's example:

;~ Put $CountFunctions[Number of Function]at the top of the function
Global $CountFunctions[3] =['', 0, 0]

HotKeySet("1", "_FunctionOne")
HotKeySet("2", "_FunctionTwo")
HotKeySet("{ESC}", "_Terminate")

While 1
    Sleep(100)
WEnd

Func _FunctionOne()
    $CountFunctions[1] += 1
    ToolTip('Function 1 has ran ' & $CountFunctions[1] & ' Times' & @CR & _
            'Function 2 has ran ' & $CountFunctions[2] & ' Times', 0, 0)
EndFunc   ;==>_FunctionOne

Func _FunctionTwo()
    $CountFunctions[2] += 1
    ToolTip('Function 1 has ran ' & $CountFunctions[1] & ' Times' & @CR & _
            'Function 2 has ran ' & $CountFunctions[2] & ' Times', 0, 0)
EndFunc   ;==>_FunctionTwo

Func _Terminate()
    Exit
EndFunc   ;==>_Terminate

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

Is it possible to integrate this:

;Put $CountFunctions[Number of Function] at the top of the function
Global $CountFunctions[3] = ['', 0, 0]

While 1
    Sleep(100)
    _FunctionOne()
    Sleep(100)
    If Mod($CountFunctions[1], 2) = 0 Then _FunctionTwo()
    ToolTip('Function 1 has ran ' & $CountFunctions[1] & ' Times' & @CR & _
        'Function 2 has ran ' & $CountFunctions[2] & ' Times', 0, 0)
WEnd

Func _FunctionOne()
    $CountFunctions[1] += 1
EndFunc

Func _FunctionTwo()
    $CountFunctions[2] += 1
EndFunc

In This:

HotKeySet("{F1}", "begin")
HotKeySet("{F2}", "End")

While 1
Sleep(10)
Wend

func begin()
WinWaitActive("Habbo ~ Habbo Hotel - ")


Sleep(400)

While 1

$x = 437
$y = 326
$Color = 0x181818

While PixelGetColor($x, $y) = $Color
sleep(10)
Wend

MyFunction()

WEnd
EndFunc



Func MyFunction()
MouseClick("left", 430, 330, 1, 1)
MouseClick("left", 826, 615, 1, 1)

Func End()
    While 1
    Sleep(10)
    Wend
EndFunc

I tried this:

HotKeySet("{F1}", "begin")
HotKeySet("{F2}", "End")

While 1
Sleep(10)
Wend

func begin()
WinWaitActive("Habbo ~ Habbo Hotel - ")


Sleep(400)

While 1

$x = 437
$y = 326
$Color = 0x181818

While PixelGetColor($x, $y) = $Color
sleep(10)
Wend

MyFunction()

WEnd
EndFunc



Func MyFunction()
Global $CountFunctions[3] = ['', 0, 0]

While 1
    Sleep(100)
    
    Sleep(100)
    ToolTip('Function 1 has ran ' & $CountFunctions[1] & '  Times')
WEnd

MouseClick("left", 430, 330, 1, 1)
MouseClick("left", 826, 615, 1, 1)
_FunctionOne()

EndFunc

Func End()
    While 1
    Sleep(10)
    Wend
EndFunc 

Func _FunctionOne()
    $CountFunctions[1] += 1
EndFunc

But that didn't work. I want it to count when MyFunction has ended.

Thanks

Link to comment
Share on other sites

  • Moderators

Blah....!

1. Global Variable (do you see that?)

2. Put the same variable (not in global state) in the function you want to track

3. Make sure it is in this type of condition variable += 1 or variable = variable + 1

That's it... Have you tried the AutoIt 123 yet? You don't seem to have an understanding of functions or scripts still at this point (6 1/2 months), the post I gave was an example only, because once again, you didn't post the script you wanted help with.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

But I did now. I can't get to work. I think I build the code the wrong way:

HotKeySet("{F1}", "begin")
HotKeySet("{F2}", "End")

While 1
Sleep(10)
Wend

func begin()
WinWaitActive("Habbo ~ Habbo Hotel - ")


Sleep(400)

While 1

$x = 437
$y = 326
$Color = 0x181818

While PixelGetColor($x, $y) = $Color
sleep(10)
Wend

MyFunction()

WEnd
EndFunc



Func MyFunction()
Global $CountFunctions[1] += 1

While 1
    Sleep(100)
    
    Sleep(100)
    ToolTip('Er zijn ' & $CountFunctions[1] & ' mensen bij de deur gekicked')
WEnd

MouseClick("left", 430, 330, 1, 1)
MouseClick("left", 826, 615, 1, 1)
_FunctionOne()

EndFunc

Func End()
    While 1
    Sleep(10)
    Wend
EndFunc 

Func _FunctionOne()
    $CountFunctions[1] += 1
EndFunc

This are the errors I get:

C:\Documents and Settings\Administrator\Bureaublad\habbo kicker.au3(32,27) : ERROR: syntax error
Global $CountFunctions[1] +=
~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\Documents and Settings\Administrator\Bureaublad\habbo kicker.au3(2,24) : ERROR: End(): undefined function.
HotKeySet("{F2}", "End")
~~~~~~~~~~~~~~~~~~~~~~~^
C:\Documents and Settings\Administrator\Bureaublad\habbo kicker.au3 - 2 error(s), 0 warning(s)

I don't understand why there's an error in the end function, because before I added the count it worked.

Link to comment
Share on other sites

  • Moderators

1. You need beta for += / -= / /= / *= / &=

2. You still have not listened to what I wrote, where do you put Global Variables? Inside a Function? What type of variable do you use inside a function generally speaking?

Edit:

I hope no one just gives you the answer, it's a good idea you actually work for it. Look at what I did for "My" script, then ask yourself how you would adapt that in your script. (Hint: My While/WEnd loop doesn't matter, and only how I used the variable in my Functions matter).

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

  • Moderators

+= = beta. :D

[edit]

SmOke_N why are you always before me. go away :D

Also why do you use [3] instead of [2] ?

[/edit]

Because I never use [0], only [1] and [2]... just a habbit, I try to keep myself like most of the functions and save [0] for the ubound.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Why don't you just help me guys? I'm here to get help, so I can Lean the things I don't know. Please help!

Once again the codes:

HotKeySet("{F1}", "begin")
HotKeySet("{F2}", "End")

While 1
Sleep(10)
Wend

func begin()
WinWaitActive("Habbo ~ Habbo Hotel - ")


Sleep(400)

While 1

$x = 434
$y = 325
$Color = 0x181818

While PixelGetColor($x, $y) = $Color
sleep(10)
Wend

MyFunction()

WEnd
EndFunc



Func MyFunction()
MouseClick("left", 430, 322, 1, 1)
MouseClick("left", 826, 615, 1, 1)
Sleep(700)
EndFunc

Func End()
    While 1
    Sleep(10)
    Wend
EndFunc    oÝ÷ Ù«­¢+ØíAÕÐÀÌØí
½Õ¹Ñչѥ½¹Ím9յȽչѥ½¹tÐѡѽÀ½Ñ¡Õ¹Ñ¥½¸)±½°ÀÌØí
½Õ¹Ñչѥ½¹ÍlÍtôlÌäìÌäì°À°Át()]¡¥±Ä(M±À ÄÀÀ¤(}չѥ½¹=¹ ¤(M±À ÄÀÀ¤(%5½ ÀÌØí
½Õ¹Ñչѥ½¹ÍlÅt°È¤ôÀQ¡¸}չѥ½¹Qݼ ¤(Q½½±Q¥À Ìäíչѥ½¸Ä¡ÌɸÌäìµÀìÀÌØí
½Õ¹Ñչѥ½¹ÍlÅtµÀìÌäìQ¥µÌÌäìµÀì
HµÀì|(Ìäíչѥ½¸È¡ÌɸÌäìµÀìÀÌØí
½Õ¹Ñչѥ½¹ÍlÉtµÀìÌäìQ¥µÌÌäì°À°À¤)]¹()Õ¹}չѥ½¹=¹ ¤(ÀÌØí
½Õ¹Ñչѥ½¹ÍlÅt¬ôÄ)¹Õ¹()Õ¹}չѥ½¹Qݼ ¤(ÀÌØí
½Õ¹Ñչѥ½¹ÍlÉt¬ôÄ)¹Õ¹
Edited by PcExpert
Link to comment
Share on other sites

  • Moderators

Why don't you just help me guys? I'm here to get help, so I can Lean the things I don't know. Please help!

What do you call what I did? It isn't a Function I wrote, it was the way to count in "my" functions I wrote, There were 3 things you had to do: 1. Have a Global Variable for each function / 2. Put that global variable with a count += 1 at the Top of the function (right after Func _blah()) / 3. Figure out where you want to check that Global variable in your script (you know, because that global variable has your count). I'm NOT going to put it in "YOUR" script for you, if you can't figure that out after 6 months, then IMHO you have no business writing any applications that would be used on any other computers other than your own.

If this sounds harsh... It's meant to really, It makes me sick that people try so hard to learn something no matter the time it takes, and actually put an effort into it, and retain what they've learned. Then, if you look at any post you have ever started, someone has written your script for you basically from the beginning to end.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

  • Moderators

Thanks all! It works now! I think I didn't really read your answeres right. Thanks again!

Helps to re-read them sometimes :D ... Glad "you" got it working (instills a bit more faith in ya :D )

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

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