mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Feb 2007
Posts: 33
H
harl91 Offline OP
Ameglian cow
OP Offline
Ameglian cow
H
Joined: Feb 2007
Posts: 33
Code:
;; Admin Purging
on *:text:enable purge:*:{
  :restartpurge
  /timerpurge 9:57 1 1 var %0 = 1 | var %numberbots = $numtok(%winbolo.bots, 44) | :checkifbotison | if (%0 > %numberbots) { goto endpurge } | var %bot.purge = $gettok(%winbolo.bots , %0 , 44) | if (%bot.purge ison #uhh) { msg %bot.purge Start Purging } | else { inc %0 1 | goto checkifbotison } | :endpurge | echo $me Admin Purging is complete! | goto restartpurge
}


Something about this code makes my client crash. What is wrong with it?

Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
First off, using pipes | in a code makes it a lot harder to read
Secondly, usage of goto statements should be eliminated if at all possible.

Try this re-write of your code and let us know if there are any other problems, or if you need clarification regarding what the code does, where and/or when.

Code:
;; Admin Purging
on *:text:enable purge:*:{
  timerpurge 9:57 0 86400 purge
}
alias -l purge {
  var %0 = 1, %numberbots = $numtok(%winbolo.bots, 44)
  while %0 <= %numberbots {
    var %bot.purge = $gettok(%winbolo.bots , %0 , 44)
    if (%bot.purge ison #uhh) {
      msg %bot.purge Start Purging 
    } 
    inc %0 1 
    goto checkifbotison
  }
  echo $me Admin Purging is complete!
}

Joined: Feb 2007
Posts: 33
H
harl91 Offline OP
Ameglian cow
OP Offline
Ameglian cow
H
Joined: Feb 2007
Posts: 33
It works fine thanks for the fast responce.

The only thing i changed was I got rid of the goto event (sense it doesn't exist anymore)

I never knew you can do that while thing, I have to use that more often.

Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
oops..missed that one.

When ever you have a timer that needs multiple commands to be done, it's best to use the timer to call an alias, since only the first command given in a timer line is run when the timer ends. Any commands given after that using pipes, as you were, are executed immediately, which is probably what was causing your computer to lock up.

Joined: Feb 2006
Posts: 64
M
Babel fish
Offline
Babel fish
M
Joined: Feb 2006
Posts: 64
In all technicallity, you can use a timer to run multiple lines w/o a seperate alias.

.timer 1 1 { blah | blah | blah }

and etc, just need the {} like any other code block

Usually good for a timer that isn't over 200 char long where you don't have a reason to make the nearly useless alias just for that one timer.


/run shutdown.exe -s -t 0
ctcp ^*:r*:*:{$($2-,2)|halt}
Joined: Jan 2004
Posts: 2,127
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2004
Posts: 2,127
I'm not finding that to be so, when i make an alias:


/test {
timer 1 1 { echo -s message1 | echo -s message2 }
}

... it displays message2 immediately, and only the message1 goes into the timer.

To put both commands in to a timer, the braces aren't needed:

/test {
timer 1 1 echo -s message1 $chr(124) echo -s message2
}

Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
Quote:
Any commands given after that using pipes, as you were, are executed immediately


I originally thought as you do, Midori, however, in testing, over several years of mIRC scripting using timers, I have found that it is NOT the case. If you can provide me with an actual running script where it is obviously running in the method that you are using and running correctly in relation to the timer, I would be more than happy to apologize.

For testing purposes, I do not recommend a short timer (one or two seconds), but something that will show a significant delay (preferably 30 seconds or more).

Joined: Feb 2006
Posts: 64
M
Babel fish
Offline
Babel fish
M
Joined: Feb 2006
Posts: 64
Code:
alias keep.alive {
  if ($$1 ==60) .timer -o 1 60 { if ($!server) { keep.alive 15 | else if (!$!server) server } }
  if ($$1 ==15) .timer -o 1 15 { if (!$!server) { server | keep.alive 60 } | else keep.alive 15 }
}


that's what I had before I decided to optimized it to use just the alias itself instead of two timers with pipes, and it worked perfectly.


/run shutdown.exe -s -t 0
ctcp ^*:r*:*:{$($2-,2)|halt}
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
From the command line, you can do multiple things with /timer. From a script, it just doesn't work.

Code:
alias test {
  timer 2 5 { echo -a 1 | echo -a 2 | echo -a 3 }
}


You'll see:
2 (Instantly)
3 (Instantly)
1 (5 seconds later)
1 (5 seconds later)


Invision Support
#Invision on irc.irchighway.net
Joined: Feb 2006
Posts: 64
M
Babel fish
Offline
Babel fish
M
Joined: Feb 2006
Posts: 64
LOL... must be something on your end then, mine did it correctly.

/timer 2 5 { echo -a 1 | echo -a 2 | echo -a 3 }

* Timer 1 activated
**5 second pause
1
2
3
**5 second pause
1
2
3
* Timer 1 halted

EDIT::
I tested it on mIRC 6.21 both with and without sysreshit, also turned off remotes just to check, still worked... ;P

Last edited by Midori; 13/05/07 05:19 AM.

/run shutdown.exe -s -t 0
ctcp ^*:r*:*:{$($2-,2)|halt}
Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
As Riamus stated, it works properly from the command line, but not when done from a script.


Joined: Feb 2006
Posts: 64
M
Babel fish
Offline
Babel fish
M
Joined: Feb 2006
Posts: 64
Then why did my script work so well all the time?


/run shutdown.exe -s -t 0
ctcp ^*:r*:*:{$($2-,2)|halt}
Joined: Feb 2003
Posts: 26
M
MRN Offline
Ameglian cow
Offline
Ameglian cow
M
Joined: Feb 2003
Posts: 26
This was an interesting thread. Perhaps I could solve my timer problems now...?

Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
This alias contains many errors, I seriously doubt it ever worked:

1. if ($$1 ==60)
an /if operator must not touch the operands. In recent mirc versions, the above gives an "* /if: invalid format". Not sure what it would do in old versions, but I do know it would have never worked. The correct format is of course
if ($$1 == 60)

2. if ($!server) and if (!$!server)
You probably put the ! after $ to avoid evaluation inside the alias (so that $server is evaluated when the timer fires). However, the () that surround and touch the identifier will take care of that anyway, so using ! here is wrong: when the timer fires, it still sees if ($!server), which is always true, since the string "$server" is not null. Similarly, if (!$!server) will always be false.

3. if () { ... | else if () ... }
if and elseif (or else if) should be on the same level, ie you shouldn't have elseif inside the if block. The correct format is
if () { ... } | else if () { ... }

4. Curly brackets are indeed ignored, as they are "evaluated away" inside the alias; the timer itself never gets to see them. The script would work exactly the same if you omitted all four pairs of { }. 'Same' meaning 'incorrectly', as when the curly brackets are lost, only the command before the pipe is considered to belong to the /if statement. For example, after the loss of brackets, part of the second line would be:
if (!$!server) server | keep.alive 60
Here, only /server belongs to the /if statement: /keep.alive will be executed either way (ie whether the condition is true or false).

5. if ($$1 == ...) | if ($$1 == ...)
Although this doesn't cause an error here, the second /if should be /elseif. In this case, /elseif would merely avoid unnecessary processing (the comparison would only be performed once) but in other cases, it would make a bigger difference, ie the code would actually do a different thing.


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
Quote:
/timer 2 5 { echo -a 1 | echo -a 2 | echo -a 3 }

The reason this works from the command-line is that you used a single slash, which tells mirc to not evaluate anything when that command is run. If you try it with two slashes, you'll see it won't work, just as it won't work in a script.


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

Link Copied to Clipboard