Frictional Games Forum (read-only)

Full Version: "For" scripts
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I was hanging for there, looking at CS's scripts, and I see a lot of those "for".
Those must be very useful, but I don't really get the meaning of them. Yes, I've read the article in the wiki but I don't get it. What's the special function of it? Does it repeat something? Does it "AddLocalVarInt" each time something in the "for" happens?

It's just that I have the impression that they are very useful and I want to have them in my power.

I will use them "For" cool purposes
Angel

That "for" joke was a very bad one... Big Grin
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.
So, an example:I want the following thing:

There is a library, a shelf. It has 200 books (impossible, I know) and I want that when one of these books touches an area something happens: It should be like this?

for(int i=1;i<=200;i+)
{
AddEntityCollideCallback("book_1_" +i, "Script", "Func", false, 1);
}



void Func /////stuff
{
////More stuff
}


Because it would be painful if I had to put 200 callbacks (one for each book)
Would it be useful?
You missed a plus at the end of the for. It should look like this:


for(int i=1;i<=200;i++)
And it would probably be AddEntityCollideCallback("book_" +i, "Script", "Func", false, 1);
But otherwise, yes, that would work.
Thanks everyone, I have a working for!