Frictional Games Forum (read-only)
what do they do?... - 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 (https://www.frictionalgames.com/forum/forum-35.html)
+--- Thread: what do they do?... (/thread-8730.html)



what do they do?... - X4anco - 06-21-2011

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
Code:
for(int i=0;i<10;i++) GiveItemFromFile("tinderbox_"+i, "tinderbox.ent");
all of the time and it's the
Code:
(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


RE: what do they do?... - palistov - 06-21-2011

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.


RE: what do they do?... - X4anco - 06-21-2011

(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


RE: what do they do?... - palistov - 06-21-2011

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!


RE: what do they do?... - Apjjm - 06-21-2011

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

If we label each part of the for loop construct
Code:
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:
Code:
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/docs/manual/doc_script_statements.html#if
it explains it very neatly.



RE: what do they do?... - palistov - 06-21-2011

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.


RE: what do they do?... - Apjjm - 06-21-2011

(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:
Code:
x = x+y;
x += y;
You can check out a list of the other compound assignment statements here.


RE: what do they do?... - palistov - 06-21-2011

Excellent! Thank you sir!


RE: what do they do?... - xiphirx - 06-21-2011

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