mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Jul 2006
Posts: 4,149
W
Wims Offline OP
Hoopy frood
OP Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,149
Today I figured there was actually an issue when handling local %variables in a timer.

When a timer fires, the local variables that existed in the scope when the /timer was called are long gone and don't exist anymore, so in order to prevent double evaluation, $unsafe must be used so that the content of the variables is seen when /timer is seen, not when it fires.

if (%localvar != $null) { command }
vs
.timer -ho 1 0 if ( $unsafe(%localvar) ) command

this works when the variable has a content, but when it's $null, you get /if invalid format, because all the timer sees if ( ) command.

This is a bit annoying, not going to lie!

If the parameter passed to $unsafe() is $null, would it be possible to still return a plain text $unsafe().undo so that a future evaluation would turn that into $null, allowing timers to correcly handle these situations, there's many more if condition formats that fail depending on where $unsafe() is used.

I'm well aware of the idea of using an alias and doing the job in an alias but that's not the point here.


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Jan 2004
Posts: 2,127
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2004
Posts: 2,127
//var -s %a $unsafe(a)
* Set %a to $unsafe(YQ==).undo

//var -s %a $unsafe(%null)
* Set %a to

It looks like $unsafe is an alias that behaves like

Code
alias makesafe {
  if (.prop == undo) returnex $decode($1,m)
  var %string $encode($1,m)
  return $ $+ makesafe( $+ %string $+ ).undo
}

The handler for .undo obviously has no trouble when the input string is blank, but if there is a problem inside the code where it doesn't like creating the .undo string to be blank, assuming .undo is being handed to the subroutine handling $decode, can simply make the string be a single base64 symbol, which $decode would return as the empty string. So the final return could be preceded by:

Code
  if (%string == $null) var %string A

So the solution is to have $unsafe($null) return either $unsafe().undo or $unsafe(A).undo


Link Copied to Clipboard