X4anco
Member
Posts: 157
Threads: 66
Joined: Apr 2011
Reputation:
0
|
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 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 |
|
palistov
Posting Freak
Posts: 1,208
Threads: 67
Joined: Mar 2011
Reputation:
57
|
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
//--------------------
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 |
|
X4anco
Member
Posts: 157
Threads: 66
Joined: Apr 2011
Reputation:
0
|
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
Can you explain? I have no idea you could do loops
...
|
|
06-21-2011, 04:56 PM |
|
palistov
Posting Freak
Posts: 1,208
Threads: 67
Joined: Mar 2011
Reputation:
57
|
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 |
|
Apjjm
Is easy to say
Posts: 496
Threads: 18
Joined: Apr 2011
Reputation:
52
|
RE: what do they do?...
If we label each part of the for loop construct
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 |
|
palistov
Posting Freak
Posts: 1,208
Threads: 67
Joined: Mar 2011
Reputation:
57
|
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
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 |
|
Apjjm
Is easy to say
Posts: 496
Threads: 18
Joined: Apr 2011
Reputation:
52
|
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
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 .
the following two statements are equivalent:
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 |
|
palistov
Posting Freak
Posts: 1,208
Threads: 67
Joined: Mar 2011
Reputation:
57
|
RE: what do they do?...
Excellent! Thank you sir!
|
|
06-21-2011, 06:14 PM |
|
xiphirx
Senior Member
Posts: 662
Threads: 16
Joined: Nov 2010
Reputation:
5
|
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 |
|
|