# two functions simultaneously

## Recommended Posts

I have a little problem.

Lets say i have 20 gates. Each gate takes 5 sec to open. I want to be able to open multiple gates at once.

Here is a function

```func opengate(\$gateID)
For \$i = _GetGateOpenVal(\$gateID) to 5 Step +1
GateOpenVal = GateOpenVal + 1
sleep(1000)
Next
Return
endfunc

func closegate(\$gateID)
For \$i = _GetGateOpenVal(\$gateID) to 0 Step -1
GateOpenVal = GateOpenVal - 1
sleep(1000)
Next
Return
endfuncoÝ÷ ØÚ0ël±¬¢«ÞheÂ«z'Ç¥yËmèµë0éâ±é^rÖ j×ºÚ"µÍ[Ý[ÛØ]Ù[XÝ

BÜ[Ø]J    ÌÍØÝ[Ø]JBÛÜÙYØ]J   ÌÍÔ][ÝÑØ]JB[[```

Now... The problem is that IF i select a gate (gate1), then 1 sec after select another gate(gate2). I have to wait for gate1 to fully open and close before gate2 start to open

Is it possible to run two functions simultaneously?

And is it possible to run one function 2 times at the same time?

[center][u]WoW Machinima Tool[/u] (Tool for Machinima Artists) [/center]

##### Share on other sites

I have a little problem.

Lets say i have 20 gates. Each gate takes 5 sec to open. I want to be able to open multiple gates at once.

Here is a function

```func opengate(\$gateID)
For \$i = _GetGateOpenVal(\$gateID) to 5 Step +1
GateOpenVal = GateOpenVal + 1
sleep(1000)
Next
Return
endfunc

func closegate(\$gateID)
For \$i = _GetGateOpenVal(\$gateID) to 0 Step -1
GateOpenVal = GateOpenVal - 1
sleep(1000)
Next
Return
endfuncoÝ÷ ØÚ0ël±¬¢«ÞheÂ«z'Ç¥yËmèµë0éâ±é^rÖ j×ºÚ"µÍ[Ý[ÛØ]Ù[XÝ

BÜ[Ø]J    ÌÍØÝ[Ø]JBÛÜÙYØ]J   ÌÍÔ][ÝÑØ]JB[[```

Now... The problem is that IF i select a gate (gate1), then 1 sec after select another gate(gate2). I have to wait for gate1 to fully open and close before gate2 start to open

Is it possible to run two functions simultaneously?

And is it possible to run one function 2 times at the same time?

You can't really run 2 functions at the same time in AutoIt. You could have another exe which executed a function and was passed parameters and this way you could have many functions running at the same time.

You could also write the code so that there was a main loop which managed all the gates like this say

```;not real code
while 1
;manage buttons etc
\$msg = GuiGetMsg()
if \$msg = \$but1 then \$AgateArray[1][1] = 1;start gate 1 opening

;deal with the next gate
\$Agate += 1
if \$Agate > \$LastGate then \$Agate = 1
dealwithgate(\$Agate)
wend

Then have a global array which has all the parameters for opening and closing gates
\$gateArray[20][3]; for up to 20 gates
element [\$Agate][1] = 1 if opening, 2 if closing 3 if fully open, 4 if fully closed
[\$Agate][2] = loop count for opening or closing
[3] = timer for when last increment was made
[0] gate state
func dealwithGate(\$ngate)
if \$gateArray[\$ngate][1] = 1 then;gate is opening
if \$gateArray[ngate][2] < \$maxloopount then
if timerdiffgateArray[\$ngate][3]) >= \$gatedelay then
\$gateArray[ngate][2] +=1
\$gateArray[ngate][3] = timerinit()
if \$gateArray[ngate][2] = \$maxloopcount then  \$gateArray[ngate][1] = 3;fully open
endif
endif
endif;same sort of thing for closing

.
.
.etc
endfunc```

This is all just an idea and what I have written is just as I've thought it up so don't expect that anything above will actually work! It's just to outline the idea.

EDIT: corrected name for array in the function.

Edited by martin

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

##### Share on other sites

You can't really run 2 functions at the same time in AutoIt. You could have another exe which executed a function and was passed parameters and this way you could have many functions running at the same time.

You could also write the code so that there was a main loop which managed all the gates like this say

```;not real code
while 1
;manage buttons etc
\$msg = GuiGetMsg()
if \$msg = \$but1 then \$AgateArray[1][1] = 1;start gate 1 opening

;deal with the next gate
\$Agate += 1
if \$Agate > \$LastGate then \$Agate = 1
dealwithgate(\$Agate)
wend

Then have a global array which has all the parameters for opening and closing gates
\$gateArray[20][3]; for up to 20 gates
element [\$Agate][1] = 1 if opening, 2 if closing 3 if fully open, 4 if fully closed
[\$Agate][2] = loop count for opening or closing
[3] = timer for when last increment was made
[0] gate state
func dealwithGate(\$ngate)
if \$gateArray[\$ngate][1] = 1 then;gate is opening
if \$gateArray[ngate][2] < \$maxloopount then
if timerdiffgateArray[\$ngate][3]) >= \$gatedelay then
\$gateArray[ngate][2] +=1
\$gateArray[ngate][3] = timerinit()
if \$gateArray[ngate][2] = \$maxloopcount then  \$gateArray[ngate][1] = 3;fully open
endif
endif
endif;same sort of thing for closing

.
.
.etc
endfunc```

This is all just an idea and what I have written is just as I've thought it up so don't expect that anything above will actually work! It's just to outline the idea.

EDIT: corrected name for array in the function.

Yhea, i thought i'd might end up in some big array project.

=(

Well... but thanks alot for the answer!

[center][u]WoW Machinima Tool[/u] (Tool for Machinima Artists) [/center]

## Create an account

Register a new account