mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Feb 2006
Posts: 64
M
Midori Offline OP
Babel fish
OP Offline
Babel fish
M
Joined: Feb 2006
Posts: 64
alias keep.alive {
if ($$2 == 15) .timer $+ $$1 -o 0 15 $iif(!$server,keep.alive $1 mix,keep.alive $1 15)
elseif ($$2 == 60) .timer $+ $$1 -o 0 60 $iif($server,keep.alive $1 15,$!iif(!$server,server))
elseif ($$2 == mix) { keep.alive $1 60 | server }
}

when i'm not connected to any server it always gives me: "* /keep.alive: not connected to server (line 70, Startup.mrc)"
and line 70 is that last elseif

why would it do that?


/run shutdown.exe -s -t 0
ctcp ^*:r*:*:{$($2-,2)|halt}
Joined: Jan 2007
Posts: 1,156
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Jan 2007
Posts: 1,156
you cannot call an alias from within itself.

/help Aliases
Quote:
Aliases can be called from the command line, from other aliases, and from popup and remote scripts. An alias cannot call itself recursively mainly because this seems to cause more problems for users than it solves.

Joined: Apr 2004
Posts: 759
M
Hoopy frood
Offline
Hoopy frood
M
Joined: Apr 2004
Posts: 759
You can only call mIRC's built in commands from within themselves:
Code:
alias msg { 
  echo -a msg: $1-
  msg $1-
}

The 2nd line in that alias wont retrigger your custum alias but mIRC's own.

You can overcome the disability of no recursion by calling the alias from a timer. Most picwin animations for instance use this trick.


$maybe
Joined: Feb 2006
Posts: 64
M
Midori Offline OP
Babel fish
OP Offline
Babel fish
M
Joined: Feb 2006
Posts: 64
Well that's useless smirk
Recursion is a very powerful tool in programming, don't see why it can't be in mIRC script.


/run shutdown.exe -s -t 0
ctcp ^*:r*:*:{$($2-,2)|halt}
Joined: Apr 2004
Posts: 759
M
Hoopy frood
Offline
Hoopy frood
M
Joined: Apr 2004
Posts: 759
put it in a timer as i stated earlier

Code:
alias recurse { 
  if (%recurse !isnum 0-5) unset %recurse
  inc %recurse
  if (%recurse == 5) echo -a yay recursed %recurse times!
  else .timerrecurse -m 1 0 recurse
}


will echo "yay recursed 5 times!" .timerrecurse -m 1 0 making it execute after 0ms have passed.
Just make sure you use a named timer for recursion as this will improve speed ALOT.

Last edited by Mpdreamz; 16/03/07 03:14 PM.

$maybe
Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
Recursion is supported in mirc, just not direct recursion. You can easily achieve the same effect with:
Code:
alias keep.alive2 keep.alive $1-
and use "keep.alive2" instead of "keep.alive" for the recursive call.


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
Joined: Jul 2006
Posts: 10
G
Pikka bird
Offline
Pikka bird
G
Joined: Jul 2006
Posts: 10
Originally Posted By: Midori
Well that's useless smirk
Recursion is a very powerful tool in programming, don't see why it can't be in mIRC script.
that is exactly why it isn't allowed. mIRC isn't multi-threaded as far as I know, so if you have one script recursively calling itself, then nothing else gets executed, and the client gets locked.

Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
If you're talking about badly written recursive aliases, mirc will not lock up, it will just halt the script with a "* Error allocating stack memory" message, after 1000 recursive calls.

However not all recursive aliases have to be badly written and recursion is indeed a very useful tool. The reason direct recursion is not allowed is because the majority of novice scripters do not usually mean to use recursion when they make an alias call itself; they usually mean to use the built-in command that has the same name as their alias.


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com

Link Copied to Clipboard