![]() |
Teaching: for()
for those of you who are new like me and dont know how the for command it used, its like saying:
i=0//the index is equil to zero while(i<64)//this is like adding to the if(), saying the index must be less then 64. and then the last section is adding or subtracting forom the index. so all together it looks like: for(i=0; i<64; i+=2;){ in here u may put commands. i will also give one example of how this may be used. if(created){toweapons test; } if(weaponfired){ for(explosionx=playerx; explosionx<64 explosionx+=1.5;) putexplosion 1,explosionx,playery+1; } } this script is a little messed up but does show a little how to use for. note: props to jagen for teaching me what for's are, and also if someone can show me how to put in a scripting section to make this easier to read it would be greatly apreciated. |
Re: Teaching: for()
Quote:
i=0; while(i<#) i++; not if(i=0) |
oh yeah, i messed up, lol.
|
>.>
format: for (initialization-operation;test;increment-operation){ commands; } (don't kill me if I got the words wrong, they still make sense >:O) initialization-operation = what happens right before the loop begins for the first time. test = what the loop will check and make sure is true before going onto the next loop. increment-operation = what happens after one loop completes EXAMPLE: for (i=0;i<10;i++){ setplayerprop #c,I CAN COUNT: #v(i)!; } OUTPUT: I CAN COUNT: 0! I CAN COUNT: 1! I CAN COUNT: 2! I CAN COUNT: 3! I CAN COUNT: 4! I CAN COUNT: 5! I CAN COUNT: 6! I CAN COUNT: 7! I CAN COUNT: 8! I CAN COUNT: 9! WHAT IT MEANS: for (i=0;i<10;i++){ setplayerprop #c,I CAN COUNT: #v(i)!; } i=0 makes it set the variable "i" to 0 before beginning the loop. for (i=0;i<10;i++){ setplayerprop #c,I CAN COUNT: #v(i)!; } i<10 checks whether or not the variable "i" is less than 10 before beginning the loop for (i=0;i<10;i++){ setplayerprop #c,I CAN COUNT: #v(i)!; } i++ makes the variable "i" increase by 1 after a loop completes. ORDER OF OPERATIONS: i is set to 0 checks whether or not i is less than 10 if i is less than 10, sets players' chat text to "I CAN COUNT: <value of i>! increases i by 1 checks whether or not i is less than 10 if i is less than 10, sets players' chat text to "I CAN COUNT: <value of i>! ...and so on Some people may be confused why it never outputs "I CAN COUNT: 10!".. thats because the test checks if its less than 10, meaning it will not actually include 10. If you wanted to include 10, you could make the test "i<11" or "i<=10" |
Quote:
Double check syntax if not using the test button in the editer ;) |
this should get stickied along with detailed explainations of other comands when they pop up.... and cheetos, im not exactly sure some people know like, initializing opertation and such, most do but i wouldnt be surprised if they didnt, anyway, there u have it folks, 2 nice and detailed explainations of for loops :D
// NPC made by Malicore (Hybrid) if (created) {toweapons BOOMY; } if (playertouchsme) { } if(weaponfired && dir=3 ){ for(explosionx=playerx+5; explosionx<playerx+15; explosionx+=1.5;){ sleep .1; putexplosion 1,explosionx,playery+1; } } if(weaponfired && dir=1){ for(explosionx2=playerx-5; explosionx2>playerx-15; explosionx2-=1.5;){ sleep .1; putexplosion 1,explosionx2,playery+1; } } if(weaponfired && dir=0){ for(explosiony=playery-5; explosiony>playery-15; explosiony-=1.5;){ sleep .1; putexplosion 1,playerx+1,explosiony; } } if(weaponfired && dir=2){ for(explosiony2=playery+5; explosiony2<playery+15; explosiony2+=1.5;){ sleep .1; putexplosion 1,playerx+1,explosiony2; } } i am now working on controlling the fire :D |
Quote:
|
:confused: huh?
|
Quote:
|
woops, haha, I was in a rush while typing that so I could finish my homework *fix* (they all have the same error cause I copy/pasted ;o)
|
Quote:
|
Quote:
|
Quote:
to get the weapon, use addweapon WeaponName; in a script |
Quote:
|
Quote:
|
Quote:
|
Quote:
|
Quote:
|
Quote:
|
| All times are GMT +2. The time now is 09:48 AM. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.