mIRC Home    About    Download    Register    News    Help

Print Thread
#85956 08/06/04 03:43 PM
Joined: Apr 2004
Posts: 21
_
Ameglian cow
OP Offline
Ameglian cow
_
Joined: Apr 2004
Posts: 21
hoi,

how can i wait until a var has a value (the value i check) ?
for example what i mean:

Code:
  if %update_check == 1 {
    xecho sca $hget(htdb, msg_0008)
    sockopen n1update www.n1ght.de 80
    set %update_isin_progress 1
  }
  while %update_isin_progress == 1 {} ;do nothing 
  // perform the rest
  echo -a blubb


this will not work because mirc freezes in the while loop. So how can i wait else? i dont want to use a timer.

#85957 08/06/04 04:28 PM
Joined: Dec 2002
Posts: 1,922
O
Hoopy frood
Offline
Hoopy frood
O
Joined: Dec 2002
Posts: 1,922
You'll have to place the rest of the code at the sockclose event.

#85958 08/06/04 04:43 PM
Joined: Apr 2004
Posts: 21
_
Ameglian cow
OP Offline
Ameglian cow
_
Joined: Apr 2004
Posts: 21
thats bad, i have to perform the code that follows always!
if updatecheck is off (%update_check == 0) the code will not perform

Last edited by _Delphi_; 08/06/04 04:44 PM.
#85959 08/06/04 05:18 PM
Joined: Apr 2003
Posts: 701
K
Hoopy frood
Offline
Hoopy frood
K
Joined: Apr 2003
Posts: 701
You don't have a lot of options here.

-> Either use a timer to check for that condition every second, something like /timer 0 1 updatecheck
-> Find every place where %var might be changed and put your code or a call to your alias behind it

It's impossible to wait in an alias until something else happens and then continue from that place in the alias. You'll have to save the status in your alias yourself and restore it when you're able to continue...

Busy waiting (while (%var != 1) { } ) will not work, like you already noticed. mIRc has only one thread executing, and if it's busy doing empty while loops, anything else (like changing the %var in the test) has to wait until the loop is done...

#85960 08/06/04 05:22 PM
Joined: Dec 2002
Posts: 1,922
O
Hoopy frood
Offline
Hoopy frood
O
Joined: Dec 2002
Posts: 1,922
You can put the rest of the code in a separate alias and call it either from the sockclose event, or from the main code if %update_check is not enabled:
Code:
  ; main script goes here
  ...
  if %update_check == 1 {
    sockopen n1update www.n1ght.de 80
  }
  else [color:purple]do_stuff[/color]
}
 
...
 
On *:sockclose:n1update:{
  [color:purple]do_stuff[/color]
}
 
alias [color:purple]do_stuff[/color] {
  ...
  the rest of the code goes here
  ..
}

#85961 08/06/04 08:37 PM
Joined: Apr 2004
Posts: 21
_
Ameglian cow
OP Offline
Ameglian cow
_
Joined: Apr 2004
Posts: 21
thx to you all wink

#85962 08/07/04 08:22 PM
Joined: Jul 2004
Posts: 31
H
Ameglian cow
Offline
Ameglian cow
H
Joined: Jul 2004
Posts: 31
alias wait {
var %tmp = $+($ticks,.wsf)
write %tmp <job id="js"><script language="jscript">WScript.Sleep( $+ $$1 $+ );</script></job>
.comopen %tmp WScript.Shell | if !$comerr { .comclose %tmp $com(%tmp,Run,3,bstr,%tmp,uint,0,bool,true) }
.remove %a
}

usage: wait <value>, value in ms

#85963 02/07/06 06:39 PM
Joined: Jul 2006
Posts: 5
N
Nutrimatic drinks dispenser
Offline
Nutrimatic drinks dispenser
N
Joined: Jul 2006
Posts: 5
I tried to use this function, but it doesn't seem to return after I call it.
-EXAMPLE-
Code:
echo going | $wait 3000 | echo back

-OUTPUT-:
Code:
going

*EDIT* *UPDATE*
After some fiddling, I was able to get it to work. I must credit whoever came up with this method of causing mirc to sleep, it really is quite clever!

Here is my slightly modified (hopefully you will see the changes as an improvement!) wait alias code:
-CODE-
Code:
alias wait {
  ; defaults to 1000ms
  if ($1) { var %duration = $1 }
  else { var %duration = 1000 }
  var %tmp = $+($ticks,.wsf)
  var %cmd = &lt;job id="js"&gt;&lt;script language="jscript"&gt;WScript.Sleep( $+ %duration $+  );&lt;/script&gt;&lt;/job&gt;
  write %tmp %cmd
.comopen %tmp WScript.Shell | if !$comerr { .comclose %tmp $com(%tmp,Run,3,bstr,%tmp,uint,0,bool,true) }
  .remove %tmp
}

-USAGE-
As far as I know, it can be used three ways from within a script:
Code:
;1st
$wait
; -or-
;2nd
$wait()
; both of these will default to 1000ms since no $1 arg is passed
;-or
;3rd
$wait(5000)
; will sleep for 5 seconds before deleting the tmp file and returning control to the caller.


Hopefully this will be helpful for someone at a future point in time. I would also like to give a BIG THANKS to hmtX for posting this code to begin with!

Last edited by nacholibre; 02/07/06 07:31 PM.
#85964 02/07/06 07:37 PM
Joined: Jul 2004
Posts: 31
H
Ameglian cow
Offline
Ameglian cow
H
Joined: Jul 2004
Posts: 31
dunno why there seems to be a message by someone else missing but that code isn't mine, so no need to thank me E_E


Link Copied to Clipboard