mIRC Home    About    Download    Register    News    Help

Print Thread
/timer non-evaluation switch #125914 23/07/05 10:44 AM
Joined: Apr 2004
Posts: 846
Sat Offline OP
Hoopy frood
OP Offline
Hoopy frood
Joined: Apr 2004
Posts: 846
I believe it would be great if /timer had a switch that would cause its command not to be evaluated upon execution, so that scripts can pass arbitrary text with the command (for example a message line from IRC), without having to worry about escaping identifiers/variables/etcetera.

For example, from the commandline,

Code:
/timer -n 1 1 echo $pi

would echo "$pi" rather than "3.14..."

I'm aware of the workarounds, but those are all awfully inconvenient.


Saturn, QuakeNet staff
Re: /timer non-evaluation switch #125915 23/07/05 11:22 AM
Joined: Sep 2003
Posts: 4,230
D
DaveC Offline
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
Im going to assume you mean $ip since you said "3.14..." and also assume you ment within scripts rather than on the prompt where using one / well produce $ip as the output.
that being said.

Even with that switch it would not display "$ip" becuase assuming -n didnt evaluate while creating the timer, the echo would evaluate $ip when its ran.
To get what you said u would need with your switch //timer -n 1 1 echo $!ip
As it stands now that would need to be //timer 1 1 echo $!!ip

Now if you wanted it to work like this
at 12:00:00 this is entered //timer 1 10 echo the time is $time
at 12:00:10 this is displayed "the time is 12:00:10"
and not what it DOES DO "the time is 12:00:00"

then you can use this
//timer 1 1 $(echo the time is $time,0)

just surround the code with $( ,0), simple you get the $( ,0) evaluated as the contents unchanged!

even this works fine
//timer 1 1 $(if ($get(0) < 2) { echo -a Less than two gets! },0)

Re: /timer non-evaluation switch #125916 23/07/05 11:23 AM
Joined: Apr 2004
Posts: 846
Sat Offline OP
Hoopy frood
OP Offline
Hoopy frood
Joined: Apr 2004
Posts: 846
First of all, $pi returns Pi. Try it.

Also, try the /timer command as I typed it, and see how it does not echo "$pi". I guess you know that lines from the commandline don't get evaluated immediately when you don't specify two slashes, but that doesn't keep /timer from evaluating it when it executes.

As for your main point, $eval does not work for this, because for example the text ",2)" may be part of the input. So that is not even a usable workaround.

Here's another (silly) example that will hopefully get my point across. Consider this remote event, which is supposed to annoy people by sending back their text after five seconds.

Code:
on *:TEXT:*:#:{ .timer 1 5 msg $chan $1- }

Now try making this not evaluate the message in $1- when the timer executes.

Last edited by Sat; 23/07/05 11:44 AM.
Re: /timer non-evaluation switch #125917 23/07/05 11:48 AM
Joined: Feb 2004
Posts: 2,019
FiberOPtics Offline
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
I've suggested this before here


Gone.
Re: /timer non-evaluation switch #125918 23/07/05 11:52 AM
Joined: Apr 2004
Posts: 846
Sat Offline OP
Hoopy frood
OP Offline
Hoopy frood
Joined: Apr 2004
Posts: 846
Ah, okay! That's strange actually, because I did search for some of the words in your post within the correct timeframe. I guess I simply overlooked it then, sorry.. frown


Saturn, QuakeNet staff
Re: /timer non-evaluation switch #125919 23/07/05 12:54 PM
Joined: Sep 2003
Posts: 4,230
D
DaveC Offline
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
Oh man i didnt read to carefully sorry.

My error about the $pi, but regardless the same effect.

The command line stuff was where my reading let me down again sorry.

And even as u pointed out there might be a ,2 in the code, but sibnce you must hardcode it, it wouldnt be a high occrance.

The idea of a -n switch on a timer would be far more valuable if it caused the timer to NOT evaluate anything at the timer creation time.
The -n switch you would want would be better attached to a /echo (using anther letter tho as n's taken) maybe -p for plain text
(from the commandline) /timer 1 1 echo -p Pi's value is $pi


Quote:
Code:
on *:TEXT:*:#:{ .timer 1 5 msg $chan $1- }


lol

on *:text:*:#:{ timer 1 5 msg $chan  $+ $replace($1-,$chr(32),$+($chr(32),)) }
;^ just puts double bold after any space disabling any evaluation (not good on channels banning color etc, evn tho u dont see it)

on *:text:*:#:{ timer 1 5 msg $chan $chr(160) $+ $replace($1-,$chr(32),$chr(160)) }
;^ just change space to $chr(160) a bit crude but acceptable in a pinch


blah you say the out put is changed!

Fair enough...
So lets take control of the value and store it, its the only way to be sure of not doing something ugly.

on *:text:*:#:{ var %v = $+(%,temp.,$ticks,.,$mid($rand(1000000,1999999),2)) | set -u10 $(%v,1) $1- | timer 1 5 msg $chan %v }
;^ always the exact output, the varable self erases after 10 seconds

UGLY! i hear you say!

Well i agree!

try this....

on *:text:*:#:{ timer 1 5 msg $chan $>($1-) }
;This is pretty clean a $>( ) surrounding the text
;
;
alias > { var %itemname = $+($ticks,.,$mid($rand(1000000,1999999),2)) | hadd -m hash.table.for.>.and.< %itemname $1 | return $!<( $+ %itemname $+ ) }
alias < { var %itemvalue = $hget(hash.table.for.>.and.<,$1) | hdel hash.table.for.>.and.< $1 | return %itemvalue }

Re: /timer non-evaluation switch #125920 23/07/05 01:59 PM
Joined: Apr 2004
Posts: 846
Sat Offline OP
Hoopy frood
OP Offline
Hoopy frood
Joined: Apr 2004
Posts: 846
Indeed, I also came to the conclusion that hashtables are the cleanest way of working around the problem - still, I'd rather have a proper solution in /timer itself..


Saturn, QuakeNet staff
Re: /timer non-evaluation switch #125921 24/07/05 10:06 AM
Joined: Jan 2003
Posts: 2,523
Q
qwerty Offline
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
I believe your suggestion is a bit different from Sat's. If I understood you correctly, you want the -n switch to prevent evaluation inside the calling script: this would be the only way for something like
timer -n 1 10 if $me == FiberOPtics { echo -a $true } | else { echo -a $false }
to work.

Sat is talking about preventing evaluation in /timer's environment, ie when /timer fires. I know I'd like both features. I'd like the -n switch to work the way Sat described and another option (perhaps something like a directive "#noeval on/off" that could be put anywhere in a script) that would do what you suggested.


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
Re: /timer non-evaluation switch #125922 24/07/05 05:52 PM
Joined: Feb 2004
Posts: 2,019
FiberOPtics Offline
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
Indeed, I glanced over the feature suggestion too fast (was on a weekend trip and had access to a comp for a few mins, teehee smile)

I would also like to see both suggestions added.


Gone.
Re: /timer non-evaluation switch #125923 25/07/05 04:00 AM
Joined: Oct 2003
Posts: 3,918
A
argv0 Offline
Hoopy frood
Offline
Hoopy frood
A
Joined: Oct 2003
Posts: 3,918
i'd prefer the -switch than the 'directive'. mIRC doesn't have any directives.. and that C style syntax will definitely fudge up groups.


- argv[0] on EFnet #mIRC
- "Life is a pointer to an integer without a cast"
Re: /timer non-evaluation switch #125924 25/07/05 07:38 AM
Joined: Jan 2003
Posts: 2,523
Q
qwerty Offline
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
What switch? The /timer -n switch would be used for Sat's idea, but for FiberOptics' suggestion there has to be a new command or something. I guess there could be a command that works like /scon N (that switches to the Nth connection until a /scon -r). However I don't see a problem with a directive, since #groups are always on the top level (outside enclosing everything), while the directive would have to be inside an event or alias. I guess that makes it less of a standard 'directive' but oh well.

Now that I think about it, there can also be a command prefix. I like either way, but a prefix is perhaps more mirc-style.

Last edited by qwerty; 25/07/05 07:43 AM.

/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
Re: /timer non-evaluation switch #125925 25/07/05 06:25 PM
Joined: Dec 2002
Posts: 2,962
S
starbucks_mafia Offline
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
If you mean the non-evaluation during parsing should be a switch then I disagree. It would be very clumsy since, unlike with identifiers, commands' parameters are determined after evaluation of the line. So a call to timer currently could exist as /timer -h $moo $blah $somethingelse. Now if the non-evaluation of the <command> parameter of mIRC were implemented then how would mIRC know what it should or should not identify? $moo could evaluate to a single number and so could $blah, meaning $somethingelse shouldn't be evaluated, or $blah could evaluate to two numbers meaning both $blah and $somethingelse should remain as-is. Hundreds of other variations are possible and there's simply no good way for mIRC to know how to behave.

In other words, for commands to have parameters that remain unevaluated it needs to apply to the whole of the line. Which means it should be something like a directive or a command prefix as qwerty said.


Spelling mistakes, grammatical errors, and stupid comments are intentional.
Re: /timer non-evaluation switch #125926 25/07/05 06:47 PM
Joined: Oct 2003
Posts: 3,918
A
argv0 Offline
Hoopy frood
Offline
Hoopy frood
A
Joined: Oct 2003
Posts: 3,918
That why the switch would be an option cool

No one ever said it would be useful or even helpful in every situation. But there will be those other situations where its a lot _less_ clumsy to use it.

If you need to evaluate commands as parameters, well then the no eval switch would just not be for you, simple.


- argv[0] on EFnet #mIRC
- "Life is a pointer to an integer without a cast"
Re: /timer non-evaluation switch #125927 25/07/05 10:27 PM
Joined: Dec 2002
Posts: 2,962
S
starbucks_mafia Offline
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
So you'd want the switch but still choose to have it not evaluate any of the line at all? What if the first parameter evaluates to the non-evaluation switch, does it not evaluate anything more of the line? It seems a very kludgey way of doing things.


Spelling mistakes, grammatical errors, and stupid comments are intentional.
Re: /timer non-evaluation switch #125928 25/07/05 10:57 PM
Joined: Sep 2003
Posts: 4,230
D
DaveC Offline
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
Well i would look at it like this

It gets to the command /TIMERname and so now checks whats following it, it should be (1) switches (2) time (3) a number (4) something that needs to be evaluated into 1 2 or 3.
If it needs evaluating then do so and check for 1 2 or 3
If theres a switch -n, then i knows that once its got everything it needs for the timer, just stop evaluating anything else.
ex:
var %switches = -on, %runtime = 12:00, %delay = 0
timer $+ $nick %switches %runtime 1 %delay echo The time is $time

timer $+ $nick becomes timerDaveC
evaluates %switches as -on
see the -n and knows to stop evaluating when it has enough details for the timer
evaluates %runtime as 12:00
sees 1
evaluates %delay as 0
so it now has "TIMEDaveC -on 12:00 1 0" and goes well thats all i need to evaluate so the command is "echo the time is $time"

* I must admit i have no idea if thats how mirc processes lines, but since it seems to be able to know if to evaluate something or not, i must assume that it processes lines as it goes down them.
ie: set %x 12 vs echo %x 12. It doesnt just evaluate everything then pass that lot to a function called SET or ECHO as it must know that SET doesnt want %x evaluated.

Re: /timer non-evaluation switch #125929 26/07/05 01:14 AM
Joined: Dec 2002
Posts: 208
H
Hrung Offline
Fjord artisan
Offline
Fjord artisan
H
Joined: Dec 2002
Posts: 208
I think you guys are talking at cross purposes. For the kind of non-evaluation that starbucks et al. are talking about, a simple $(,0) is all you need.. sat's suggestion, and I believe arg's points as well, is for a switch to let the line evaluate when /timer is used, but when the time runs out, and the timer fires, don't evaluate the text.. say, just as if it were entered at the command line without the double slashes. This would allow things like using $1- on a timer in an on text event without having to worry about what happens if someone says a $($decode(),2) line. Sounds like a great idea to me. I also think such a switch should be added to /scid and /scon so that various scripts for doing things such as relaying text from one chan/network to another is risk free without writing needlessly complex code. It's not dissimilar to the n switch to $read, so maybe making it -n is suitable.


If I knew now what I will know then... maybe things will have been different...
Re: /timer non-evaluation switch #125930 26/07/05 02:41 AM
Joined: Jan 2003
Posts: 2,523
Q
qwerty Offline
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
Quote:
a simple $(,0) is all you need


Not exactly. } and | characters cannot be surrounded by spaces, commas cannot be used (unless inside brackets) and there are probably other issues with $(,0) that I can't remember:

//echo -a $(one | two,0)
//echo -a $(a { b } c,0)

A more real-world example is given in FiberOptics' thread.

Of course you can escape }, | and get around the problem with commas but that's exactly what FiberOptics' suggestion is about: not having to escape anything, just like the good old single slash in editbox.


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
Re: /timer non-evaluation switch #125931 26/07/05 11:11 AM
Joined: Sep 2003
Posts: 4,230
D
DaveC Offline
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
So is what where really after is a $donteval( ), like $( ,0) but one that takes what ever is inside it and somehow "marks it" for non evaluation

ex
var %blah = $!time $!+ $!date
timer 1 5 echo $donteval(%blah)
;^ now at this point %blah is evaluated but the content of it, becomes unevaluatable so you end up with...

timer 1 5 echo *$time $+ $date*

And that actually displays $time $+ $date, the * being some type of marker that tells mirc to simple not evaluate anything between it.

Oh well i guess thats a directive isnt it.