View Single Post
  #2  
Old 11-03-2001, 05:53 AM
Xaviar Xaviar is offline
Registered User
Join Date: Aug 2001
Location: Fairyland
Posts: 463
Xaviar is on a distinguished road
Send a message via ICQ to Xaviar Send a message via AIM to Xaviar
A for loop is a counter driven loop, the syntax is for(var and starting value; condition to loop while true; increment) { commands to be executed }

So for instance,
NPC Code:

for (i = 0; i < 10; i++) {
playerx+=.5;
sleep .05;
}


will move the player 5 spaces to the right (.5 spaces, 10 times)

But don't use it like that, the best time to use it (In my opinion) is with arrays:
Say I've got a 5 element array, and I want to set each element to whereever it is in the array, + 1, so that the array will be {1, 2, 3, 4, 5} (the first element's index in an array is 0, remember) I would do this:

NPC Code:

for (i = 0; i < 5; i++) {
myarray[i] = i + 1;
}


Get it?
__________________
One by one, the penguins steal my sanity.

*cookie for Xaviar* --Originally posted by Tyhm

--Xaviar

A m e r i c a
Reply With Quote