mIRC Home    About    Download    Register    News    Help

Print Thread
#102780 13/11/04 02:32 AM
Joined: Feb 2004
Posts: 45
N
Navid Offline OP
Ameglian cow
OP Offline
Ameglian cow
N
Joined: Feb 2004
Posts: 45
hello.
This is probably my first post or maybe second dont know smile.
I'll introduce myself if required.

Okay, I've been trying to learn how to use the
Code:
var %i = 1
while (%i <= 10) {
  echo 2 %i
  inc %i
}
but I can't figure out what the 'while' does in that script.
Another thing about the $gettok tokkens (ie:
Code:
$gettok(a.b.c.d.e,3,46)	returns c
 
okay in that line I understand why it returns C but what is the 46 for. I've seen a few $gettok but with different number at the end like 32,46 etc..
Can someone help with those 2 questions please smile

Joined: Dec 2002
Posts: 2,962
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
A while loop will keep running everything inside it's execution block (the code between the { }'s) as long as the condition is true.

For example this code:
Code:
var %i = 1
while (%i <= 4) {
  echo 2 %i
  inc %i
}
echo This echo is outside the while loop

would run like this line-by-line:
Assign 1 to %i
Check while loop condition... (1 <= 4) is [color:green]true

Output %i
Increment %i by 1
Check while loop condition... (2 <= 4) is true
Output %i
Increment %i by 1
Check while loop condition... (3 <= 4) is true
Output %i
Increment %i by 1
Check while loop condition... (4 <= 4) is true
Output %i
Increment %i by 1
Check while loop condition... (5 <= 4) is false
Output 'This echo is outside the while loop'[/color]

The 46 in $gettok(a.b.c.d.e,3,46) is the ASCII number for a fullstop (.). 32 is the ASCII number for a space. You can get the ASCII number of any character by using $asc(character here).


Spelling mistakes, grammatical errors, and stupid comments are intentional.
Joined: Feb 2004
Posts: 45
N
Navid Offline OP
Ameglian cow
OP Offline
Ameglian cow
N
Joined: Feb 2004
Posts: 45
thanks for the while loops I understand them now smile

so with every $gettok command there has to be a 46 or 32 at the end?. How do you know which one to put?

Joined: Dec 2002
Posts: 2,962
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
Well it doesn't have to be 46 or 32, they're simply two of the most commonly used. It can be the number of any ASCII character (ie. 1-255). You use the number of whichever character you want to be the token delimiter (the character which separates the tokens).

So for example if you used $gettok(a=a[color:red].b=b.c=c,2,46)[/color] then it would return b=b because the fullstop is being used as the delimiter, however if you used $gettok(a[color:red]=a.b=b.c=c,2,61)[/color] (61 is the ASCII number for the equals sign) then it would return a.b since the equals sign is now the delimiter.


Spelling mistakes, grammatical errors, and stupid comments are intentional.
Joined: Feb 2004
Posts: 45
N
Navid Offline OP
Ameglian cow
OP Offline
Ameglian cow
N
Joined: Feb 2004
Posts: 45
okay thanks for your help starbucks_mafia. I appriciate it smile


Link Copied to Clipboard