CabConModding
Facebook
Twitter
youtube
Discord
Contact us
RSS
Menu
CabConModding
Home
New
Top
Premium
Rules
FAQ - Frequently Asked Questions
Games
Fornite
Call of Duty: Black Ops 3
Clash of Clans
Grand Theft Auto 5
Apex Legends
Assassin’s Creed Origins
Forums
Premium
Latest posts
What's new
Latest posts
New profile posts
Latest activity
Members
Current visitors
New profile posts
Log in
Register
What's new
Premium
Latest posts
Menu
Log in
Register
Navigation
Install the app
Install
More options
Dark Theme
Contact us
Close Menu
Forums
Gaming
Call of Duty Classics
Tutorial Section
Basic GSC Coding: While, Break and Wait
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="CabCon" data-source="post: 9847" data-attributes="member: 1"><p>This is the next tutorial about basic gsc coding, I´ll explain at first the "while" command, this command what it does is to repeat something continuously (with a wait beetween repetitions). Its structure is the following:</p><p>[code]while( something )</p><p>{</p><p>WHAT YOU WANT TO REPEAT</p><p>wait ( THE FRECUENCY YOU WANT TO REPEAT );</p><p>}[/code]</p><p></p><p>In the while is necessary to add a wait, if not you will make a BIG failure. The wait works like this and it is measured in seconds:</p><p>[code]wait ( time you want to wait );[/code]</p><p></p><p>You can also simplify it like this (I put a few examples):</p><p>[code]wait 3;</p><p>wait 2.5;</p><p>wait 0.9;</p><p>wait 0.05;[/code]</p><p></p><p>Or if the time is smaller than 1:</p><p>[code]wait .05;[/code]</p><p></p><p>Lets continue with the while, the while will repeat when is something happening, if you dont care of what happens and you want to keep it running without end, you put in "something": true or 1 (which are both same).</p><p>[code]</p><p>while( 1 )</p><p>while( true )[/code]</p><p></p><p>You can also put in the something a condition, for example, if you have a variable called variable1 and its value is 6 and its changing, you can do like this to make it only repeat when the value is 6</p><p>[code]while( variable1 == 6 )[/code]</p><p></p><p>You can also add a ingame function, for example one that checks your player stance (stand, prone or crouch, in the example I am checking if the stance is crouch):</p><p>[code]while( self getStance() == "crouch" )[/code]</p><p></p><p>Lets try to do something that says some words to all players every 10 seconds:</p><p>[code]while( 1 )</p><p>{</p><p> self sayall( "While Tutorial" );</p><p> wait ( 10 );</p><p>}[/code]</p><p></p><p>The sayall is a command that says something in chat to all players in the lobby. The problem of the "while"s is that if you dont end them, they will keep running and sometimes if you reach a certain ammount of them running you will suffer problems such as laggs or game crashes, so its very important to destroy them. One way to do this is using another gsc command called "break", it will destroy the "while" in which is contained:</p><p>[code]while( 1 )</p><p>{</p><p> self iPrintLnBold( "Break Function" );</p><p> break;</p><p> wait ( 3 );</p><p>}[/code]</p><p></p><p>The previous code is quite stupid, because the "while" will never repeat, it will just play once because you destroy it in the first repetition, so the best thing on this is to check a variable and then "break" it:</p><p>[code]while( 1 )</p><p>{</p><p> if( self getStance() == "stand" )</p><p> break;</p><p> wait ( 0.05 );</p><p>}[/code]</p><p></p><p>In the previous case the "while" will be destroyed when the player stance is "stand". Another way to destroy "while"s which is more used is to add a "endon". The endon waits for some game notification and when it happens it destroys the "while"s contained in the function, the most used ones are these 2:</p><p>[code]self endon( "death" );</p><p>self endon( "disconnect" );[/code]</p><p></p><p>The first one will destroy the "while" when you die and the second one when you disconnect. Lets combine a few of the previous examples all in 1 and inside a function, functions have this structure if you dont know:</p><p>[code]Function( )</p><p>{</p><p>CODES HERE</p><p>}[/code]</p><p></p><p>Lets see the example (It will say to all players: While Tutorial every 10 seconds and the "while" be destroyed if you die or disconnect):</p><p>[code]</p><p>Tutorial( )</p><p>{</p><p> self endon( "death" );</p><p> self endon( "disconnect" );</p><p> while( 1 )</p><p> {</p><p> self sayall( "While Tutorial" );</p><p> wait ( 10 );</p><p> }</p><p>}[/code]</p><p></p><p><strong>Question?</strong></p><p><a href="http://cabconmodding.com/index.php?forums/gsc-section-questions.54/" target="_blank">Ask them here</a>.</p><p></p><p>Credits are going to Yamato.</p></blockquote><p></p>
[QUOTE="CabCon, post: 9847, member: 1"] This is the next tutorial about basic gsc coding, I´ll explain at first the "while" command, this command what it does is to repeat something continuously (with a wait beetween repetitions). Its structure is the following: [code]while( something ) { WHAT YOU WANT TO REPEAT wait ( THE FRECUENCY YOU WANT TO REPEAT ); }[/code] In the while is necessary to add a wait, if not you will make a BIG failure. The wait works like this and it is measured in seconds: [code]wait ( time you want to wait );[/code] You can also simplify it like this (I put a few examples): [code]wait 3; wait 2.5; wait 0.9; wait 0.05;[/code] Or if the time is smaller than 1: [code]wait .05;[/code] Lets continue with the while, the while will repeat when is something happening, if you dont care of what happens and you want to keep it running without end, you put in "something": true or 1 (which are both same). [code] while( 1 ) while( true )[/code] You can also put in the something a condition, for example, if you have a variable called variable1 and its value is 6 and its changing, you can do like this to make it only repeat when the value is 6 [code]while( variable1 == 6 )[/code] You can also add a ingame function, for example one that checks your player stance (stand, prone or crouch, in the example I am checking if the stance is crouch): [code]while( self getStance() == "crouch" )[/code] Lets try to do something that says some words to all players every 10 seconds: [code]while( 1 ) { self sayall( "While Tutorial" ); wait ( 10 ); }[/code] The sayall is a command that says something in chat to all players in the lobby. The problem of the "while"s is that if you dont end them, they will keep running and sometimes if you reach a certain ammount of them running you will suffer problems such as laggs or game crashes, so its very important to destroy them. One way to do this is using another gsc command called "break", it will destroy the "while" in which is contained: [code]while( 1 ) { self iPrintLnBold( "Break Function" ); break; wait ( 3 ); }[/code] The previous code is quite stupid, because the "while" will never repeat, it will just play once because you destroy it in the first repetition, so the best thing on this is to check a variable and then "break" it: [code]while( 1 ) { if( self getStance() == "stand" ) break; wait ( 0.05 ); }[/code] In the previous case the "while" will be destroyed when the player stance is "stand". Another way to destroy "while"s which is more used is to add a "endon". The endon waits for some game notification and when it happens it destroys the "while"s contained in the function, the most used ones are these 2: [code]self endon( "death" ); self endon( "disconnect" );[/code] The first one will destroy the "while" when you die and the second one when you disconnect. Lets combine a few of the previous examples all in 1 and inside a function, functions have this structure if you dont know: [code]Function( ) { CODES HERE }[/code] Lets see the example (It will say to all players: While Tutorial every 10 seconds and the "while" be destroyed if you die or disconnect): [code] Tutorial( ) { self endon( "death" ); self endon( "disconnect" ); while( 1 ) { self sayall( "While Tutorial" ); wait ( 10 ); } }[/code] [B]Question?[/B] [URL='http://cabconmodding.com/index.php?forums/gsc-section-questions.54/']Ask them here[/URL]. Credits are going to Yamato. [/QUOTE]
Verification
Post reply
Forums
Gaming
Call of Duty Classics
Tutorial Section
Basic GSC Coding: While, Break and Wait
CabConModding is now on facebook! Check the latest Updates, the Site Status and much more now!
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.
Accept
Learn more…
Top