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
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


Messages In This Thread
"For" scripts - by The chaser - 10-06-2012, 08:56 AM
RE: "For" scripts - by Ongka - 10-06-2012, 09:46 AM
RE: "For" scripts - by The chaser - 10-06-2012, 10:40 AM
RE: "For" scripts - by Kreekakon - 10-06-2012, 12:39 PM
RE: "For" scripts - by Ongka - 10-06-2012, 01:29 PM
RE: "For" scripts - by The chaser - 10-06-2012, 02:34 PM



Users browsing this thread: 2 Guest(s)