mIRC Home    About    Download    Register    News    Help

Print Thread
#174604 10/04/07 02:20 AM
Joined: Jul 2006
Posts: 4,180
W
Wims Offline OP
Hoopy frood
OP Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,180
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 ?


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Wims #174605 10/04/07 02:57 AM
Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
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.

Wims #174610 10/04/07 04:25 AM
Joined: Jul 2003
Posts: 655
Fjord artisan
Offline
Fjord artisan
Joined: Jul 2003
Posts: 655
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)


"Allen is having a small problem and needs help adjusting his attitude" - Flutterby
Om3n #174623 10/04/07 09:35 AM
Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
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.


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
qwerty #174636 10/04/07 02:18 PM
Joined: Jul 2003
Posts: 655
Fjord artisan
Offline
Fjord artisan
Joined: Jul 2003
Posts: 655
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 } }

Last edited by Om3n; 10/04/07 02:22 PM.

"Allen is having a small problem and needs help adjusting his attitude" - Flutterby
Om3n #174638 10/04/07 02:48 PM
Joined: Apr 2004
Posts: 871
Sat Offline
Hoopy frood
Offline
Hoopy frood
Joined: Apr 2004
Posts: 871
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 }


Saturn, QuakeNet staff
qwerty #174666 10/04/07 06:17 PM
Joined: Jul 2006
Posts: 4,180
W
Wims Offline OP
Hoopy frood
OP Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,180
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


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Wims #174667 10/04/07 06:51 PM
Joined: Dec 2002
Posts: 2,033
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Dec 2002
Posts: 2,033
I'm going to call the 2nd one a bug because no
matter what I tried, I couldn't get it to work.

Sat #174668 10/04/07 07:11 PM
Joined: Jul 2003
Posts: 655
Fjord artisan
Offline
Fjord artisan
Joined: Jul 2003
Posts: 655
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.


"Allen is having a small problem and needs help adjusting his attitude" - Flutterby
Om3n #174676 10/04/07 09:55 PM
Joined: Apr 2004
Posts: 871
Sat Offline
Hoopy frood
Offline
Hoopy frood
Joined: Apr 2004
Posts: 871
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


Saturn, QuakeNet staff
Wims #174960 15/04/07 04:47 AM
Joined: Jul 2006
Posts: 4,180
W
Wims Offline OP
Hoopy frood
OP Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,180
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 .


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Wims #174962 15/04/07 06:59 AM
Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
Try using the correct format for a variable name, specifically something along the lines of %a not %

Wims #174967 15/04/07 08:28 AM
Joined: Mar 2006
Posts: 395
T
Pan-dimensional mouse
Offline
Pan-dimensional mouse
T
Joined: Mar 2006
Posts: 395
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


[02:16] * Titanic has quit IRC (Excess Flood)
The_JD #174970 15/04/07 08:49 AM
Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
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.

Wims #174974 15/04/07 09:48 AM
Joined: Feb 2003
Posts: 810
C
Hoopy frood
Offline
Hoopy frood
C
Joined: Feb 2003
Posts: 810
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.


* cold edits his posts 24/7
RusselB #174992 15/04/07 03:48 PM
Joined: Jul 2006
Posts: 4,180
W
Wims Offline OP
Hoopy frood
OP Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,180
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


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Wims #174996 15/04/07 05:24 PM
Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
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.

RusselB #175000 15/04/07 05:58 PM
Joined: Jul 2006
Posts: 4,180
W
Wims Offline OP
Hoopy frood
OP Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,180
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





Last edited by Wims; 15/04/07 06:05 PM.

#mircscripting @ irc.swiftirc.net == the best mIRC help channel

Link Copied to Clipboard