|
Joined: Jul 2006
Posts: 4,187
Hoopy frood
|
OP
Hoopy frood
Joined: Jul 2006
Posts: 4,187 |
/set can do math operations natively with two operands and one operator (math and bitwise logic.) That's faster and handy, I'd like to suggest a switch for /set so that the full line is a $calc parameter.
set -sc %a 2+3 -5 * 8,%b a + b,%c,%d % $+ a,%e %d + 1
* set %a to -35 * set %b to 0 * set %c to * set %d to -35 * set %e to 0
The assignment is not to be evaluated twice with the math occuring after, %e should be trying to $calc the plaintext "%a" string resulting in 0, %e shouldn't result in -34
#mircscripting @ irc.swiftirc.net == the best mIRC help channel
|
|
|
|
Joined: Jan 2012
Posts: 329
Pan-dimensional mouse
|
Pan-dimensional mouse
Joined: Jan 2012
Posts: 329 |
It is possible to replace the built-in command with your own version of the functionality through aliases. Try to use this code. To check enter the command " /set_calc":
alias set_calc {
set -s %a 2+3 -5 * 8
set -s %b a + b
set -s %c
set -s %d % $+ a
set -s %e %d + 1
;--------------------------
echo -s $eval(%a,0) =40 %a
echo -s $eval(%b,0) =40 %b
echo -s $eval(%c,0) =40 %c
echo -s $eval(%d,0) =40 %d
echo -s $eval(%e,0) =40 %e
}
alias -l set {
if (- == $left($1,1) && s isin $1) {
if ($3) var %value $calc($3-) | else var %value $null
echo $color(info) -a * Set $2 to %value | set $2 %value
}
else set $1 $calc($2-)
}
With this method of assigning variables (line by line), the variable " %e" will be equal to " -34", but this can certainly be fixed :-]You can also try to implement this method so that it accepts all variable values in one line, separated by commas.
|
|
|
|
Joined: Jan 2012
Posts: 329
Pan-dimensional mouse
|
Pan-dimensional mouse
Joined: Jan 2012
Posts: 329 |
- :: Update and correction to previous post :: - mIRC allows to remap built-in commands via aliases, so you can try to change or add yourself own functionality for to this command and completely replace its action. Thus, you can independently implement many new, interesting and additional functions you need. I think this may be enough to experiment in this direction. I tried to make my code according to your idea and this is what I got. Test command: //set -sc %a 2 + 3 -5 * 8,%b a + b,%c,%d % $+ a,%e %d + 1
alias set {
if (- == $left($1,1)) {
if ($len($1) > 1) {
if (c isin $1) {
var %i 1 | while (%i <= $numtok($2-,44)) {
var %t $gettok($2-,%i,44), %v $gettok(%t,1,32), %m $gettok(%t,2-,32)
if (%m != $null) var %m $calc(%m) | else var %m $null
if (s !isin $1) set $eval(%v,1) %m | inc %i
}
}
if (s isin $1) {
var %i 1 | while (%i <= $numtok($2-,44)) {
var %t $gettok($2-,%i,44), %v $gettok(%t,1,32), %m $gettok(%t,2-,32)
if (c isin $1) { if (%m != $null) var %m $calc(%m) | else var %m $null }
set -s $eval(%v,1) %m | inc %i
}
}
}
else echo $color(info) -a * ERROR: required letter for switches are missing.
}
else { var %i 1 | while (%i <= $numtok($1-,44)) { set $eval($gettok($1,%i,44),1) $gettok($2-,%i,44) | inc %i } }
}
This is a demo exemple of the method to show how it can be done and of course it can be improved. I think you can handle this on your own. Warning: If you decide to do this, then you should know that changing the functionality of built-in commands and identifiers at the global level can negatively affect the work of all scripts that also use these commands and identifiers, and lead to unpredictable behavior of your client. Therefore, this should be done with extreme caution, at your own peril and risk, and it is advisable to use only at the local level in the individual scripts you need. For example: " alias -l set { ... }".
|
|
|
|
Joined: Jul 2006
Posts: 4,187
Hoopy frood
|
OP
Hoopy frood
Joined: Jul 2006
Posts: 4,187 |
Thanks, but there are many reasons why it's a terrible idea for me or someone else to script this. Your alias is not doing what I want if %e is -34, the reason why is related to why it's a terrible idea, and no you cannot fix it as that you require you to parse and support $calc's format entirely, i don't want each assignment to take 200ms!
#mircscripting @ irc.swiftirc.net == the best mIRC help channel
|
|
|
|
Joined: Jul 2006
Posts: 4,187
Hoopy frood
|
OP
Hoopy frood
Joined: Jul 2006
Posts: 4,187 |
My point of view didn't change, but in my original post, there's two unfortunate typos, %d is not set to -35, it is set to plain text "%a", and i meant to use /var, although the underlying command is /set, I'm not suggesting for /set to support multiple assignments.
#mircscripting @ irc.swiftirc.net == the best mIRC help channel
|
|
|
|
|