![]() |
[SCRIPT] "For" scripts - Printable Version +- Frictional Games Forum (read-only) (https://www.frictionalgames.com/forum) +-- Forum: Amnesia: The Dark Descent (https://www.frictionalgames.com/forum/forum-6.html) +--- Forum: Custom Stories, TCs & Mods - Development (https://www.frictionalgames.com/forum/forum-38.html) +---- Forum: Development Support (https://www.frictionalgames.com/forum/forum-39.html) +---- Thread: [SCRIPT] "For" scripts (/thread-18653.html) |
"For" scripts - The chaser - 10-06-2012 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 ![]() That "for" joke was a very bad one... ![]() RE: "For" scripts - Ongka - 10-06-2012 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. RE: "For" scripts - The chaser - 10-06-2012 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? RE: "For" scripts - Kreekakon - 10-06-2012 You missed a plus at the end of the for. It should look like this: for(int i=1;i<=200;i++) RE: "For" scripts - Ongka - 10-06-2012 And it would probably be AddEntityCollideCallback("book_" +i, "Script", "Func", false, 1); But otherwise, yes, that would work. RE: "For" scripts - The chaser - 10-06-2012 Thanks everyone, I have a working for! |