|
Joined: Jun 2009
Posts: 6
Nutrimatic drinks dispenser
|
OP
Nutrimatic drinks dispenser
Joined: Jun 2009
Posts: 6 |
i was helping someone with a script today, that should have worked, but didn't. i couldn't really see anything wrong so i started testing, and i got a strange result.
//var %qn = 4 / 6 / | /var %qn = $deltok(%qn,-1,32) | /echo -s %qn returns 0.666667
//var %qn = 4 / 6 / | /var %qn = $left(%qn,$calc($len(%qn)-1)) | /echo -s %qn returns 0.666667
//var %qn = 4 + 6 + | /var %qn = $left(%qn,$calc($len(%qn)-1)) | /echo -s %qn
returns 10.... if you make it 4 & 6 & (witch is what started this, he tried to add results to a output string, like "found more results in quote 3 & 4 & 5...") it just returns 4..
and so on... any operator it just ($calcs) them..
and it only happens when theres 2 numbers.. if i did 4 + 6 + 6 + it would return "4 + 6 + 6"
it happens on xp, win7, on mirc 6.21 and 6.35.. so i assume its some sort of script engine bug..
|
|
|
|
Joined: Jul 2006
Posts: 4,145
Hoopy frood
|
Hoopy frood
Joined: Jul 2006
Posts: 4,145 |
Look at /help Variables, this is an intended behavior, not a bug. You can make single operation when you assign a value to a variable. In your exemple, you're deleting the last character (the '/'), the string become a single operation.
#mircscripting @ irc.swiftirc.net == the best mIRC help channel
|
|
|
|
Joined: Jun 2009
Posts: 6
Nutrimatic drinks dispenser
|
OP
Nutrimatic drinks dispenser
Joined: Jun 2009
Posts: 6 |
oh well, i just found it really odd, and there isnt anything in the help on variables that suggest that it would calculate what you put into a var, if theres only 2 numbers "2 & 3", but if you set the var to "2 & 3 & 4" it would show it correctly. doesnt matter if i use /var(local var) or /set either...
but yes i did find the -n switch, but imo it should be the other way around, use a switch to make it calc...
//set %qn 4 + 4 + 4 | /echo -s %qn reply "4 + 4 + 4"
//set %qn 4 + 4 | /echo -s %qn reply "8"
just seems a little inconsistent to me.. i've used mirc for 10 years and scripted most of the time, but i never knew it behaved like that..
Wouldnt it be better to have the variable be set in a constant way, unless you use a switch, instead of it silently doing something unexpected when you set it to 2 num's delimited by a operator.. anyways, sorry for wasting your time.
|
|
|
|
Joined: Jul 2006
Posts: 4,145
Hoopy frood
|
Hoopy frood
Joined: Jul 2006
Posts: 4,145 |
Wouldnt it be better to have the variable be set in a constant way, unless you use a switch, instead of it silently doing something unexpected when you set it to 2 num's delimited by a operator It just depend how you see it, the only thing you should expect about a behavior is what the help file say. and there isnt anything in the help on variables that suggest that it would calculate what you put into a var, if theres only 2 numbers "2 & 3", but if you set the var to "2 & 3 & 4" it would show it correctly. Yes, there is : You can also use the equal sign to assign values to variables:
%i = 5 %xyzi = 3.14159 %count = $1
And you can perform the following operations on variables when using the equal sign:
%x = 5 + 1 %x = 5 - %y %x = %x * 2 %x = %z / $2 %x = $1 % 3 %x = 2 ^ %w
You can only perform a single operation in an assignment at this time. The -n switch does not exists for the /var command, but you can use set -ln.
Last edited by Wims; 14/06/09 12:55 PM.
#mircscripting @ irc.swiftirc.net == the best mIRC help channel
|
|
|
|
Joined: Jun 2009
Posts: 6
Nutrimatic drinks dispenser
|
OP
Nutrimatic drinks dispenser
Joined: Jun 2009
Posts: 6 |
ok i found that in the help file, but since theres no header for the extra info, it looks like its under the /dec help item not under the variable or set item, and i didnt read it.
thanks for your time, just wanted to report something i "thought" looked funky.
Last edited by dev0; 14/06/09 01:12 PM.
|
|
|
|
Joined: Nov 2006
Posts: 1,559
Hoopy frood
|
Hoopy frood
Joined: Nov 2006
Posts: 1,559 |
Your results did surprise you, but those operations are documented in the helpfile. The mIRC Scripting Language isn't "of a piece", it evolved over time. While there are several inconsistencies in it, mainly due to this evolution, any change to the current behaviour would break countless existing scripts - and imho this scenario is worse than adapting to the existing "oddities"... Thus, reflections on a "better" (more consistent) syntax are valid but irrelevant - unless Khaled would decide to rewrite MSL from scratch. A helpfile overhaul could serve many scripters though.
|
|
|
|
|