Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 06-28-2002, 10:26 AM
Xbob42 Xbob42 is offline
Registered User
Join Date: May 2002
Posts: 429
Xbob42 is on a distinguished road
Unhappy 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.
__________________
Criminal uses this account to post.
Reply With Quote
  #2  
Old 06-28-2002, 10:32 AM
Python523 Python523 is offline
Banned
Join Date: Aug 2001
Location: Illinois
Posts: 3,498
Python523 is on a distinguished road
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
Reply With Quote
  #3  
Old 06-28-2002, 11:04 AM
mikepg mikepg is offline
Registered User
Join Date: Nov 2001
Location: VA, USA
Posts: 501
mikepg is on a distinguished road
Send a message via AIM to mikepg Send a message via Yahoo to mikepg
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:

setarray count,10;
for (i=1; i<=arraylen(count); i++ {
count[i-1]=i;
}



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.
__________________
~War Lord Mpg2
Bravo Online's Asst. Staff Manager

"Sittin by the tree, sippin eggnog, waitin on christmas gifts"
Reply With Quote
  #4  
Old 06-29-2002, 12:14 AM
adam adam is offline
http://wiki.graal.us/
adam's Avatar
Join Date: Nov 2001
Posts: 2,247
adam has a spectacular aura aboutadam has a spectacular aura about
Send a message via AIM to adam
NPC Code:

// NPC made by Rogue Shadow -TT-*C* (TCN) // my name
if (created){ // check to see that npc has been created
this.rain=50; // number of raindrops
setarray this.xys,this.rain*6; // define the array
timeout=.05; // start the timeout loop
}
if (timeout){ // check for timeout
for (this.i=0;this.i<6*this.rain;this.i+=6){ // for loop in 6 step intervels
this.xys[this.i]+=this.xys[this.i+2]; // add xspeed to x
this.xys[this.i+1]+=this.xys[this.i+3]; // add yspeed to y
this.xys[this.i+5]+=1; // increase distance that has elapsed
showimg this.i,@o,this.xys[this.i],this.xys[this.i+1]; // draw the rain
changeimgcolors this.i,.5,.5,1,.9; // do color effects
changeimgzoom this.i,2*(1-(this.xys[this.i+5]/this.xys[this.i+4])); // do zoom effecs by percent of completed travel
if (this.xys[this.i+5]>this.xys[this.i+4]){ // check to see if distance has exceeded distance to travel
this.xys[this.i+0]=random(0,64); // x
this.xys[this.i+1]=random(0,64); // y
this.xys[this.i+2]=random(.5,.9); // xspeed
this.xys[this.i+3]=random(.5,.9); // yspeed
this.xys[this.i+4]=random(20,30); // distance to travel
this.xys[this.i+5]=0; // distance that has elapsed
}
}
timeout=.05; // restart timeout
}



This is my 6 variable per raindrop rain script.


It is one big array. Perhaps it will show you some interesting things...
__________________
Rogue Shadow (TCN)(NAT)(Global Development Team)

For development help, contact the patrons of the #graaldt irc channel below, I am usually there.
Click Here to Join IRC Chat Now! -- irc.freenode.net Channel: #graaldt
Quote:
<Dustyshouri> no, RogueShadow is always talking about scripts lol
<Dustyshouri> in fact, he pretty much brought Graal back as a topic single-handedly
Reply With Quote
  #5  
Old 06-29-2002, 07:39 AM
Xbob42 Xbob42 is offline
Registered User
Join Date: May 2002
Posts: 429
Xbob42 is on a distinguished road
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.
__________________
Criminal uses this account to post.
Reply With Quote
  #6  
Old 06-29-2002, 10:27 AM
adam adam is offline
http://wiki.graal.us/
adam's Avatar
Join Date: Nov 2001
Posts: 2,247
adam has a spectacular aura aboutadam has a spectacular aura about
Send a message via AIM to adam
Yes.... Once you learn arrays...

You could do that same script in 1/6th the number of lines....

or less.....
__________________
Rogue Shadow (TCN)(NAT)(Global Development Team)

For development help, contact the patrons of the #graaldt irc channel below, I am usually there.
Click Here to Join IRC Chat Now! -- irc.freenode.net Channel: #graaldt
Quote:
<Dustyshouri> no, RogueShadow is always talking about scripts lol
<Dustyshouri> in fact, he pretty much brought Graal back as a topic single-handedly
Reply With Quote
  #7  
Old 07-01-2002, 03:22 PM
Xbob42 Xbob42 is offline
Registered User
Join Date: May 2002
Posts: 429
Xbob42 is on a distinguished road
Talking

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;
}
}
}
__________________
Criminal uses this account to post.
Reply With Quote
  #8  
Old 07-01-2002, 03:29 PM
adam adam is offline
http://wiki.graal.us/
adam's Avatar
Join Date: Nov 2001
Posts: 2,247
adam has a spectacular aura aboutadam has a spectacular aura about
Send a message via AIM to adam
Quote:
Originally posted by Xbob42
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;
}
}
}


sorry but there are no arrays in that script.......
__________________
Rogue Shadow (TCN)(NAT)(Global Development Team)

For development help, contact the patrons of the #graaldt irc channel below, I am usually there.
Click Here to Join IRC Chat Now! -- irc.freenode.net Channel: #graaldt
Quote:
<Dustyshouri> no, RogueShadow is always talking about scripts lol
<Dustyshouri> in fact, he pretty much brought Graal back as a topic single-handedly
Reply With Quote
  #9  
Old 07-01-2002, 04:09 PM
Xbob42 Xbob42 is offline
Registered User
Join Date: May 2002
Posts: 429
Xbob42 is on a distinguished road
Unhappy

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.

__________________
Criminal uses this account to post.
Reply With Quote
  #10  
Old 07-01-2002, 08:18 PM
GrowlZ1010 GrowlZ1010 is offline
defunct
Join Date: May 2002
Posts: 187
GrowlZ1010 is on a distinguished road
Quote:
Originally posted by Xbob42
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.

I'll give it a try, lol.

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:

setarray test,4;

OR

test = {0,0,0,0};



... leaves you with:

NPC Code:

test[0]
test[1]
test[2]
test[3]



... which can all have different contents:

NPC Code:

test[0]=9;
test[1]=3;
test[2]=2.682475981347;
test[3]=-2;



That help?
Reply With Quote
  #11  
Old 07-01-2002, 10:42 PM
adam adam is offline
http://wiki.graal.us/
adam's Avatar
Join Date: Nov 2001
Posts: 2,247
adam has a spectacular aura aboutadam has a spectacular aura about
Send a message via AIM to adam
Quote:
Originally posted by adam
Yes.... Once you learn arrays...

You could do that same script in 1/6th the number of lines....

or less.....

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:

//-------------wrong thing----------//
if (this.value = this.othervalue) {
//do this;
}


//------------correct thing-----------//
if (this.value == this.othervalue){
//dothis;
}




Keep at it. You'll get it.
__________________
Rogue Shadow (TCN)(NAT)(Global Development Team)

For development help, contact the patrons of the #graaldt irc channel below, I am usually there.
Click Here to Join IRC Chat Now! -- irc.freenode.net Channel: #graaldt
Quote:
<Dustyshouri> no, RogueShadow is always talking about scripts lol
<Dustyshouri> in fact, he pretty much brought Graal back as a topic single-handedly
Reply With Quote
  #12  
Old 07-01-2002, 11:05 PM
GrowlZ1010 GrowlZ1010 is offline
defunct
Join Date: May 2002
Posts: 187
GrowlZ1010 is on a distinguished road
Quote:
Originally posted by adam

Also you need to use " == " instead of " = " in an if statement.
Actually, that's not compulsory. Scripts will run fine online and offline with a single equals. It's only suggested in the documentation to help keep with the C++/Java syntax.

Quote:
npcprogramming.doc:
You can also use some other symbols like ':=' for assignment and a single '=' for checking equality, but it's not recommended (to keep compability to the Java/C++ syntax).
It's suggested you use two. Not required.

If this sounded vaguely patronizing, then I apologize. No insult was meant. Just getting my point across.
Reply With Quote
  #13  
Old 07-01-2002, 11:14 PM
Saga2001 Saga2001 is offline
Wishing he had 3 feet
Join Date: Aug 2001
Location: Basement
Posts: 1,565
Saga2001 is on a distinguished road
Send a message via ICQ to Saga2001 Send a message via AIM to Saga2001 Send a message via Yahoo to Saga2001
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?
__________________

!Wan ( 11:27:55 AM):
can i c ur scripts please?
Zorg (RC): If I hear NPC Server call Ne0, Past Austin or Brent sexy one more time im disconnecting it
Reply With Quote
  #14  
Old 07-02-2002, 01:09 AM
Python523 Python523 is offline
Banned
Join Date: Aug 2001
Location: Illinois
Posts: 3,498
Python523 is on a distinguished road
Quote:
Originally posted by Saga2001
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?
Funny when I haven't deleted any posts at all unless they are posted after I close a thread by the same user asking for the same thing, but no, you have to go and point fingers at me, you have no evidence at all that I deleted this post yet you always blame me for everything and constantly harass me, get your facts straight before you open your mouth
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 04:37 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.