mIRC Homepage
Posted By: Wims /var - 10/04/07 02:20 AM
In first, with this :
//var %t = GA is Ga ,%b = $len(%t) ,%a 1 | while (%a <= %b) { var -s %r = $+(%r,$mid(%t,%a,1)) | inc %a }

all the spaces of %t will be removed in %r, why ? is it a bug ?

Other thing, : why can't we set a %var ( with /var ) if the var name doesn't begin with a % like :
//Var -s $+(%,a,b) 1
is it a bug too ?
Posted By: RusselB Re: /var - 10/04/07 02:57 AM
The stripping of multiple spaces is not a bug, but intentional. There have been many posts regarding multiple spaces. mIRC also does not allow leading or following spaces. There are ways around this, most notably, using a 3rd party dll called spaces.dll

mIRC recognizes two characters for variable names, depending on the type of variable that you're wanting/needing to work with.

The most common one is the local/global variable (local variables are set using /var, global variables are set using /set). If the % character isn't present, then mIRC doesn't know that it's a variable.

I find it interesting that I can use
Code:
//set -s $+(%,a,b) 1
and it works properly, yet your example does not.

Note: If, for some reason, you must use a local variable, you can set it using the /set command and the -l switch. This method does work as a workaround for the second bug you posted.
Posted By: Om3n Re: /var - 10/04/07 04:25 AM
1. Your problem is "var -s %r = $+(%r,$mid(%t,%a,1))", when it reaches a space in the string, $mid will evalutate to a space and your command will become "var -s %r = $+(%r, )". Obviously you cant $+ a space...

2. Not sure why "var -s $+(%,a,b) 1" does not work, as it works fine when using set -s (note: square braces around it dont help)
Posted By: qwerty Re: /var - 10/04/07 09:35 AM
Quote:
1. Your problem is "var -s %r = $+(%r,$mid(%t,%a,1))", when it reaches a space in the string, $mid will evalutate to a space and your command will become "var -s %r = $+(%r, )". Obviously you cant $+ a space...

That's not it at all, try "var -s %r = $+(%r,$mid(%t,%a,1),anythinghere)" for example, you'll find it works if $mid() returns a space.

/var and /set can handle any number of consecutive or leading spaces; there only is a problem with a single trailing space. All mirc identifiers (including custom ones, if one uses the undocumented but apparently quite stable /returnex command) can also handle consecutive/leading/trailing spaces fine. Only /commands (other than /var and /set) strip leading/trailing spaces and reduce consecutive spaces to a single one. The interested reader can find lots more about the whole spaces issue in this comprehensive mIRC Internals Wiki article.

Examples:

//var %a = $str($chr(32),3) $+ a | echo -a $len(%a)
echoes "4". 3 consecutive leading spaces, followed by "a", were successfully stored in %a.

//var %a = $str($chr(32),3) | echo -a $len(%a)
echoes "3". 3 consecutive spaces where successfully stored in %a. Since nothing else follows, those are also trailing spaces.

//var %a = a $+ $str($chr(32),3) | echo -a $len(%a)
echoes "4". Similar to above.

//var %a = a $+ $str($chr(32),1) | echo -a $len(%a)
echoes "1". The space was lost in this case, because it was the last character and the character before that was not a space.
Posted By: Om3n Re: /var - 10/04/07 02:18 PM
Perhapse my wording was not specific enough, you cant $+ LITERAL spaces. Using $str and $chr is a workaround, the point was that the problem with the OP's code is that $mid evaluates to a literal space, which is infact why it is not functioning as they expected.

I am well aware of the spaces issue, and that no single trailing space (in any form) can be used in that way. Although i am sure the OP will appreciate your explanation since i failed to do so myself.

To OP: you would need to check for this case, eg..
//var %t = GA is Ga, %b = $len(%t), %a 1 | while (%a <= %b) { if ( $mid(%t,%a,1) == $chr(32) ) { var -s %r = $+(%r,$mid(%t,%a,2)) | inc %a 2 } | else { var -s %r = $+(%r,$mid(%t,%a,1)) | inc %a } }
Posted By: Sat Re: /var - 10/04/07 02:48 PM
Originally Posted By: Om3n
the point was that the problem with the OP's code is that $mid evaluates to a literal space, which is infact why it is not functioning as they expected.

If that is the case, then why does the following code work just fine?

//var %t = GA is Ga ,%b = $len(%t) ,%a 1 | while (%b >= %a) { var -s %r = $+($mid(%t,%b,1),%r) | dec %b }
Posted By: Wims Re: /var - 10/04/07 06:17 PM
Thanks for explanation but i supposed it was something like that (and so it was not a bug).I don't need any workaround, it was just exemple to show the problem.

But for the second problem, i know i can use set -l but the bug is here for me : we can't use /Var $+(%,a,b) 1 whereas we can use /set -l $+(%,a,b) 1
Posted By: RoCk Re: /var - 10/04/07 06:51 PM
I'm going to call the 2nd one a bug because no
matter what I tried, I couldn't get it to work.
Posted By: Om3n Re: /var - 10/04/07 07:11 PM
Sigh... concidering the OP's post, and the subsequent replies, i think it was established that we were talking about trailing spaces not leading spaces. I was replying to, and inreference of, the OP's specific example.
Posted By: Sat Re: /var - 10/04/07 09:55 PM
Hmm, I thought you were talking about "literal" vs "non-literal" spaces, and the ability to concatenate those, in general (instead of in the very specific /var single-trailing-space-bug context). If that's not what you meant, then I have nothing to say. smile
Posted By: Wims Re: /var - 15/04/07 04:47 AM
Just find another strange thing with /var :

//var % 1 | echo -a %a \ $var(%).value

and after :

//set % 56 | var % 1 | echo 4 -a $var(%).value | unset % | echo 6 -a $var(%).value

this would echos :
2
1

and i don't know why .
Posted By: RusselB Re: /var - 15/04/07 06:59 AM
Try using the correct format for a variable name, specifically something along the lines of %a not %
Posted By: The_JD Re: /var - 15/04/07 08:28 AM
I dont get why some things can't be /var'd but can be /set'd


I think i had the problem with using things like $left & $right
Posted By: RusselB Re: /var - 15/04/07 08:49 AM
The set command creates a global variable. The var command creates a local variable. Local variables can also be created using the -l switch in the set command.
Local variables only stay for a period of time -- usually until the script ends -- however, I have come across times when a local variable has been unset before the script ended, especially when it's been a big script (ie: 25k+)

Global variables don't get unset until you unset them (or reset them).

None of this counteracts my earlier statement about using proper variable names.
Posted By: cold Re: /var - 15/04/07 09:48 AM
Originally Posted By: Wims
Just find another strange thing with /var :

//var % 1 | echo -a %a \ $var(%).value

and after :

//set % 56 | var % 1 | echo 4 -a $var(%).value | unset % | echo 6 -a $var(%).value

this would echos :
2
1

and i don't know why .


Firstly, you should use the correct $var usage ($var(%var,N).value):
Code:
//set % set | var % var  | echo 4 -a $var(%,1).value | unset % | echo 6 -a $var(%,1).value

This will echo...
Code:
var
var

...and it shouldn't. It should be "var" and "set". Although /var is lacking the '=' sign in your code, I've found the issue isn't due to that, but rather to a variable name weirdness, like RusselB suggested. Anything other than '%' will work:
Code:
//set %% set | var %% var  | echo 4 -a $var(%%,1).value | unset %% | echo 6 -a $var(%%,1).value


Nevertheless, you should include the '=' sign in your /var commands, as the practice of not doing it has been proven unsafe by many times in these forums.
Posted By: Wims Re: /var - 15/04/07 03:48 PM
Why do you thing i post here, because i'd rather that /Var or /set % 1 will return an error since we don't specify a valid entry for the variable name

For the "=" of /var % 1 and the format of $var, watch this :

//var % = 1 | echo 4 -a $var(%,1).value

As i said, i think /Var or /set with '%' should return an error
Posted By: RusselB Re: /var - 15/04/07 05:24 PM
OK...In that case I agree completely, since using % without anything else would be an incorrect variable name. I'm not sure if I missed that point earlier, or if I just misunderstood what you were saying.
Posted By: Wims Re: /var - 15/04/07 05:58 PM
But i would have liked some explanation about the result of $var
because /var % 1 | echo -a $var(%) $var(%).value will echos 1 1 and
and //set -u1 % 1 | //var % 1 | echo -a $var(%) $var(%).value echos 2 2

for the "=" and $var, in fact i made a mistake, i forgot some exemple :

//var % = 1 | echo 4 -a $var(%,1).value > = 1
//var % = 1 | echo 4 -a $var(%).value > 1
//set -su1 % 2 | var -s % = 2 | echo -a $var(%) $var(%).value > 2 2
//var -s % = 2 | echo -a $var(%) $var(%).value > 1 1

we can see % is egual to = 2




© mIRC Discussion Forums