|
Joined: Oct 2005
Posts: 122
Vogon poet
|
OP
Vogon poet
Joined: Oct 2005
Posts: 122 |
This is part of a larger script ive made, i keep getting an if error every 30 secs when the timer goes off, and i cant tell why
alias autoidleaway {
var %z = $$input(Idle How Long Before Going Away (Format is Xm,Xh (m = min, h=hours)),ev,Auto Idle After How Long?)
if ($input(Auto Change Nicks To AFK And Back?,y,Auto Change Nicks) == $true) { set %AutoChangeNicks on }
else { set %AutoChangenicks off }
if (m isin %z) {
.timerawayloggeridle 0 30 if ($idle >= $calc(60 * $remove(%z,m)) { afk2 |.timerawayloggeridle off }
}
elseif (h isin %z) { .timerawayloggeridle 0 30 if ($idle >= $calc(3600 * $remove(%z,h)) { afk2 | .timerawayloggeridle off } }
}
|
|
|
|
Joined: Apr 2004
Posts: 759
Hoopy frood
|
Hoopy frood
Joined: Apr 2004
Posts: 759 |
if ($idle >= $calc(60 * $remove(%z,m)) )
$maybe
|
|
|
|
Joined: Oct 2005
Posts: 122
Vogon poet
|
OP
Vogon poet
Joined: Oct 2005
Posts: 122 |
blah ty lol, knew it wuz sumtin simple
|
|
|
|
Joined: Mar 2004
Posts: 21
Ameglian cow
|
Ameglian cow
Joined: Mar 2004
Posts: 21 |
The problem is here: (and in the other /timer command)
.timerawayloggeridle 0 30 if ($idle >= $calc(3600 * $remove(%z,h)) { afk2 | .timerawayloggeridle off }
Three reasons: - You forgot a parenthesis in the condition. - When you launch a timer, $idents & %variables which are 'affixed' with parenthesis in conditions or $ident() are not right away evaluated. They'll just be evaluated when the timer performs the command (passed in parameters), after the delay specified (here 30 seconds). Knowing that, you can now see your variable %z, created via /var, will not exist 30 seconds later. - In timers, you can not right away use "{ } |" caracters, because mIRC evaluates them. So, you can try one of these two solutions: 1°) $(<value>,) allows not to evaluate the value. And with spaces in the condition, $ident and %variable are evaluated when you launch the timer, so not after the delay.
.timerawayloggeridle 0 30 if ($idle >= $calc(3600 * $remove( %z ,h)) ) $({,) afk2 $(|,) .timerawayloggeridle off $(},)
2°) You put yours commands in an alias, like CheckIdle here, with %z as parameters, because it's the only %variable which has to be right away evaluated.
.timerawayloggeridle 0 30 CheckIdle %z
; You create a new alias :
alias CheckIdle {
if ($idle >= $calc(3600 * $remove($1,h))) { afk2 | .timerawayloggeridle off }
}
I hope that will work. If it's not the case, consider it like an idea on the good way
-Be cool with my English- irc.EpiKnet.org:#scripts
|
|
|
|
Joined: Apr 2004
Posts: 759
Hoopy frood
|
Hoopy frood
Joined: Apr 2004
Posts: 759 |
thats quite unneccessary you only have to escape the | , also the %z is evaluated twice. Once when you send it to the timer and once when the timer is executed. try this:
alias test {
var %x = $!me
/timer 0 10 if ($me == $me) { echo -a %x $(|,) echo -a yay! }
}
cleanest thing to do is put the timeroff declaration in the afk2 alias.
$maybe
|
|
|
|
Joined: Feb 2004
Posts: 2,019
Hoopy frood
|
Hoopy frood
Joined: Feb 2004
Posts: 2,019 |
There's more to escape, try your /timer line in mIRC with immediately issuing a /timers after it. Will look something like this: * Timer 1 10s delay if ($me == echo -a | echo -a yay! (DALnet) $me) evaluated to $null ... and the { } are gone. People can find a little in depth information about how/what should be escaped when passing params to a timer here Although the best advice is always: create an alias, and call that alias instead. No worries of double evaluating and takes no effort. EDIT: Note to people wondering: obviously you need to execute the timer command from the command line with double slashes // to reproduce what it would do in a script.
Gone.
|
|
|
|
Joined: Apr 2004
Posts: 759
Hoopy frood
|
Hoopy frood
Joined: Apr 2004
Posts: 759 |
I was using if ($me == Mpdreamz) in the editor gives me: * Active timers: * Timer 1 10s delay if ($me == Mpdreamz) echo -a $me | echo -a yay2 (TwistedEggs) * Timer 2 10s delay if ($me == Mpdreamz) echo -a $me | echo -a yay2 (TwistedEggs)
if ($me == $me) doesnt evaluate indeed, i stand corrected.
$maybe
|
|
|
|
Joined: Feb 2004
Posts: 2,019
Hoopy frood
|
Hoopy frood
Joined: Feb 2004
Posts: 2,019 |
Even with using a hardcoded name it still doesnt give you the required result because those braces {} are gone.
Compare:
//timer 1 0 if (5 == 6) { echo -a inside braces $(|,) echo -a still inside braces }
--> it echoes "still inside braces" whilst it shouldn't as 5 != 6
with
//timer 1 0 if (5 == 6) $({,) echo -a inside braces $(|,) echo -a still inside braces $(},)
--> works correctly
To anyone reading these posts: do not put code in a timer but in an alias, unless you are experienced enough to know all of its possible pitfalls and associated dangers.
Gone.
|
|
|
|
Joined: Apr 2004
Posts: 759
Hoopy frood
|
Hoopy frood
Joined: Apr 2004
Posts: 759 |
Never gonna get that wrong again, my appologies to CoolWave
$maybe
|
|
|
|
Joined: Mar 2004
Posts: 21
Ameglian cow
|
Ameglian cow
Joined: Mar 2004
Posts: 21 |
-Be cool with my English- irc.EpiKnet.org:#scripts
|
|
|
|
Joined: Feb 2004
Posts: 2,019
Hoopy frood
|
Hoopy frood
Joined: Feb 2004
Posts: 2,019 |
Btw in case you're interested, regarding this evaluation behaviour of parameters passed to a timer there is something quite interesting:
if you have a set/unset command in the timer, then the variable following it will not be evaluated (it will be with /var though) so if you do decide to pass something to a timer, then the variable that you want to set doesn't need escaping when used with set/unset.
Observe:
//.timer 1 1 set -l %a 5 $(|) set %a bla $(|) unset %a 7 $(|) var %a = lol | timers
The message displayed by the /timers command shows that all %a's did not get evaluated except for the one that was set with the /var command.
It doesnt even need to even be an actual command, as long as there is the string "set or unset" followed by optional flags and a variable, then the variable will not evaluate when the timer is set.
//.timer 1 1 echo -a hmm set %a how weird | timers
As you can also see, the pipe | doesn't necessarily need to be escaped with the level 0 of eval, just having it not be surrounded by a space is sufficient for it not to evaluate to a pipe. This doesn't work for other characters and even produces flaky results, try: //echo -a $({) VS $(}). Therefore, as a rule of thumb, I always use the universal way to escape a character being $eval(<char>,0) or shorter $(<char>,)
Additionally, instead of escaping characters with using $eval of level 0, you can of course also use their ascii representation like $chr(124) is a pipe.
Note that this behaviour of set/unset is only with /timer, not with scon/scid where double evaluation also occurs.
//scon -r set %a 7 --> will give: * /set: invalid parameters, because it evaluated the %a making the command "set -s 7" (assuming you didn't have a global variable %a in your variables list of course)
This wasn't directed at you, it's for anyone who cares.
Gone.
|
|
|
|
Joined: Mar 2004
Posts: 21
Ameglian cow
|
Ameglian cow
Joined: Mar 2004
Posts: 21 |
Already noted for /set global, and /var only as command, but for /set -l it's very interessant (never thought of that) Strange that doesn't work with /scid... However, in a string it's very less interessant For the pipe without level 0 of eval, i use it recently , but not sure of the result here (not tested the code before posting) Thanks for this complement, useful !
-Be cool with my English- irc.EpiKnet.org:#scripts
|
|
|
|
Joined: Apr 2004
Posts: 759
Hoopy frood
|
Hoopy frood
Joined: Apr 2004
Posts: 759 |
Odd behaviour to say the least
$maybe
|
|
|
|
Joined: Sep 2003
Posts: 4,230
Hoopy frood
|
Hoopy frood
Joined: Sep 2003
Posts: 4,230 |
you spend wholey to much time using mirc. <grin>
|
|
|
|
Joined: Feb 2004
Posts: 2,019
Hoopy frood
|
Hoopy frood
Joined: Feb 2004
Posts: 2,019 |
Hehe, so do you :tongue:
I've been spending a lot more time in front of MSVC++ lately though, a nice break from mIRC.
Gone.
|
|
|
|
|