| View previous topic :: View next topic |
| Author |
Message |
degarb
Joined: 14 Feb 2007 Posts: 98
|
Posted: Sat Jul 07, 2007 9:02 pm Post subject: loops |
|
|
I wrote a monitor log script, but also wish to monitor a website--two perpetual loops within/using same exe (compiled).
Can AHK do two loops at once? Only with settimer? (I think I used goto in one loop.) |
|
| Back to top |
|
 |
degarb
Joined: 14 Feb 2007 Posts: 98
|
Posted: Sat Jul 07, 2007 9:17 pm Post subject: |
|
|
I always assumed not. In past to avoid bloated distro, I would create an engine (resource edited autohotkey.exe) and pass off scripts to make multiple threads.
Problems is this means more files in the directory to confuse user, loss of hiding code, and need for a zipped distro or extractor. |
|
| Back to top |
|
 |
toralf
Joined: 31 Jan 2005 Posts: 3842 Location: Bremen, Germany
|
Posted: Sat Jul 07, 2007 9:58 pm Post subject: |
|
|
Two loops are possible, you have to start two threads (SetTimer), or the script is calling itself again (maybe with a command line parameter, so that it knows it is the second call). Either way, you have only one file. _________________ Ciao
toralf  |
|
| Back to top |
|
 |
degarb
Joined: 14 Feb 2007 Posts: 98
|
Posted: Mon Jul 09, 2007 12:29 pm Post subject: |
|
|
Thanks, I think I understand. (anyone with ex.?)
>Two loops are possible, you have to >start two threads (SetTimer),
So any set timer should start a loop on startup of script? So several set timers start several loops at one time?
>or the script is calling itself >again (maybe with a command line >parameter, so that it knows it is >the second call).
What kind of parameter?
A script to run self. Would not this create endless opening same new scripts at exponential rate [1>2>4>8>16>32>64>128>etc], and crash your machine? |
|
| Back to top |
|
 |
ManaUser
Joined: 24 May 2007 Posts: 904
|
Posted: Mon Jul 09, 2007 5:09 pm Post subject: |
|
|
I was going to give an example... only it doesn't work.
| Code: | SetTimer SecondLoop, -1
X := 0
Y := 1
Loop
{
X += 1
ToolTip X = %X%, 10, 20, 1
Sleep 1000
}
SecondLoop:
Loop
{
Y *= 2
ToolTip Y = %Y%, 10, 40, 2
Sleep 1000
} |
I guess script threads don't interact the way I thought.
Making the compiled script call itself might work. It would just need to to let the second copy know not to call any more. A command line parameter would probably be the simplest way.
Last edited by ManaUser on Mon Jul 09, 2007 10:18 pm; edited 1 time in total |
|
| Back to top |
|
 |
tonne
Joined: 06 Jun 2006 Posts: 1190 Location: Denmark
|
Posted: Mon Jul 09, 2007 5:24 pm Post subject: |
|
|
Why mix timers and loops?
| Code: | SetTimer SecondLoop, 1000, -1
SetTimer FirstLoop, 1000, 0
X := 0
Y := 1
return
FirstLoop:
X += 1
ToolTip X = %X%, 10, 20, 1
return
SecondLoop:
Y *= 2
ToolTip Y = %Y%, 10, 40, 2
return |
_________________ there's a dog barking close within the range of my ear
sounds like he wants to escape the chain
he would probably bite me to death if he could
but the chain lets me spit in his face
- Kashmir |
|
| Back to top |
|
 |
Titan
Joined: 11 Aug 2004 Posts: 5107 Location: eth0 ::1
|
Posted: Mon Jul 09, 2007 9:37 pm Post subject: |
|
|
| tonne wrote: | | Why mix timers and loops? | You may want real simultaneous loops for A_Index, Break, Continue etc. and ManaUser's example shows how you can do that. _________________
RegExReplace("irc.freenode.net/ahk", "^(?=(.(?=[\0-r\[]*((?<=\.).))))(?:[c-\x73]{2,8}(\S))+((2)|\b[^\2-]){2}\D++$", "$u3$1$3$4$2") |
|
| Back to top |
|
 |
tonne
Joined: 06 Jun 2006 Posts: 1190 Location: Denmark
|
Posted: Mon Jul 09, 2007 9:41 pm Post subject: |
|
|
only it doesn't work...
When the timed thread with a loop is started the x-loop never continues. _________________ there's a dog barking close within the range of my ear
sounds like he wants to escape the chain
he would probably bite me to death if he could
but the chain lets me spit in his face
- Kashmir |
|
| Back to top |
|
 |
Titan
Joined: 11 Aug 2004 Posts: 5107 Location: eth0 ::1
|
Posted: Mon Jul 09, 2007 10:01 pm Post subject: |
|
|
| tonne wrote: | | When the timed thread with a loop is started the x-loop never continues. | It does for me. You may need to update your version of AutoHotkey since the '-1' option on SetTimer is a relatively new feature. _________________
RegExReplace("irc.freenode.net/ahk", "^(?=(.(?=[\0-r\[]*((?<=\.).))))(?:[c-\x73]{2,8}(\S))+((2)|\b[^\2-]){2}\D++$", "$u3$1$3$4$2") |
|
| Back to top |
|
 |
daniel2 Guest
|
Posted: Mon Jul 09, 2007 10:17 pm Post subject: |
|
|
It doesn't for me either; I was actually toying around w/ this the other day-- & I evan tried adjusting priority level w/ no success.. | Code: | #Persistent
X := 0 , Y := 1
SetTimer, FirstLoop, -1, 1
SetTimer, SecondLoop, -1, 1
return
^t::Msgbox, Hotkeys don't seem to launch thread either...
FirstLoop:
Loop {
X += 1
ToolTip X = %X%, 10, 20, 1
Sleep 1000
}
SecondLoop:
Loop {
Y *= 2
ToolTip Y = %Y%, 10, 40, 2
Sleep 1000
} | It seems like the thread that takes charge is the one w/ the highest priority or if same priority-- the most recent called. I also noticed that hotkeys don't launch thread as expected either
I wasn't going to post since I don't regularly create infinate loops.. but since I saw someone talking about it......... |
|
| Back to top |
|
 |
tonne
Joined: 06 Jun 2006 Posts: 1190 Location: Denmark
|
Posted: Mon Jul 09, 2007 10:27 pm Post subject: |
|
|
Just installed 1.0.47.01 (from 1.0.47.00) and still it doesn't work.
X is counted to 1 and Y is doubled until script is stopped. _________________ there's a dog barking close within the range of my ear
sounds like he wants to escape the chain
he would probably bite me to death if he could
but the chain lets me spit in his face
- Kashmir |
|
| Back to top |
|
 |
ManaUser
Joined: 24 May 2007 Posts: 904
|
Posted: Mon Jul 09, 2007 10:32 pm Post subject: |
|
|
All I can figure is that AutoHotkey "threads" don't work how you would expect. It seems one thread always has exclusive control, until either it ends, or is interupted. AHK never does time sliceing or anything like that as far as I can see.
But tonne does have a point. What you're trying to do can almost surely be accomplished without two actuall loops running at the same time. It may just take more work to set it up. |
|
| Back to top |
|
 |
engunneer
Joined: 30 Aug 2005 Posts: 6804 Location: Pacific Northwest, US
|
Posted: Mon Jul 09, 2007 10:48 pm Post subject: |
|
|
AHK is not multithreaded. Try using a positive timer value, and they won't step on each other.
| Code: |
#Persistent
X := 0 , Y := 1
SetTimer, FirstLoop, 1000
SetTimer, SecondLoop, 1000
return
^t::Msgbox, Hotkeys don't seem to launch thread either...
FirstLoop:
X += 1
ToolTip X = %X%, 10, 20, 1
Return
SecondLoop:
Y *= 2
ToolTip Y = %Y%, 10, 40, 2
Return
|
_________________
Unless otherwise noted, all code is untested.
Common Answers: 1.(Loops, Viruses, etc.) 2. Search 3.RTFM |
|
| Back to top |
|
 |
daniel2 Guest
|
Posted: Tue Jul 10, 2007 3:29 am Post subject: |
|
|
| tonne wrote: | | Why mix timers and loops? |
| Titan wrote: | | You may want real simultaneous loops for A_Index, Break, Continue etc. and ManaUser's example shows how you can do that. |
tonne also gave a regular timer example (not using loop..). My point was that if you do need to use a loop in a thread (or pseudo-thread.. whatever you want to call them..) they seem to conflict w/ other threads. |
|
| Back to top |
|
 |
|