Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Script Help "For" scripts
The chaser Offline
Posting Freak

Posts: 2,486
Threads: 76
Joined: Jun 2012
Reputation: 113
#1
"For" scripts

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

THE OTHERWORLD (WIP)
[Image: k6vbdhu]

Aculy iz dolan.
10-06-2012, 08:56 AM
Find
Ongka Offline
Member

Posts: 225
Threads: 3
Joined: Nov 2010
Reputation: 20
#2
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.

[Image: 18694.png]
10-06-2012, 09:46 AM
Find
The chaser Offline
Posting Freak

Posts: 2,486
Threads: 76
Joined: Jun 2012
Reputation: 113
#3
RE: "For" scripts

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?

THE OTHERWORLD (WIP)
[Image: k6vbdhu]

Aculy iz dolan.
10-06-2012, 10:40 AM
Find
Kreekakon Offline
Pick a god and pray!

Posts: 3,063
Threads: 70
Joined: Mar 2012
Reputation: 124
#4
RE: "For" scripts

You missed a plus at the end of the for. It should look like this:


for(int i=1;i<=200;i++)

[Image: Tv0YgQb.gif]
Image by BandyGrass
10-06-2012, 12:39 PM
Find
Ongka Offline
Member

Posts: 225
Threads: 3
Joined: Nov 2010
Reputation: 20
#5
RE: "For" scripts

And it would probably be AddEntityCollideCallback("book_" +i, "Script", "Func", false, 1);
But otherwise, yes, that would work.

[Image: 18694.png]
10-06-2012, 01:29 PM
Find
The chaser Offline
Posting Freak

Posts: 2,486
Threads: 76
Joined: Jun 2012
Reputation: 113
#6
RE: "For" scripts

Thanks everyone, I have a working for!

THE OTHERWORLD (WIP)
[Image: k6vbdhu]

Aculy iz dolan.
10-06-2012, 02:34 PM
Find




Users browsing this thread: 2 Guest(s)