![]() |
for loops and setarray
I'm probably not the first to ask about these. I'm trying to learn about for loops and setarray (arrays or something).
Will anyone be nice and willing to post an extremely small script that does something and add an explanation (comments) alongside them so I can read it and hopefull get a better understanding of them. I've tried to search through the old threads, but I didn't find anything really useful for what I was looking for. :( I'll be very greatful and give many thanks to whoever could help me to understand them. |
for(i=0;i<10;i++){
playerrupees+=i; sleep 1; } that adds 1 ruppes every second for 10 second setarray array,2; array[0]=1 array[1]=2 you can save numberical info in arrays like that |
also
you can also set values of arrays like this:
array = {0,1,2,4,5,-15,..n}; setarray arrayname,10; this would give you (in the debugger) arrayname = 0/{0,0,0,0,0,0,0,0,0,0} (the 0/ part does nothing, as far as i know) example of an array in a for statement: NPC Code: and you'd get back count = 0/{1,2,3,4,5,6,7,8,9,10} count[x] is the "slot" of the array you are accessing..so after we ran the forstatement above, count[3] would be 4, because the array begins with count[0] (not count[1]) And...that's pretty much the basics...I don't know if that helped, that's the way I looked at it. |
NPC Code: This is my 6 variable per raindrop rain script. It is one big array. Perhaps it will show you some interesting things... |
lol. Hey thanks guys. So far I have an idea about the for loop now.
Here's something I tested out to experiment with using for loops // NPC made by Criminal if(playerenters){ toweapons Test_Kamehameha; playermp=100; } if(weaponfired){ if(playermp>=10){ playermp-=10; if(playerdir=3){ for(this.explosx=4; this.explosx<11; this.explosx+=1.5;){ sleep.1; setani shoot,; freezeplayer .3; putexplosion2 1,1,playerx+this.explosx,playery+.75; } }else if(playerdir=1){ for(this.explosx2=3; this.explosx2<11; this.explosx2+=1.5;){ sleep.1; setani shoot,; freezeplayer .3; putexplosion2 1,1, playerx-this.explosx2,playery+.75; } } if(playerdir=0){ for(this.explosy=3; this.explosy<11; this.explosy+=1.5;){ sleep.1; setani shoot,; freezeplayer .3; putexplosion2 1,1, playerx,playery-this.explosy; } } if(playerdir=2){ for(this.explosy2=4; this.explosy2<11; this.explosy2+=1.5;){ sleep.1; setani shoot,; freezeplayer .3; putexplosion2 1,1, playerx,playery+this.explosy2; } } } else say2 Sorry you don't have #b anymore magic left; } Now I just need to figure out how to do the arrays. :D |
Yes.... Once you learn arrays...
You could do that same script in 1/6th the number of lines.... or less..... |
well here's my first try using arrays.
// NPC made by Criminal (Skyre Draneth) // experimenting with arrays if(playerenters){ toweapons Kamehameha_Array_Test; } if(weaponfired){ this.end=10; setarray this.start,this.end; setani shoot,; freezeplayer .8; for(this.start=4; this.start<this.end; this.start++;){ if(playerdir=3){ putexplosion2 1,1,playerx+this.start,playery+.5; sleep.1; } if(playerdir=1){ putexplosion2 1,1,playerx-this.start,playery+.5; sleep.1; } if(playerdir=0){ putexplosion2 1,1,playerx,playery-this.start; sleep.1; } if(playerdir=2){ putexplosion2 1,1,playerx,playery+this.start; sleep.1; } } } |
Quote:
sorry but there are no arrays in that script....... |
Are there any others that can explain arrays in a simple way and showing an example of one being used. Just 1 array in a script.
:( |
Quote:
An array is where one variable becomes capable of holding more than one value. In effect, it turns one variable into many. Example. NPC Code: ... leaves you with: NPC Code: ... which can all have different contents: NPC Code: That help? |
Quote:
Sorry my bad. For loops and thinking. would let you do that in less lines. only becouse there is a build in command for some old arrays. Also you need to use " == " instead of " = " in an if statement. NPC Code: Keep at it. You'll get it. :) |
Quote:
Quote:
If this sounded vaguely patronizing, then I apologize. No insult was meant. Just getting my point across. :) |
Well if Mr. Mod wonldn't have deleted my post on the forums a few days ago that was not only a very good explaination of arrays and string arrays, but also was a very good explaination of many other things I would have posted it here. I didn't think i should save it, because I figured it would stay there, but I guess Jagen didn't agree, what is he intimidated because he didn't post it?
|
Quote:
|
All times are GMT +2. The time now is 10:12 PM. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.