mIRC Home    About    Download    Register    News    Help

Print Thread
$v1 etc, for while loops #223573 29/07/10 03:36 AM
Joined: Nov 2009
Posts: 295
P
pball Offline OP
Fjord artisan
OP Offline
Fjord artisan
P
Joined: Nov 2009
Posts: 295
I've use $v1 a few times after if statements, but I find myself wishing there was something like that for while loops.

I have lots of loops that use $gettok() and then I reference that same $gettok() many times in the loop, it would simpler if $v1 also worked in while loops.

EX:
set -l %stuff 1|2|3|4|5|6|7
set -l %num 1
while ($gettok(%stuff,%num,124)) {
echo -a $v1
inc %num
}

it'd be nice to use $v1 instead of $gettok(%stuff,%num,124), specially if I need to use that token multiple times.


http://scripting.pball.win
My personal site with some scripts I've released.
Re: $v1 etc, for while loops [Re: pball] #223575 29/07/10 03:47 AM
Joined: Dec 2002
Posts: 3,138
C
Collective Offline
Hoopy frood
Offline
Hoopy frood
C
Joined: Dec 2002
Posts: 3,138
$v1 already works in while loops. Even the exact code you posted produces the expected result.

Note that if you call an alias containing an if statement then $v1 and $v2 will be overwritten for subsequent commands.

Re: $v1 etc, for while loops [Re: pball] #223585 29/07/10 03:33 PM
Joined: Nov 2009
Posts: 295
P
pball Offline OP
Fjord artisan
OP Offline
Fjord artisan
P
Joined: Nov 2009
Posts: 295
wtf i swore i tried that and it didn't work before, not that exact code but using $v1

EDIT:
Actually now that I think about it my request still stands. Just a slight change, give use a unique $v1 type identifier for while loops. While $v1 does work in a loop it's reset as soon as you use an if statement. So an identifier for only while loops would be great.

Last edited by pball; 29/07/10 03:42 PM.

http://scripting.pball.win
My personal site with some scripts I've released.
Re: $v1 etc, for while loops [Re: pball] #223587 29/07/10 05:11 PM
Joined: Apr 2010
Posts: 921
F
FroggieDaFrog Offline
Hoopy frood
Offline
Hoopy frood
F
Joined: Apr 2010
Posts: 921
Code:
while (this condition that) {
  var %v1 = $v1, %v2 = $v2
  if (something condition thisthing) {
    ;use $v1 & $v2 for the if part, and %v1,%v2 for checking while things 
  }
}


I am SReject
My Stuff
Re: $v1 etc, for while loops [Re: pball] #223593 29/07/10 07:25 PM
Joined: Jul 2007
Posts: 1,129
T
Tomao Offline
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
FYI, $v1 and $v2 identifier weren't introduced until the version 6.16. They work the same for $ifmatch and $ifmatch2

So for those who still stick around with the old version below 6.16, they must use the other two for reference.

Re: $v1 etc, for while loops [Re: pball] #223596 29/07/10 10:00 PM
Joined: Oct 2003
Posts: 3,918
A
argv0 Offline
Hoopy frood
Offline
Hoopy frood
A
Joined: Oct 2003
Posts: 3,918
$v1/$v2 would *always* reset for any other control statement. Even if mIRC had a special "$v1"-like identifier for while loops, it would still necessarily reset for another nested while:

Code:
while (conditionA) {
  while (conditionB) {
    echo -a $v1 | ; results of conditionB
  }
}


So it doesn't really help that much. Given that you can always assign the result to a variable, and that you would still need to do this in at least a few cases, another special variable would only lead to more confusion.


- argv[0] on EFnet #mIRC
- "Life is a pointer to an integer without a cast"
Re: $v1 etc, for while loops [Re: argv0] #223604 30/07/10 04:15 AM
Joined: Nov 2009
Posts: 295
P
pball Offline OP
Fjord artisan
OP Offline
Fjord artisan
P
Joined: Nov 2009
Posts: 295
that is true, but I find myself needing the same value only inside single while loops and not nested while loops.


http://scripting.pball.win
My personal site with some scripts I've released.
Re: $v1 etc, for while loops [Re: pball] #223605 30/07/10 04:23 AM
Joined: Apr 2010
Posts: 921
F
FroggieDaFrog Offline
Hoopy frood
Offline
Hoopy frood
F
Joined: Apr 2010
Posts: 921
See my previous post smile


I am SReject
My Stuff
Re: $v1 etc, for while loops [Re: pball] #223758 01/08/10 12:01 PM
Joined: Jan 2004
Posts: 162
R
RRX Offline
Vogon poet
Offline
Vogon poet
R
Joined: Jan 2004
Posts: 162
The 'reset' goes even further than you think, even without an /if in your while loop: if you call an alias containing a condition, it's altered from there.

Last edited by RRX; 01/08/10 12:01 PM.
Re: $v1 etc, for while loops [Re: RRX] #223782 01/08/10 05:23 PM
Joined: Oct 2004
Posts: 8,327
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,327
That doesn't change what was said... just set a variable. Trying to keep track of a bunch of different $v's in order to keep from replacing them with other conditions, you can much more easily set a variable and be done with it. It doesn't slow your script down anywhere near enough to notice.


Invision Support
#Invision on irc.irchighway.net
Re: $v1 etc, for while loops [Re: Riamus2] #223786 01/08/10 05:38 PM
Joined: Jan 2004
Posts: 162
R
RRX Offline
Vogon poet
Offline
Vogon poet
R
Joined: Jan 2004
Posts: 162
It doesn't change what was said, it appends to it: not only other conditions (alike the mentioned outer while loop condition) alter $v1, also external code that is called, so without any condition in this code section, will alter it whenever it has a condition somewhere. You don't see any condition, yet $v1 is altered due to an alias call.

For example:
Code:
alias bla { if ($read(mirc.ini,1) != $null) { blalog $v1 | echo -ag $v1 logged } }
alias blalog { if (ON == %logging) { noop } }

notice how the second $v1 in alias bla becomes the 'ON' from alias blalog.
That was what I tried to make clear.
So yes, it should use a variable.

Re: $v1 etc, for while loops [Re: RRX] #223802 01/08/10 11:36 PM
Joined: Oct 2004
Posts: 8,327
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,327
Ok, I thought you were adding that extra $v's should be used because of that reason as well. I agree with you. laugh


Invision Support
#Invision on irc.irchighway.net