mIRC Home    About    Download    Register    News    Help

Topic Options
#176628 - 12/05/07 05:58 PM Something wrong with this script
harl91 Offline
Ameglian cow

Registered: 24/02/07
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?

Top
#176629 - 12/05/07 06:10 PM Re: Something wrong with this script [Re: harl91]
RusselB Offline
Planetary brain

Registered: 03/08/04
Posts: 7252
Loc: Ontario, Canada
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!
}

Top
#176633 - 12/05/07 06:22 PM Re: Something wrong with this script [Re: RusselB]
harl91 Offline
Ameglian cow

Registered: 24/02/07
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.

Top
#176636 - 12/05/07 06:38 PM Re: Something wrong with this script [Re: harl91]
RusselB Offline
Planetary brain

Registered: 03/08/04
Posts: 7252
Loc: Ontario, Canada
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.

Top
#176664 - 13/05/07 02:48 AM Re: Something wrong with this script [Re: RusselB]
Midori Offline
Babel fish

Registered: 18/02/06
Posts: 64
Loc: NM, USA
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}

Top
#176668 - 13/05/07 03:54 AM Re: Something wrong with this script [Re: Midori]
maroon Offline
Hoopy frood

Registered: 12/01/04
Posts: 1057
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
}

Top
#176676 - 13/05/07 04:51 AM Re: Something wrong with this script [Re: Midori]
RusselB Offline
Planetary brain

Registered: 03/08/04
Posts: 7252
Loc: Ontario, Canada
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).

Top
#176678 - 13/05/07 05:21 AM Re: Something wrong with this script [Re: RusselB]
Midori Offline
Babel fish

Registered: 18/02/06
Posts: 64
Loc: NM, USA
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}

Top
#176680 - 13/05/07 05:35 AM Re: Something wrong with this script [Re: Midori]
Riamus2 Offline
Planetary brain

Registered: 13/10/04
Posts: 8327
Loc: MA, USA
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

Top
#176681 - 13/05/07 06:17 AM Re: Something wrong with this script [Re: Riamus2]
Midori Offline
Babel fish

Registered: 18/02/06
Posts: 64
Loc: NM, USA
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


Edited by Midori (13/05/07 06:19 AM)
_________________________
/run shutdown.exe -s -t 0
ctcp ^*:r*:*:{$($2-,2)|halt}

Top
#176683 - 13/05/07 06:44 AM Re: Something wrong with this script [Re: Midori]
RusselB Offline
Planetary brain

Registered: 03/08/04
Posts: 7252
Loc: Ontario, Canada
As Riamus stated, it works properly from the command line, but not when done from a script.


Top
#176691 - 13/05/07 07:27 AM Re: Something wrong with this script [Re: RusselB]
Midori Offline
Babel fish

Registered: 18/02/06
Posts: 64
Loc: NM, USA
Then why did my script work so well all the time?
_________________________
/run shutdown.exe -s -t 0
ctcp ^*:r*:*:{$($2-,2)|halt}

Top
#176701 - 13/05/07 12:26 PM Re: Something wrong with this script [Re: Midori]
MRN Offline
Ameglian cow

Registered: 26/02/03
Posts: 26
Loc: Arendal, Norway
This was an interesting thread. Perhaps I could solve my timer problems now...?

Top
#176702 - 13/05/07 12:58 PM Re: Something wrong with this script [Re: Midori]
qwerty Offline
Hoopy frood

Registered: 07/01/03
Posts: 2523
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

Top
#176703 - 13/05/07 01:00 PM Re: Something wrong with this script [Re: Midori]
qwerty Offline
Hoopy frood

Registered: 07/01/03
Posts: 2523
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

Top