Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #4  
Old 09-08-2003, 02:48 AM
CheeToS2 CheeToS2 is offline
That Guy
CheeToS2's Avatar
Join Date: Dec 2001
Location: Seattle, WA
Posts: 2,528
CheeToS2 will become famous soon enough
Send a message via AIM to CheeToS2
>.>

format:
for (initialization-operation;test;increment-operation){
commands;
}
(don't kill me if I got the words wrong, they still make sense >:O)

initialization-operation = what happens right before the loop begins for the first time.

test = what the loop will check and make sure is true before going onto the next loop.

increment-operation = what happens after one loop completes

EXAMPLE:
for (i=0;i<10;i++){
setplayerprop #c,I CAN COUNT: #v(i)!;
}

OUTPUT:
I CAN COUNT: 0!
I CAN COUNT: 1!
I CAN COUNT: 2!
I CAN COUNT: 3!
I CAN COUNT: 4!
I CAN COUNT: 5!
I CAN COUNT: 6!
I CAN COUNT: 7!
I CAN COUNT: 8!
I CAN COUNT: 9!

WHAT IT MEANS:
for (i=0;i<10;i++){
setplayerprop #c,I CAN COUNT: #v(i)!;
}
i=0 makes it set the variable "i" to 0 before beginning the loop.

for (i=0;i<10;i++){
setplayerprop #c,I CAN COUNT: #v(i)!;
}
i<10 checks whether or not the variable "i" is less than 10 before beginning the loop

for (i=0;i<10;i++){
setplayerprop #c,I CAN COUNT: #v(i)!;
}
i++ makes the variable "i" increase by 1 after a loop completes.


ORDER OF OPERATIONS:
i is set to 0
checks whether or not i is less than 10
if i is less than 10, sets players' chat text to "I CAN COUNT: <value of i>!
increases i by 1
checks whether or not i is less than 10
if i is less than 10, sets players' chat text to "I CAN COUNT: <value of i>!
...and so on



Some people may be confused why it never outputs "I CAN COUNT: 10!".. thats because the test checks if its less than 10, meaning it will not actually include 10. If you wanted to include 10, you could make the test "i<11" or "i<=10"
__________________


Last edited by CheeToS2; 09-08-2003 at 04:20 AM..
Reply With Quote
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 02:25 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.