mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Apr 2010
Posts: 30
M
Ameglian cow
OP Offline
Ameglian cow
M
Joined: Apr 2010
Posts: 30
Is there any way to prevent /var's implicit calculation feature when doing assignments?

I am using an alias similar to this:

alias test {
var %x = $1-
echo -a %x
}

and i need $1- to be saved as plain text in %x without ANY modification.

Calls like
test 10 - 5
test 10 / 5
however result in being implicitly evaluated as calculation resulting in "5" or "2" being saved in %x.

I haven't found a way to disable that.
even ugly workarounds like
var %x = $eval($1-,1)
var %x = $1 $2-
...

don't seem to do the trick.

Last edited by m0viefreak; 18/11/10 05:31 PM.
Joined: Feb 2006
Posts: 546
J
Fjord artisan
Offline
Fjord artisan
J
Joined: Feb 2006
Posts: 546
you could use the fact that /set looks for local variables before affecting global ones:

Code:
  var %x
  set -n %x $1-


or you can use /set's undocumented -l switch which /var uses implicitly to handle local variables:

Code:
  set -ln %x $1-


"The only excuse for making a useless script is that one admires it intensely" - Oscar Wilde
Joined: Jul 2007
Posts: 1,129
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
You should have done it as such:
Code:
alias test {
  var %x = $!1-
  echo -a [ [ %x ] ]
}


Joined: Apr 2010
Posts: 30
M
Ameglian cow
OP Offline
Ameglian cow
M
Joined: Apr 2010
Posts: 30
Originally Posted By: Tomao
You should have done it as such:
Code:
alias test {
  var %x = $!1-
  echo -a [ [ %x ] ]
}


That's not an option. The script is much more complicated than that. I'm doing a lot more with %x than just echoing it, and using [ [ ] ] every time would be quite annoying (let alone the fact that $1 changes on /tokenize).

The set -ln method looks a lot better, however I also need to change EVERY assignment like
%a = %b
where %b might auto evalulate using calculation to
set %a %b

This is gonna be a lot of work (and isn't very straight forward coding either).

I was hoping for some global directive to prevent this (in my opinion useless) auto-calculation in general.

Last edited by m0viefreak; 18/11/10 09:01 PM.
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
One possibility is to change something in $1- before doing anything else to it and then change it back when you're ready to view/use the data. For example, putting a character that won't be seen by the script, such as ~ in front of $1- in the variable and then ignoring that when displaying the information. It may not be fancy or "clean", but it works. Of course, you're still likely to need to make changes elsewhere to handle the extra character that you want to ignore.

In the end, switching to /set is probably the easiest and quickest thing to implement.


Invision Support
#Invision on irc.irchighway.net

Link Copied to Clipboard