mIRC Home    About    Download    Register    News    Help

Print Thread
#17957 03/04/03 07:37 PM
Joined: Apr 2003
Posts: 1
A
Mostly harmless
OP Offline
Mostly harmless
A
Joined: Apr 2003
Posts: 1
i'm getting to think that i'm stupid. Is there any posibility to loop through all parameters given in the $1- ... with $0 I can check the number, with $1 $2- $6-8 i can access these parameters, but is there any way to adress the parameter with a variable ... for example $(%parameter_num) ...

#17958 03/04/03 07:54 PM
Joined: Mar 2003
Posts: 63
N
Babel fish
Offline
Babel fish
N
Joined: Mar 2003
Posts: 63
Try using $gettok($1-,%parameter_number,32)
For example, if you have "hello it's me" in $1-, $gettok($1-,2,32) will return "it's"
Look at the gettok help section for more info smile

#17959 03/04/03 07:55 PM
Joined: Dec 2002
Posts: 699
N
Fjord artisan
Offline
Fjord artisan
N
Joined: Dec 2002
Posts: 699
Code:
  var %i = 1
  while $eval($+($,%i),2) {
    [color:blue]commands[/color]
    inc %i
  }

#17960 04/04/03 12:31 AM
Joined: Dec 2002
Posts: 332
C
Fjord artisan
Offline
Fjord artisan
C
Joined: Dec 2002
Posts: 332
just a quick question on the
var %i = 1
i have been using while loops but i wasnt sure how many times can i use var %i = 1
or is there no limit as long as it is seperate files ?

#17961 04/04/03 01:02 AM
Joined: Dec 2002
Posts: 699
N
Fjord artisan
Offline
Fjord artisan
N
Joined: Dec 2002
Posts: 699
Local Variables
Local variables are variables that exist only for the duration of the script in which they are created and can only be accessed from within that script. They can be created with the /var command:

They can be the same name as, and have no effect on, global variables, You can use /var %name any number of times in any number of scripts, each is only accessable from within its own code block smile

Here's a couple of little loops to show the same name (%i) being used twice concurrently. (use /testvar)
Code:
alias testvar {
  var %i = 1
  while %i < 3 {
    echo -a testvar1 $ord(%i) loop
    testvar2
    inc %i
  }
}
alias -l testvar2 {
  var %i = 1
  while %i < 3 {
    echo -a * testvar2 $ord(%i) loop
    inc %i
  }
}

#17962 04/04/03 01:34 AM
Joined: Dec 2002
Posts: 332
C
Fjord artisan
Offline
Fjord artisan
C
Joined: Dec 2002
Posts: 332
ah thats great .. lol i had almost run out of letters in the alphabet thx for the explanation smile

#17963 04/04/03 01:53 AM
Joined: Dec 2002
Posts: 699
N
Fjord artisan
Offline
Fjord artisan
N
Joined: Dec 2002
Posts: 699
Quote:
i had almost run out of letters in the alphabet

Well, you can also use numbers and symbols laugh grin
//var %1 = i | echo -a %1
//var %% = test | echo -a %%

#17964 04/04/03 04:57 AM
Joined: Jan 2003
Posts: 44
L
Ameglian cow
Offline
Ameglian cow
L
Joined: Jan 2003
Posts: 44
The thing that's going to help you the most here is to get away from using single letter variables.

Instead, use whole words for your variable names.

Doing this will greatly improve the readability of your programs and start to lend them to being of the self-documenting style.

For instance, 3 months down the road when you pick up mirc scripting again, variables like %i %x %j won't mean squat to you, but variables like %nicklist_index %chat_lines %file_length will.

Also when you start using words for variables, you are suddenly capable of way more variable names than by just using letters and symbols (which amount to about 70 variables).

#17965 04/04/03 05:31 AM
Joined: Dec 2002
Posts: 699
N
Fjord artisan
Offline
Fjord artisan
N
Joined: Dec 2002
Posts: 699
If you are talking about global variables I agree with using unique names, however I very much disagree with using so many global variables that their naming becomes a problem. laugh

#17966 04/04/03 11:59 PM
Joined: Dec 2002
Posts: 332
C
Fjord artisan
Offline
Fjord artisan
C
Joined: Dec 2002
Posts: 332
well i was meaning mostly for the while loops i have several different sscripts which use while loops and each one has a diff var %i or var %a etc just for simplicity i would think just one letter would be easier however i didnt realize it wouldnt conflict i went check the help further tho and i se the difference now thx for the input everyone smile

#17967 07/04/03 10:39 PM
Joined: Apr 2003
Posts: 342
M
Fjord artisan
Offline
Fjord artisan
M
Joined: Apr 2003
Posts: 342
Code:
 while ($0) {
   <do whatever >
   tokenize 32 $2-
}  


Every local variable exists only within the code block it's executing. It was introduced in 5.4 I beleive (about time). Here's an example...

[code];*** CREATES DIRECTORIES
;*** /MKDIR <PATH>
;***
ALIAS /MKDIR {
if ($1- == $null) { error /mkdir -hcl - Directory? WHAT DIRECTORY? }

if (($count($1-,:) != 1) && ($left($1,2) != \\)) { tokenize 32 $mircdir $+ $1- }

if (/ isin $1-) {
tokenize 32 $replace($1-,/,\)
}
if ($left($1,1) == ") { tokenize 34 $1- }

inc %l.dir.table
if ($right($1,1) == \) { tokenize 34 $left($1,-1) }

if (($isdir($deltok($1,$numtok($1,92),92)) == $false) $&
&& ($isfile($deltok($1,$numtok($1,92),92)) == $false)) {
recurse mkdir $quote($deltok($1,$numtok($1,92),92))
}

/!mkdir $quote($1-)
}[code]


Beware of MeStinkBAD! He knows more than he actually does!

Link Copied to Clipboard