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 01-29-2002, 02:40 AM
zell12 zell12 is offline
Gone
zell12's Avatar
Join Date: Jun 2001
Location: Alberta, Canada
Posts: 8,541
zell12 will become famous soon enough
Send a message via ICQ to zell12 Send a message via AIM to zell12 Send a message via MSN to zell12
Strings and Arrays >.<

ok, I need some help, Strings and Arrays are, I find, the hardest to script...
What are they used for, and can someone give me a good well explained example of them being used...
also, what are those "this.something"
commands for?
__________________
Reply With Quote
  #2  
Old 01-29-2002, 04:15 AM
amonrabr amonrabr is offline
Scripter
Join Date: Nov 2001
Location: Brazil
Posts: 374
amonrabr is on a distinguished road
Re: Strings and Arrays >.<

Strings are letters, you cant use math here...
Arrays, you can use more numbers, example: a={1,2,3...} if 5 is in a, do...
this.thing... It just has the number when you are online, when you reconnect you will lose this number.. example: this.a=1; if (this.a==1){do...} this flag just can be loaded in this npc. If a different npc has the same line, this.a=1; they are 2 differents numbers...
if you have 2 npcs in the same level, and you want that they are the same, you can use "level.thing"
Reply With Quote
  #3  
Old 01-29-2002, 10:06 AM
zell12 zell12 is offline
Gone
zell12's Avatar
Join Date: Jun 2001
Location: Alberta, Canada
Posts: 8,541
zell12 will become famous soon enough
Send a message via ICQ to zell12 Send a message via AIM to zell12 Send a message via MSN to zell12
umm... I don't get it anyway, your just confused me even more
__________________
Reply With Quote
  #4  
Old 01-29-2002, 11:36 AM
TDK_RC6 TDK_RC6 is offline
Registered User
TDK_RC6's Avatar
Join Date: Jan 2002
Location: Earth
Posts: 0
TDK_RC6 is on a distinguished road
well, lets see

strings can be alphanumeric such as stringname=1,stringies,34kald

you can replace parts of the string with replacestring stringname,index,newstring;
lets say you want to replace the word 'stringies' in the above string, so, you find the index, in this case, 1, you would do replacestring stringname,1,newstringies

you can access parts of the string with #I(stringname,index);
lets say you want to make a npc say the 34kald in stringname
so, message #I(stringname,2);

you can addstring extra strings to stringname with the addstring stringname,text;
lets say you want to add the string bluebellicecreamX2 to stringname, you would do addstring stringname,bluebellicecreamX2;

afterwards stringname=1,stringies,34kald would now be stringname=1,stringies,34kald,bluebellicecreamX2

well, more on strings and arrays tomorrow
__________________
Staff on Renegade


email: [email protected]
aim: papivicente
Reply With Quote
  #5  
Old 01-29-2002, 12:57 PM
BocoC BocoC is offline
Registered User
BocoC's Avatar
Join Date: Jun 2001
Location: Washington State, USA
Posts: 980
BocoC is on a distinguished road
Send a message via AIM to BocoC Send a message via Yahoo to BocoC
Ugh. Explaining arrays to Brandon was tough. Let me see:

Arrays are basically 1 variable that can hold multiple values. In Graal, arrays are 1 dimensional. Let's take a look at an array:

this.myarray={5,2,6,2,3};

This.myarray holds 6 independant values. You retrieve a value by putting the index of the value inside brackets [ ] after the variable:

this.myarray[2] returns the number 6. The letter 5 is index 0, 2 is index 1, 6 is index 2, ect, ect.

People normally use arrays to organize lots of similar data. Here is great use of arrays and keydowns:
NPC Code:

if (created) {
this.keys={0,0,0,0,0,0,0,0,0,0,0}; //Initialize an array with 11 values from 0 to 10
timeout=0.05;
}
if (timeout) {
GetKeys();
timeout=0.05;
}
function GetKeys() {
for (i=0;i<11;i++) this.keys[i]=keydown(i);
}


This will return the state of all 11 keydowns in a nice little variable called this.keys. You can then check if certain keys are down inside your code by checking a value in the array. If the D key was down, this.keys[4] will return 1.

I hope this helps. From my experience, I learned that teaching arrays is hard.
__________________
-Boco

FLKJH$TRFG*$(&%>FMG >REN<>F ;.kjsd
Reply With Quote
  #6  
Old 01-29-2002, 08:02 PM
TDK_RC6 TDK_RC6 is offline
Registered User
TDK_RC6's Avatar
Join Date: Jan 2002
Location: Earth
Posts: 0
TDK_RC6 is on a distinguished road
second edition

to set a string you would use the command setstring stringname,strings; lets say you want to set the string stringname with the value of 1, stringies, and 34kald, then you would do: setstring stringname,1,stringies,34kald :o

Arrays

Plain arrays are only numeric

you can initialize arrays two ways:
setarray arrayname,length;
arrayname={values,...}

you can change array variables many ways, but the most common (for me) is with arrayname[index]=newvalue;
so lets say you want a array of 4 different values and then set them to the current npcs hearts/mp/ap/direction, you would do the following;
setarray this.myvars,4;
this.myvars[0]=hearts; // Index 0 will be NPCs heart count
this.myvars[1]=mp; // Index 1 will be NPCs MP amount
this.myvars[2]=ap; // Index 2 will be NPCs AP amount
this.myvars[3]=dir; // Index 3 will be NPCs direction

you read values from arrays with arrayname[index], lets say you want the NPC to display his mp,direction,ap, and heart count, so you would:
message MP: #v(this.myvars[1]) Direction: #v(this.myvars[3]) AP: #v(this.myvars[2]) Hearts: #v(this.myvars[0]);

there are some other "commands" that help you find the length or arrays and stuff such as that

arraylen(arrayname); // For arrays
sarraylen(arrayname); // For string arrays

so, if you want to get the length of this.myvars from above, you would do
this.arraylength=arraylen(this.myvars);
this.arraylength is now equal to 4

if you want to find out the length of the above string, 'stringname', you would do
howlong=sarraylen(stringname);
no 'howlong' is equal 3
__________________
Staff on Renegade


email: [email protected]
aim: papivicente
Reply With Quote
  #7  
Old 01-29-2002, 09:11 PM
zell12 zell12 is offline
Gone
zell12's Avatar
Join Date: Jun 2001
Location: Alberta, Canada
Posts: 8,541
zell12 will become famous soon enough
Send a message via ICQ to zell12 Send a message via AIM to zell12 Send a message via MSN to zell12
Ok guys, that helpped me, somewhat... Thankz to my genuis scripter Screen Name, BocoC, and Kaimestu for correcting there posts
__________________
Reply With Quote
  #8  
Old 01-29-2002, 11:52 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
Ok better description of string arrays...i think...
NPC Code:

// Add Strings to server.vals
addstring server.vals,valueone;
addstring server.vals,valuetwo;
addstring server.vals,valuethree;
addstring server.vals,valuefour;
addstring server.vals,valuefive;
// Goes thru the server.vals array by finding out how many valuesa re in it with sarraylen()
for (i=0;i<sarraylen(server.vals);i++ {
// Searches for a string is the array and sets this.ret to the lindex it, (lindex is the position of the value in the array)
if (this.ret = lindexof(valueone,server.vals)) {
// Sets the player's chat to the string it found.
setplayerprop #c,#I(server.vals,this.ret);
}
}



hope it helped...i am worried i switched a few values, i think that #I is like this...#I(index,array)...:-/ if so, sorry, look in commands.rtf for any clarification. Also u can e-mail me if u wish, [email protected]...i can send you some sample scripts...

*phew* exhausted
__________________

!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
  #9  
Old 01-30-2002, 02:35 AM
zell12 zell12 is offline
Gone
zell12's Avatar
Join Date: Jun 2001
Location: Alberta, Canada
Posts: 8,541
zell12 will become famous soon enough
Send a message via ICQ to zell12 Send a message via AIM to zell12 Send a message via MSN to zell12
thankz, that helpped alot
__________________
Reply With Quote
  #10  
Old 01-30-2002, 09:31 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 Kaimetsu


Spelt my name wrong there, Joe.
One of these days someone should make a list:
Alias's and Mispellings of Kamietsu
Reply With Quote
  #11  
Old 01-30-2002, 09:38 AM
TheBig099 TheBig099 is offline
Registered User
Join Date: Jan 2002
Location: Québec!
Posts: 122
TheBig099 is on a distinguished road
Send a message via AIM to TheBig099 Send a message via Yahoo to TheBig099
I dont understand anything and i think ill never...
I guess i should stick to gfxs and level making
__________________
~2nd_wolf
Co-owner of Mystical marlee
non-p2p server
url: http://www.mysticalmarlee.f2s.com
Reply With Quote
  #12  
Old 01-30-2002, 10:18 AM
TDK_RC6 TDK_RC6 is offline
Registered User
TDK_RC6's Avatar
Join Date: Jan 2002
Location: Earth
Posts: 0
TDK_RC6 is on a distinguished road
its not that hard really, you just have to pratice
__________________
Staff on Renegade


email: [email protected]
aim: papivicente
Reply With Quote
  #13  
Old 01-30-2002, 10:24 AM
zell12 zell12 is offline
Gone
zell12's Avatar
Join Date: Jun 2001
Location: Alberta, Canada
Posts: 8,541
zell12 will become famous soon enough
Send a message via ICQ to zell12 Send a message via AIM to zell12 Send a message via MSN to zell12
I didn't really under stand it either, I just printed it off... then recorded it on to my recorder thingey, an playered it all ngiht... Now I can like say everything off by heart
__________________
Reply With Quote
  #14  
Old 01-30-2002, 11:15 AM
Faheria_GP2 Faheria_GP2 is offline
Banned
Faheria_GP2's Avatar
Join Date: Oct 2001
Posts: 1,177
Faheria_GP2 is on a distinguished road
Quote:
Originally posted by BocoC
Ugh. Explaining arrays to Brandon was tough. Let me see:

Arrays are basically 1 variable that can hold multiple values. In Graal, arrays are 1 dimensional. Let's take a look at an array:

this.myarray={5,2,6,2,3};

This.myarray holds 6 independant values. You retrieve a value by putting the index of the value inside brackets [ ] after the variable:

this.myarray[2] returns the number 6. The letter 5 is index 0, 2 is index 1, 6 is index 2, ect, ect.

People normally use arrays to organize lots of similar data. Here is great use of arrays and keydowns:
NPC Code:

if (created) {
this.keys={0,0,0,0,0,0,0,0,0,0,0}; //Initialize an array with 11 values from 0 to 10
timeout=0.05;
}
if (timeout) {
GetKeys();
timeout=0.05;
}
function GetKeys() {
for (i=0;i<11;i++) this.keys[i]=keydown(i);
}


This will return the state of all 11 keydowns in a nice little variable called this.keys. You can then check if certain keys are down inside your code by checking a value in the array. If the D key was down, this.keys[4] will return 1.

I hope this helps. From my experience, I learned that teaching arrays is hard.
gawd, use setarray
Reply With Quote
  #15  
Old 01-30-2002, 11:25 AM
Falcor Falcor is offline
Darth Cucumber
Falcor's Avatar
Join Date: Mar 2001
Location: At School
Posts: 2,874
Falcor is on a distinguished road
Send a message via ICQ to Falcor Send a message via AIM to Falcor Send a message via MSN to Falcor Send a message via Yahoo to Falcor
oh brother
__________________

subliminal message: 1+1=3
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 10:35 AM.


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