Sign in to follow this  
Followers 0
stackover

keep function in loop when start other function

31 posts in this topic

#1 ·  Posted (edited)

I Have the simple code:

HotkeySet ("{F5}", "ClickMouseDireito")
HotkeySet ("{F7}", "AutoCleanMode1")

Func ClickMouseDireito()
    
    While (1)
    MouseDown ("Right")
    Call ("Desfoque")
    Send (" ")
    MouseUp ("Right")
    Send (" ")
    Sleep(60)
    WEnd

EndFunc

Func AutoCleanMode1()

    $ContAutoClean = TimerInit()
    Do
        If TimerDiff($ContAutoClean) > $Time4Clean Then
            Call("AbrirInventorio")
            Send ("{SHIFTDOWN}")
            $pos = MouseGetPos()
            MouseMove($CoordCleanX1, $CoordCleanY1, 1)
            Call("Get")
            MouseMove($DX, $DY, 1)
            Call("Drop")
            MouseMove ($pos[0], $pos[1], 1)
            Call("AbrirInventorio")
            Send ("{SHIFTUP}")
            Sleep (100)
            $ContAutoClean2 = TimerInit()
            Do
                If TimerDiff($ContAutoClean2) > $Time4Clean Then
                Call("AbrirInventorio")
                Send ("{SHIFTDOWN}")
                $pos = MouseGetPos()
                MouseMove($CoordCleanX1, $CoordCleanY3, 1)
                Call("Get")
                MouseMove($DX, $DY, 1)
                Call("Drop")
                MouseMove ($pos[0], $pos[1], 1)
                Call("AbrirInventorio")
                Send ("{SHIFTUP}")
                Sleep (100)
                EndIf
            Until TimerDiff($ContAutoClean2) > $Time4Clean
        $ContAutoClean = TimerInit()
        EndIf
    Until TimerDiff($ContAutoClean) > $Time4Clean+$Time4Clean*10

EndFunc

While (1)
Sleep (1)
WEnd

When I start ClickMouseDireito() is ok but when I start AutoCleanMode1() function the ClickMouseDireito () function stop. How to keep first working?

Edited by stackover

Share this post


Link to post
Share on other sites



Hi,

you scripted the way you described. Run func one or func two, but never run both together!

So long,

Mega


Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites

Excuse but I have scripts that run more than 1 functions.. So its possible..

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

as stated by th.meger, you would need to completely rework your code if you want to do both. What I would suggest is to take both of your functions, and put each one inside a conditional statement that executes inside a single loop. Then use the hotkeys to set a global variable, allowing you to execute the parts of the code you want. An example follows (without the bulk of your code... you'll need to work it in)

Global $CMD=0, $ACM=0
HotkeySet ("{F5}", "ClickMouseDireito")
HotkeySet ("{F7}", "AutoCleanMode1")

while 1
if $CMD=1 then 
;your code here
endif
if $ACM=1 then
;your code here
endif
sleep(50)
wend

Func ClickMouseDireito()
$CMD-=1
$CMD*=-1
EndFunc

Func AutoCleanMode1()
$ACM-=1
$ACM*=-1
EndFunc

Edit: Some of the code escaped the AutoIT tags!

Edited by improbability_paradox

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

hmm I understand and think that ill be fine .. but I already saw more than one func running ... or maybe I m crazy ^^ anyway ... is there others ways ? :)

Edited by stackover

Share this post


Link to post
Share on other sites

AutoIT code executes one line at a time. I may be overlooking something, but to the best of my knowledge that is a fairly universal characteristic of this scripting language. In other words, it is not a Multi Threaded programming language. You may have seen certain examples that appear to be exceptions, but when you analyze them more thoroughly you will see that this is not the case. Take, for example, an Adlib function. The way an Adlib function works is that the function is called on a specific interval, regardless of what else is happening in the script (there are a few things that can prevent this from happening. I think that reading an STDOUT stream, for example, can stop it if there is nothing to be read from the stream. But these are exceptions, not the rule). So, using an adlib function it may SEEM as though there are two functions running simultaneously, but in actuality the first function is "paused" while the Adlib function does its job, and then "Resumed" once its done.

Another way to simulate a Multi Threaded language is to run two scripts at once, and have them communicate to each other.

There may be other methods, but these are the only ones that come to mind.

Share this post


Link to post
Share on other sites

Hi,

you cannot do things parallel! There is no multithreading in Autoit.

So long,

Mega


Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Strange .. I try to test with paradox sugestion.. I just do a simple example like ...

Global $CMD=0, $ACM=0
HotkeySet ("{F5}", "ClickMouseDireito")
HotkeySet ("{F7}", "AutoCleanMode1")

while 1
if $CMD=1 then
 While 1
   MouseClick("Left")
 WEnd
endif

if $ACM=1 then
 While 1
   MoveMouse(200, 200, 1)
    Sleep (3000)
   MoveMouse(400, 400, 1)
 WEnd
endif

sleep(50)
wend

Func ClickMouseDireito()
$CMD-=1
$CMD*=-1
EndFunc

Func AutoCleanMode1()
$ACM-=1
$ACM*=-1
EndFunc

Dont do 2 if in same time .. or do one or do another ..

Edited by stackover

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Strange .. I try to test with paradox sugestion.. I just do a simple example like ...

Global $CMD=0, $ACM=0
HotkeySet ("{F5}", "ClickMouseDireito")
HotkeySet ("{F7}", "AutoCleanMode1")

while 1
if $CMD=1 then
 While 1
   MouseClick("Left")
 WEnd
endif

if $ACM=1 then
 While 1
   MoveMouse(200, 200, 1)
    Sleep (3000)
   MoveMouse(400, 400, 1)
 WEnd
endif

sleep(50)
wend

Func ClickMouseDireito()
$CMD-=1
$CMD*=-1
EndFunc

Func AutoCleanMode1()
$ACM-=1
$ACM*=-1
EndFunc

Dont do 2 if in same time .. or do one or do another ..

I think you missed the concept a little. You need to get rid of the extra while-wends that you added. that is where you're problem is. What you want is for the code to execute in a SINGLE loop. Take out the while-wends from inside the if-then-endif statements, and you should be fine Edited by improbability_paradox

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

OHHH.. Sry again but forgot mention. I ll tell what Im trying to do. My script when started he sends mouse click all the time and dont stop anymore.. Than when you start second function. This will be move mouse in two coords A and B. When passed for example 20 secs he start move mouse 3 times for example and still clicking... I have a script that I got in internet that do this and it isnt in while ... it is in functions .. one for clicks and other to move mouse ... and a main while for bot never stop like While 1 Sleep 1 WEnd ... Thats the reason that I put whiles inside IFs

LOL.. I cant believe .. I already tryed about 20 diferents scripts ^^ :)

Edited by stackover

Share this post


Link to post
Share on other sites

Any sugestion ?

Thanks

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

Any sugestion ?

Thanks

About what? Sorry, but I don't understand what the question is. what is it that isn't working? Was it any closer to what you wanted when you tried my code without the while-wend statements in the if-then clauses?

As far as putting the actions inside of functions goes, there is no reason not to do that. What you have to understand is that both functions are not run concurrently. It is one, then the other. (Although you can, of course, call a function from inside of another function)

But back to the point of this post, what suggestions, exactly, are you looking for?

Edited by improbability_paradox

Share this post


Link to post
Share on other sites

Just try make a script that do for example:

1st function: Only do mouse click right. Once started dont stop any more.

2nd function: 20 in 20 secs do mouse move in two coordenates. Dont stop either. Times in times execute mouse moves.

I know that is possible. I got a script in internet that do it. But I have to learn how to do this to make others functions. And in script the author dont use IFs. He use Func.

That the motive that Im scared.

Regards

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

OK, so for function 1, there is no time delay between mouse clicks, correct?

And for function 2, the mouse moves a certain way every 20 seconds?

Personally, I would use the same basic template that I already gave you, in order to accomplish this. I would, however, probably employ a few UDF's (functions) that I would write for the task. There are many ways of getting to the same ends, but this is how I would do it.

function 1 is easy, if you do not want a delay. The trick is simply making sure that function two doesn't mess up function one. Notice that if I use a Sleep() function, I will 'pause' the ENTIRE script, and so function 1 will cease to work until it is 'un-paused'. To get around this, I would use TimerInit() and TimerDiff(). An example would look something like this.

local $TimerStatus=0, $TimerValue

while 1

Switch $TimerStatus
case 0
$TimerValue=TimerInit()
$TimerStatus=1
case 1
If TimerDiff($TimerValue) > 20000 then
$TimerStatus=2
;Do whatever you want... mousemove, or something else
$TimerValue=TimerInit()
endif
case 2
If TimerDiff($TimerValue) > 20000 then
$TimerStatus=1
;Do some other action
$TimerValue=TimerInit()
endif
EndSwitch
sleep(50)
wend

This script will alternate between doing two different actions every twenty (approximately) second. In the mean time, you can keep doing whatever else you want (MouseClicks, etc.) so long as the code is between the original While-Wend loop, and does not form a part of the Switch-Case-EndSwitch argument.

To understand these features better, take a look in the helpfile at TimerInit, TimerDiff, and Switch (which is like another form of if-then-elseif-endif statement)

Note that the above code is untested, as I wrote in in the browser window, but the concept should be correct and so long as there are no syntax errors, it should work.

BTW, this script you found on the internet, was in made in AutoIT?

Edit: so you know, the Sleep(50) is inside the loop so as to prevent the script from consuming all of your CPU time

Edit2: I intentionally did not write the full code for you. This is so that, by trial and error, you can learn the syntax of these new functions/arguments

Edited by improbability_paradox

Share this post


Link to post
Share on other sites

I troggle all fods in script that I found in internet that works two functions in the same time and I found some curious thing ... Look at final of script... dont have a Endif statment and script compiles fine.. lol

Look he screanshot

post-18439-1169856867_thumb.jpg

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

I troggle all fods in script that I found in internet that works two functions in the same time and I found some curious thing ... Look at final of script... dont have a Endif statment and script compiles fine.. lol

Look he screanshot

That is curious. I would bet that there actually is an endif statement buried in there, but that some other statement doesn't close (while without wend, for example) and so Scite can't figure it out.

I know that you think that this script is running two functions at once, but it just plain isn't possible. There is physically no way for Autoit to execute two lines of code simultaneously. As I said before, to you it has the APPEARANCE of running "two functions at once", but this is simply an appearance. In cannot happen in the way that you think it is. There is no MultiThreading in Autoit! period.

Anyway, did you try out the code that I posted? Are you able to get it to do what you want? I will work with you to get it to that point. Post what you have, and I will continue to make suggestions.

Edited by improbability_paradox

Share this post


Link to post
Share on other sites

#17 ·  Posted (edited)

Believe me..its runs two functions or is there a command to stop a function? In script there is a simple function like this:

Func Click()

While 1

mouseclick("right")

WEnd

EndFunc

How can be possible once this While in func started call others functions? There is no variable to do a exitloop there isnt nothing so how can be possible exit this while ?

Or code works good. But I need it deferent. For example like in script. Example:

If press F5 start click. If press F6 dont stop clicks but after 20 secs do mouse moves and after do 2 moves back to mouse clicks. Its very important to make it with HotKeys and once start functions never stop both. They still work all the time.

Im editind script that I found in internet and when I ll get this **** code I ll post. :)

Thanks

Edited by stackover

Share this post


Link to post
Share on other sites

Hmm, maybe I missed something while skimming the text, but maybe adlible() is just what you want. You could set a var if a func is called by adlible and if that's the case, use the "normal" func-call. Just a wild guess. :)

Share this post


Link to post
Share on other sites

Im tried with AdlibEnable() dont work. Maybe I did wrong. Can someone help if it real work ?

Share this post


Link to post
Share on other sites

Believe me..its runs two functions or is there a command to stop a function? In script there is a simple function like this:

Func Click()

While 1

mouseclick("right")

WEnd

EndFunc

How can be possible once this While in func started call others functions? There is no variable to do a exitloop there isnt nothing so how can be possible exit this while ?

Or code works good. But I need it deferent. For example like in script. Example:

If press F5 start click. If press F6 dont stop clicks but after 20 secs do mouse moves and after do 2 moves back to mouse clicks. Its very important to make it with HotKeys and once start functions never stop both. They still work all the time.

Im editind script that I found in internet and when I ll get this **** code I ll post. :)

Thanks

By combining the concepts from the last template-script I gave you with the previous script, you will have exactly what you asked for. As I said, I intentionally DID NOT combine both scripts, so that you would need to do it. That is how you will learn how the functions work. If you correctly combine the two templates I gave you into one script, it will work. That isn't to say that it is the only way. :">

Perhaps you can post the the script you keep referring to, so that we can take I look and figure out why it "appears" to do what you claim. I guaranty that two functions are not being run at the same time... not if it is an AutoIT script, anyway.

Share this post


Link to post
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
Sign in to follow this  
Followers 0