mIRC Homepage
Posted By: harl91 Something wrong with this script - 12/05/07 04:58 PM
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?
Posted By: RusselB Re: Something wrong with this script - 12/05/07 05:10 PM
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!
}
Posted By: harl91 Re: Something wrong with this script - 12/05/07 05:22 PM
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.
Posted By: RusselB Re: Something wrong with this script - 12/05/07 05:38 PM
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.
Posted By: Midori Re: Something wrong with this script - 13/05/07 01:48 AM
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.
Posted By: maroon Re: Something wrong with this script - 13/05/07 02:54 AM
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
}
Posted By: RusselB Re: Something wrong with this script - 13/05/07 03:51 AM
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).
Posted By: Midori Re: Something wrong with this script - 13/05/07 04:21 AM
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.
Posted By: Riamus2 Re: Something wrong with this script - 13/05/07 04:35 AM
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)
Posted By: Midori Re: Something wrong with this script - 13/05/07 05:17 AM
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
Posted By: RusselB Re: Something wrong with this script - 13/05/07 05:44 AM
As Riamus stated, it works properly from the command line, but not when done from a script.

Posted By: Midori Re: Something wrong with this script - 13/05/07 06:27 AM
Then why did my script work so well all the time?
Posted By: MRN Re: Something wrong with this script - 13/05/07 11:26 AM
This was an interesting thread. Perhaps I could solve my timer problems now...?
Posted By: qwerty Re: Something wrong with this script - 13/05/07 11:58 AM
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.
Posted By: qwerty Re: Something wrong with this script - 13/05/07 12:00 PM
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.
© mIRC Discussion Forums