Sign in to follow this  
Followers 0
Giordano

Help me Please! Maybe very difficult to do it... One script, more than 1 instance!

4 posts in this topic

#1 ·  Posted (edited)

I will explain the problem:

I have to create a GUI

in this GUI i can add some accounts (max 3 for example)

every account has a list of actions to do like this:

ACCOUNT 1 = timestamp of start:Function1()|timestamp of start:Function2()

ACCOUNT 2 = timestamp of start:Function1()|timestamp of start:Function2()

#include<Array.au3>
 
$ActionsAccount1 = String(_TimeGetStamp()+20)&":funcA()|"&String(_TimeGetStamp()+50)&":funcB()"
$ActionsAccount2 = String(_TimeGetStamp()+20)&":funcC()|"&String(_TimeGetStamp()+50)&":funcA()"
 
While 1
$ActualTimeStamp = _TimeGetStamp()
 
ConsoleWrite("$ActualTimeStamp&@CRLF"]$ActualTimeStamp&@CRLF)
ConsoleWrite("$ActionsAccount1&@CRLF"]$ActionsAccount1&@CRLF)
 
$Actions1 = StringSplit($ActionsAccount1,"|")
For $i = 1 To $Actions1[0]
 
  $Act1 = StringSplit($Actions1[$i],":")
  $Time = int($Act1[1])
  $FuncToDo = $Act1[2]
 
  If $Time <= $ActualTimeStamp Then
 
   Switch($FuncToDo)
 
    Case "funcA()"
     funcA()
 
    Case "funcB()"
     funcB()
 
    Case "funcC()"
     funcC()
 
   EndSwitch
 
   _ArrayDelete($Actions1,$i)
   ExitLoop
 
  EndIf
 
Next
 
_ArrayDelete($Actions1,0)
$ActionsAccount1 = _ArrayToString($Actions1,"|")
If $ActionsAccount1 = "" Then
  ConsoleWrite("Work Finished! See you later.."[email="&@CRLF"]&@CRLF[/email])
  Exit
EndIf
 
Sleep(1000)
 
WEnd
 
Func funcA()
For $i=1 To 10
  ConsoleWrite("Hello, i'm funcA!"[email="&@CRLF"]&@CRLF[/email])
  Sleep(1000)
Next
EndFunc
 
Func funcB()
For $i=1 To 20
  ConsoleWrite("Hello, i'm funcB!"[email="&@CRLF"]&@CRLF[/email])
  Sleep(1500)
Next
EndFunc
 
Func funcC()
For $i=1 To 15
  ConsoleWrite("Hello, i'm funcC!"[email="&@CRLF"]&@CRLF[/email])
  Sleep(500)
Next
EndFunc
 
Func _TimeGetStamp()
Local $av_Time
$av_Time = DllCall('CrtDll.dll', 'long:cdecl', 'time', 'ptr', 0)
If @error Then
  SetError(99)
  Return False
EndIf
Return $av_Time[0]
EndFunc

This code can elaborate a single list of functions to do....

Is there a function that can elaborate 2 different while wend loops simultanely (so a Loop will do actions related for $ActionsAccount1 and the other loop will do $ActionsAccount2)?

EDIT: CODE FIXED TIMING!

Thanks

Giordano[Rome,IT]

Edited by Giordano

[font=courier new, courier, monospace]Una piccola riflessione: [/font] [font=courier new, courier, monospace]Se guardassi la Terra da un pianeta distante 1 anno luce, vedresti la terra 1 anno prima di quell'istante! Quindi se tu potessi arrivare a quella distanza impiegando solo 6 mesi (quindi viaggiando a 2 volte la velocita della luce) vedresti il mondo com'era 6 mesi prima della partenza.. il passato![/font]

Share this post


Link to post
Share on other sites



Not getting whats on you mind code wise. But on the 'simultaneously' part ...

Only way to do more than one While-WEnd loop at the same time (in the same code/process) is by nesting them. (but that's generally not of any use.)

Best way to think (and code) you program is by knowing that in a given process only one thing can be done at the same time. But that in addition to that you have the option to temporary stop your main code execution to do something else.

Example:

;; general bailout.
AdlibRegister('_Exit', 10 * 1000)
Func _Exit()
    ConsoleWrite('... EXIT ...' & @CRLF)
    Exit
EndFunc

;; setup some main code break-in function call.
Global $fFlag = False
AdlibRegister('Adlib_Timed_Func', 1 * 1000)
;; Adlib just being one way. On eventMode calls are a other.
Func Adlib_Timed_Func()
    $fFlag = ($fFlag = False)
EndFunc

;; run main code.
main()
Func main()
    Local Const $iMAX = 16
    Local $iCount = 0
    While $iCount < $iMAX
        If $fFlag Then
            $iCount -= 1
        Else
            $iCount += 1
        EndIf
        ConsoleWrite('$iCount = ' & $iCount & @CRLF)
        Sleep(100)
    WEnd
EndFunc

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Share this post


Link to post
Share on other sites

Thank you for the reply, but i think this won't work for my kind of functions to launch...

Best way to think (and code) you program is by knowing that in a given process only one thing can be done at the same time

This is true, infact i don't need to run simultaneous function for the same account! (the account has to do different functions with different runtimes, but the next function can start, without problems, when the actual function finish his work!

But in same time, i need to follow the clock for the 2nd account! Like a NEW ISTANCE of the .EXE launch (with different account ID parameter)

if it is impossible to do, i could remove the multiaccount in my program and let the user launch more than 1 time the same program changing the user ID associated..

So i will have 2 different processess and all be ok.. But i was wondering to do it with the same MAIN program!

Sorry for my bad english

Giordano


[font=courier new, courier, monospace]Una piccola riflessione: [/font] [font=courier new, courier, monospace]Se guardassi la Terra da un pianeta distante 1 anno luce, vedresti la terra 1 anno prima di quell'istante! Quindi se tu potessi arrivare a quella distanza impiegando solo 6 mesi (quindi viaggiando a 2 volte la velocita della luce) vedresti il mondo com'era 6 mesi prima della partenza.. il passato![/font]

Share this post


Link to post
Share on other sites

Yes. Its possible to Run() multiple processes from a single Main process/program. (Best done from a single main program actually)

In basics its relative simple. But things can get complicated pretty fast. Suggest searching the forum a bit for examples in that area. (including examples that deal with communication between two processes.)


"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

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