Jump to content

Recommended Posts

Posted (edited)

I was attempting to run two different functions simultaneously, at first i was just using two different scripts, but they seem to conflict with each other too often. i did some digging and found the following.

https://www.autoitscript.com/forum/topic/19521-running-2-loops-at-the-same-time/

the only problem is im having issues getting this to use a sleep(random) to go with my script.

  Reveal hidden contents

if anyone can help me solve this, it would be much appreciated.

 

edit:

second failed example of trying to code it in

  Reveal hidden contents

it waits until timer two's delay finishes, then just infinitely spams.

Edited by Bobm
added second failed example of my code
Posted

What is the problem, exactly?

Try setting the random prior to the sleep, have the random in a variable and place the variable in the sleep, see if it makes any difference.

  Reveal hidden contents

IUIAutomation - Topic with framework and examples

Au3Record.exe

Posted
  On 7/19/2018 at 5:55 PM, careca said:

What is the problem, exactly?

Try setting the random prior to the sleep, have the random in a variable and place the variable in the sleep, see if it makes any difference.

Expand  

so far when ive tried to add

Local $Timer1, $Delay1 = sleep(random)

it seems to wait until it reaches that time, then just infinitely spams

what im trying to have it do, is to repeatedly do the random sleep of f3 until its time for it to do f4, but so far when ive tried it seems to just be spamming both repeatedly without the properly sleep times

Posted

You  can't run 2 Sleeps at the same time, the whole script will pause for the first sleep time, and then continue.

Use timers and not sleep.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

  Reveal hidden contents

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Posted (edited)

What i meant for you to try:

$var = Random(3000, 5000, 1)
Sleep($var)

Now that i think of it, shouldn't make a difference.

Edited by careca
  Reveal hidden contents

IUIAutomation - Topic with framework and examples

Au3Record.exe

Posted
  On 7/20/2018 at 3:36 PM, BrewManNH said:

You  can't run 2 Sleeps at the same time, the whole script will pause for the first sleep time, and then continue.

Use timers and not sleep.

Expand  

thats what im attempting to figure out, is how to get the 2 random sleeps to work as random timers or vice versa, however it works.

 

  On 7/20/2018 at 3:25 PM, FrancescoDiMuro said:

Hi @Bobm, and welcome to the AutoIt forum :)
Post the code you are working on, so we can see what you've tried so far :)

Best Regards.

Expand  

its in the spoiler in my first post

Posted

Things i dont get: $Delay1 is never defined, how can the script check TimerDiff($Timer1) > $Delay1 if it doesn't know what the delay is?

And i didn't get the point of all this

 

  Reveal hidden contents

IUIAutomation - Topic with framework and examples

Au3Record.exe

Posted

Can you please explain the problem you want to solve?
So we can understand if two functions need to run at the same time or if another solution fits your needs.

My UDFs and Tutorials:

  Reveal hidden contents

 

Posted
  On 7/20/2018 at 8:11 PM, water said:

Can you please explain the problem you want to solve?
So we can understand if two functions need to run at the same time or if another solution fits your needs.

Expand  

yes, trying to get both function f3 and function f4 to work at the same time essentially, but i want them to both be running on random sleep times / delays. i want f3 to run continuously until its time for f4 to happen, pausing f3 until f4 finishes, and then return to f3 until its time for f4 again.

Posted

2 things:

1 - Dont quote a post directly above, it's anoying.

2 - That is not "running 2 functions simultaneously", that is alternating between 2 functions.

HotKeySet("{ESC}", "Terminate")
HotKeySet("{F2}", "OnOff")
;=============================================================================
Local $Timer1, $RdmTime
Local $On = 0
;=============================================================================
Func OnOff()
    If $On = 1 Then
        $On = 0
    Else
        $On = 1
    EndIf
EndFunc   ;==>OnOff
;=============================================================================
Func _F3a_Func()
    ConsoleWrite('_F3a_Func - ' & @MSEC & @CRLF)
EndFunc   ;==>_F3a_Func
;=============================================================================
Func _F4a_Func()
    ConsoleWrite('_F4a_Func - ' & @MSEC & @CRLF)
EndFunc   ;==>_F4a_Func
;=============================================================================
While 1
    If $On = 1 Then
        ;=============================================================================
        $RdmTime = Random(1000, 4000, 1)
        $Timer1 = TimerInit()
        Do
            If $On = 0 Then
            ExitLoop
            EndIf
            _F3a_Func()
            Sleep(100)
        Until TimerDiff($Timer1) > $RdmTime
        _F4a_Func()
        ;=============================================================================
    EndIf
    Sleep(100)
WEnd
;=============================================================================
Func Terminate()
    Exit 0
EndFunc   ;==>Terminate
;=============================================================================

 

  Reveal hidden contents

IUIAutomation - Topic with framework and examples

Au3Record.exe

Posted
  On 7/20/2018 at 10:24 PM, Bobm said:

yes, trying to get both function f3 and function f4 to work at the same time essentially, but i want them to both be running on random sleep times / delays. i want f3 to run continuously until its time for f4 to happen, pausing f3 until f4 finishes, and then return to f3 until its time for f4 again.

Expand  

You do not explain the problem, you explain the solution you try to implement.

Explaining the problem would be like:
"I have a script that runs application x. Sometimes a popup gets displayed. I need a function to wait for this popup and click a button"

My UDFs and Tutorials:

  Reveal hidden contents

 

Posted (edited)

@careca this seems to be almost perfect, plenty better than what i had. i notice that hitting the pause still has f4 go off, is this unavoidable?

i apologize, im not the best at explaining things. but you appear to understand what i was attempting to say. i really appreciate the help you have given.

@water

apologies, properly explaining things isn't one of my strengths. but i briefly mentioned in my original under the edit, and my first reply, of the problem being it was infinitely spamming. it seems i didnt quite make the issue of it quite clear. but it was spamming without any delay, and i was trying to get it to have proper delays.

Edited by Bobm
to make water happy. excuse my failed attempt to use the quotes for directing my response.
Posted

We do not expect a PERFECT explanation, but we do expect that you TRY to explain your PROBLEM.

  Quote

Dont quote a post directly above, it's anoying.

Expand  

What do you do in your next post?  You quote the post again :doh:

As it seems you do not read our replies and just keep repeating your initial post I'm out now!

My UDFs and Tutorials:

  Reveal hidden contents

 

Posted
  On 7/21/2018 at 6:41 AM, Bobm said:

@careca  i notice that hitting the pause still has f4 go off, is this unavoidable?

Expand  

Hi, No. Try this one:

HotKeySet("{ESC}", "Terminate")
HotKeySet("{F2}", "OnOff")
;=============================================================================
Local $Timer1, $RdmTime
Local $On = 0
;=============================================================================
Func OnOff()
    If $On = 1 Then
        $On = 0
    Else
        $On = 1
    EndIf
EndFunc   ;==>OnOff
;=============================================================================
Func _F3a_Func()
    ConsoleWrite('_F3a_Func - ' & @MSEC & @CRLF)
EndFunc   ;==>_F3a_Func
;=============================================================================
Func _F4a_Func()
    ConsoleWrite('_F4a_Func - ' & @MSEC & @CRLF)
EndFunc   ;==>_F4a_Func
;=============================================================================
While 1
    If $On = 1 Then
        ;=============================================================================
        $RdmTime = Random(1000, 4000, 1)
        $Timer1 = TimerInit()
        Do
            _F3a_Func()
            Sleep(100)
        Until TimerDiff($Timer1) > $RdmTime Or $On = 0
        If $On = 1 Then
        _F4a_Func()
        EndIf
        ;=============================================================================
    EndIf
    Sleep(100)
WEnd
;=============================================================================
Func Terminate()
    Exit 0
EndFunc   ;==>Terminate
;=============================================================================

 

  Reveal hidden contents

IUIAutomation - Topic with framework and examples

Au3Record.exe

Posted (edited)

@careca yes that worked, thank you. I think if i add another OnOff in there, i could perhaps pause f3 but keep f4 to continue after yes? or vice versa. i will attempt this when i get some time later.

im still very much a noob as they say. i used to know a bit more, but i havent done anything with coding in so long i have forgotten things.

 

Edited by Bobm

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
  • Recently Browsing   0 members

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