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


Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
what do they do?...
X4anco Offline
Member

Posts: 157
Threads: 66
Joined: Apr 2011
Reputation: 0
#1
what do they do?...

Hello peoples,

I am wondering and thinking about some scripts I've been seeing and could you explain them to me?

1) I see things like
for(int i=0;i<10;i++) GiveItemFromFile("tinderbox_"+i, "tinderbox.ent");
all of the time and it's the
(int i=0;i<10;i++)
bit that confuses me. What does it do?

2) In the game scripts I see things called 'Cases' what do they do?

3) How do peoples do crowbar puzzles and chipper and hammer puzzles? What is the code for that?
-X4anco

...
(This post was last modified: 06-21-2011, 04:55 PM by X4anco.)
06-21-2011, 04:51 PM
Find
palistov Offline
Posting Freak

Posts: 1,208
Threads: 67
Joined: Mar 2011
Reputation: 57
#2
RE: what do they do?...

That's a loop. It translates into "For every integer between 0 and less than 10, inclusive of 0, give the player 1 tinderbox". It will give the player 10 tinderboxes.

For loops are very handy. Toy around with them, I'm sure you'll find great uses for them Smile

//--------------------

Cases are used in switch functions. They're basically step-wise functions that are executed based on a variable. In vernacular it means "if the designated variable is 1, execute case 1; if the designated variable is 2, execute case 2; etc"

They're handy in a wide variety of functions. I suggest you master them, you'll find scripting events, puzzles, even your soundscape MUCH easier.

(This post was last modified: 06-21-2011, 04:57 PM by palistov.)
06-21-2011, 04:55 PM
Find
X4anco Offline
Member

Posts: 157
Threads: 66
Joined: Apr 2011
Reputation: 0
#3
RE: what do they do?...

(06-21-2011, 04:55 PM)palistov Wrote: That's a loop. It translates into "For every integer between 0 and less than 10, inclusive of 0, give the player 1 tinderbox". It will give the player 10 tinderboxes.

For loops are very handy. Toy around with them, I'm sure you'll find great uses for them Smile

Can you explain? I have no idea you could do loops Huh

...
06-21-2011, 04:56 PM
Find
palistov Offline
Posting Freak

Posts: 1,208
Threads: 67
Joined: Mar 2011
Reputation: 57
#4
RE: what do they do?...

It just executes whatever function you use 10 times, or however many times you want, depending on the loop. If you made it

for(int a=1;a<=100;a++) AddTimer(a, a, "Timers");

the function would create 100 timers, each having a duration one second longer than the previous. You can use them to give the player multiple items, create sequential timers, create/control/destroy multiple objects, etc. The sky's the limit!

06-21-2011, 05:02 PM
Find
Apjjm Offline
Is easy to say

Posts: 496
Threads: 18
Joined: Apr 2011
Reputation: 52
#5
RE: what do they do?...

(int i=0;i<10;i++)

If we label each part of the for loop construct
for(A;B;C)
  {
   D
  }

A: Executed when the for loop is first run. This part is mostly used to define a counting variable (usually i - chosen as it is the first letter of iteration), anything declared here only exists for the looped code and the loop construct.
B: A condition. Whilst this condition is true, the for loop will run. This is mostly used to check if our counting variable meets a condition.
C: A statement which is executed after each iteration of the loop.
D: The code you want to loop

This can be used for standard counting, as above, but it can also be used in other ways too:
for(;i>0;)  //Doing nothing at the stages is permitted
for(int x=2; y<0; y+=x) //Having different variables is permitted
for(int i=1; GetEntityExists("scriptarea_"+i); i++) //Functions can be called.

For switch-case stuff, i recommend reading the angelscript documentation on the matter:
http://www.angelcode.com/angelscript/sdk...ts.html#if
it explains it very neatly.
(This post was last modified: 06-21-2011, 07:54 PM by Apjjm.)
06-21-2011, 05:46 PM
Find
palistov Offline
Posting Freak

Posts: 1,208
Threads: 67
Joined: Mar 2011
Reputation: 57
#6
RE: what do they do?...

In comes the pro! Thanks for this Apjjm I didn't know you could do that stuff with loops...I like you, good sir. Very nice. Any other awesome tricks you'd like to share? Always willing to learn something new Smile

By the way, what does += do? And can -= be used? Sorry for the off-topic but I couldn't find anything on a quick Google search.

(This post was last modified: 06-21-2011, 05:55 PM by palistov.)
06-21-2011, 05:53 PM
Find
Apjjm Offline
Is easy to say

Posts: 496
Threads: 18
Joined: Apr 2011
Reputation: 52
#7
RE: what do they do?...

(06-21-2011, 05:53 PM)palistov Wrote: In comes the pro! Thanks for this Apjjm I didn't know you could do that stuff with loops...I like you, good sir. Very nice. Any other awesome tricks you'd like to share? Always willing to learn something new Smile

By the way, what does += do? And can -= be used? Sorry for the off-topic but I couldn't find anything on a quick Google search.
Happy to help Smile.
the following two statements are equivalent:
x = x+y;
x += y;
You can check out a list of the other compound assignment statements here.
(This post was last modified: 06-21-2011, 06:09 PM by Apjjm.)
06-21-2011, 06:09 PM
Find
palistov Offline
Posting Freak

Posts: 1,208
Threads: 67
Joined: Mar 2011
Reputation: 57
#8
RE: what do they do?...

Excellent! Thank you sir!

06-21-2011, 06:14 PM
Find
xiphirx Offline
Senior Member

Posts: 662
Threads: 16
Joined: Nov 2010
Reputation: 5
#9
RE: what do they do?...

It would help to learn the basics of C++. AngelScript has, pretty much, the exact syntax.

06-21-2011, 06:57 PM
Find




Users browsing this thread: 1 Guest(s)