Ongka
Member
Posts: 225
Threads: 3
Joined: Nov 2010
Reputation:
20
|
RE: "For" scripts
If you want to add 3 tinderboxes to your inventory, you can write:
GiveItemFromFile("tinderbox_1", "tinderbox.ent");
GiveItemFromFile("tinderbox_2", "tinderbox.ent");
GiveItemFromFile("tinderbox_3"i, "tinderbox.ent");
or
for(int i=1;i<=3;i++)
{
GiveItemFromFile("tinderbox_"+i, "tinderbox.ent");
}
Basically what this does is also add 3 tinderboxes to your inventory, now imagine you want to add 100 tinderboxes. With the first method it would take you pretty long, but here you simply have to change i<=3 to i<=100 and it will add 100 tinderboxes. i++ means each time the loop repeats, the variable i will add 1 to itself (1 to 2 and so on).
int i = 1 just declares a variable, you don't have to change this value.
i<=3 is the condition in which the loop operates. It will repeat till i is 3 (Basically: three times).
You could also write i<4 which would do the same.
GiveItemFromFile("tinderbox_"+i, "tinderbox.ent");
The i is a different number each time it repeats, so in the first run its "tinderbox_"+1 then it is "tinderbox_"+2 in the end the name of the tinderbox will be tinderbox_1 or tinderbox_2.
It sounds more complicated than it really is.
Feel free to ask questions if something isn't clear.
|
|
10-06-2012, 09:46 AM |
|