mIRC Home    About    Download    Register    News    Help

Print Thread
#9309 02/02/03 02:51 AM
Joined: Dec 2002
Posts: 111
F
Frog Offline OP
Vogon poet
OP Offline
Vogon poet
F
Joined: Dec 2002
Posts: 111
alias fc .timer $$1 0 say $!+(,$rand(1,15),$$2-) <-------- doesnt work, even though it does if I type it.


Experience The Void.. Are You Ready?
#9310 02/02/03 03:18 AM
Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
That's not a bug. You're just not letting $$2- evaluate in the script: remember that from the moment you used the ! in $+(), it is not considered an identifier anymore, so $$2- is not considered a parameter. So it won't be evaluated in the script if it touches other elements. And it can't be evaluated inside the /timer (ie each time it triggers) because $1, $2 etc have no meaning in /timers. You could try this:
Code:
alias fc .timer $$1 0 say $!+(,$rand(1,15), $$2- )
Notice the spaces around $$2-.

BUT, this solution is not very good either: depending on what $$2- contains, unexpected things could happen. For example, if $$2- contains a comma "," this will be considered a parameter separator for $+() each time the timer triggers. Probably the best solution would be to set a global variable with $$2- and let th /timer call it:
Code:
alias fc set %fc $$2- | .timer $1 0 say $!+(,$rand(1,15),%fc)


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
#9311 02/02/03 08:54 AM
Joined: Dec 2002
Posts: 1,321
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Dec 2002
Posts: 1,321
A far better solution is to put any and all commands you want performed into an alias that the timer can call, perhaps with parameters specified in the command section of the timer.


DALnet: #HelpDesk and #m[color:#FF0000]IR[color:#EEEE00]C
#9312 02/02/03 01:01 PM
Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
Using an alias with parameters instead of direct code in a /timer makes things simpler and safer. It usually works, but in this case, if unknown parameters are passed to that alias, it gets tricky and could even be dangerous. As I explained in my previous post you should NOT pass $$2- as a parameter to an alias called by /timer. The reason is that $2- is to be evaluated twice. During that second evaluation, unexpected things can happen.

I'll give an example to make it clear. We make a simple alias that does the job and we use that in the /timer, passing it $2- as parameters:
Code:
alias fc .timer $1 0 fc2 $$2-
alias fc2 say $+($chr(3),$base($rand(1,15),10,10,2),$1-)

Everything looks fine, right? If the user typed
Code:
/fc Hey guys, use this to delete a file: //echo -a About to delete file.txt | remove file.txt
he can be sure that there's no problem with what he typed because he used a single slash, so mirc code won't be evaluated and he can /say to his friends whatever he wants. No! Each time fc2 is executed by the timer, the parameters passed to it ($2-) will be evaluated once more, which would end up in /remove deleting file.txt. That's why I used the global variable: so we don't have to pass unknown content to an alias called by a /timer.

I still think that having a single alias in a /timer is usually the "best" solution, as long as we're cautious with the parameters. An example that would be safe is this:
Code:
alias fc set [color:green]%fc[/color] $$2- | .timer $1 0 fc2
alias fc2 say $+($chr(3),$base($rand(1,15),10,10,2),[color:green]%fc[/color])


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

Link Copied to Clipboard