|
Tutorial Basic GSC Coding: Foreach, Continue and Return
|
|
Post: #1
|
|||
|
|||
|
Basic GSC Coding: Foreach, Continue and Return
Hello
This is the last Basic GSC coding tutorial, I´ll explain here: "foreach", "continue" and "return". "foreach" is used only with arrays. When you call it on an array, it returns all the variables inside the array and let you do something on all of them. Its structure is: Code: foreach( something in array )"something" is a random name you give to each array variable, "array" is the array you are using. Real examples: Code: foreach( player in level.players ) //most commonThe next command is "continue;", is used with "if"s. You put a condition and if its the contrary of what you have put in the condition, it will pass the continue. Its structure is this one: Code: if( a < b ) //if: a > b, it will pass, if not, it will go backExample: Code: if( self getVelocity()[0] > 100 )The previous is the same as: Code: if( self getVelocity()[0] < 100 && self isAlive() )The last command is "return", it does what its name says, return some value or whatever, what is after it in the code wont be played, is very useful sometimes to shorten some codes, its structure is the following: Code: return SOMETHING;Using a return can also force a function to continue running: Code: if( a == b )Real Example: Code: getName()I hope it has helped. Thanks for reading. @Yamato
![]() |
|||
The following 2 users say Thank You to Yamato for this post:Bloodfocus (04-02-2012), tsoPANos (04-03-2012) |
|
Post: #2
|
|||
|
|||
|
RE: Basic GSC Coding: Foreach, Continue and Return
I think you have something wrong with continue;
Continue skips the following commands and starts the next pass of a loop. Example: Code: foreach( player in level.players ) //most common![]() |
|||
The following 1 user says Thank You to zxz0O0 for this post:Yamato (04-04-2012) |
|
Post: #3
|
|||
|
|||
RE: Basic GSC Coding: Foreach, Continue and Return
|
|||
The following 1 user says Thank You to The Clay Man for this post:Yamato (04-04-2012) |
|
Post: #4
|
|||
|
|||
|
RE: Basic GSC Coding: Foreach, Continue and Return
Also, using return on it's own can force a function to exit prematurely. Eg:
Code: doCrap()
![]() A casual conversation between barata and I about Nukem. |
|||
The following 1 user says Thank You to master131 for this post:Yamato (04-04-2012) |
|
Post: #5
|
|||
|
|||
RE: Basic GSC Coding: Foreach, Continue and Return
(04-02-2012 23:48)master131 Wrote: Also, using return on it's own can force a function to exit prematurely. Eg: Be careful with threads... Not everything needs a thread. crAyon makes no warranty with respect to documents or other information available from this place, assumes no legal liability or responsibility whatsoever for the accuracy, completeness, or usefulness of any such information, and does not represent that its use would not infringe privately owned rights. crAyon disclaims all warranties, express and implied, including the warranties of merchantability and fitness for a particular purpose.
|
|||
|
Post: #6
|
|||
|
|||
RE: Basic GSC Coding: Foreach, Continue and Return
(04-03-2012 00:51)crAyon Wrote:(04-02-2012 23:48)master131 Wrote: Also, using return on it's own can force a function to exit prematurely. Eg: I know that crayon, it was just an example.
![]() A casual conversation between barata and I about Nukem. |
|||
|
Post: #7
|
|||
|
|||
RE: Basic GSC Coding: Foreach, Continue and Return
(04-02-2012 20:25)zxz0O0 Wrote: I think you have something wrong with continue; Yes, thats what I said. @master131 I added that to the main post. ![]() |
|||
|
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)
Media Embeding by Simple Audio Video Embeder



![[Image: veovuq.png]](http://i44.tinypic.com/veovuq.png)



![[-]](images/twilight/collapse.gif)

![[Image: azuw.jpg]](http://imageshack.us/a/img29/2668/azuw.jpg)

![[Image: 30xhrep.png]](http://i48.tinypic.com/30xhrep.png)
