Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   arrays (https://forums.graalonline.com/forums/showthread.php?t=25353)

la_builder 03-10-2002 05:31 AM

arrays
 
i dun know nothing about arrays yet i read npc programming bud tough i dont understand and i dun even know where arrays are good for ,can some teach me in this:megaeek:

nyghtGT 03-10-2002 05:40 AM

http://razza.org/tormented/php/variables.php

I believe I have something bout regular variable arrays, but not string arrays ...

screen_name 03-10-2002 05:43 AM

quite simple

a array is like a lot of variables all in one variable

u can set variables like this:

arrayname={0,0,0}

or setarrary arrayname,3;

each would produce the array, arrayname={0,0,0}

and u can use variables out of the array by using indexes, like this

lets say there is a array 'nums' and it is equal to {3,5,7}
say2 #v(arrayname[index]);
so if the index was 2 it would show 7

u must remember that the indexes start with 0, not 1

so

nums[0] - 3
nums[1] - 5
nums[2] - 7

also, if you want to set a value in a array, just do this:

arrayname[index]=whatevervarialbe;

Python523 03-10-2002 08:04 AM

also, there are string arrays, there are specific commands for them:
(from newfeatures2001.txt)
addstring list,text;
insertstring list,index,text;
replacestring list,index,text;
removestring list,text;
deletestring list,index;
sarraylen(list)
lindexof(list,text)
#I(list,index)

screen_name 03-10-2002 09:57 AM

he first needs to learn the basics of arrays, then string arrays should come in

Python523 03-10-2002 10:49 AM

Quote:

Originally posted by screen_name
he first needs to learn the basics of arrays, then string arrays should come in
I don't find any of them hard, string arrays are probably the easiest, I thought they were normal strings until I found out they were string arrays

nyghtGT 03-10-2002 01:23 PM

would someone mind explaining string arrays to me (accesing them, settings them, etc.) and hopefully if I learn em i'll write ai little tutorial for them ...

la_builder 03-10-2002 09:24 PM

mmm.. ok i understand it. bud what will an array be good for i know its a noobish question:( i mean what will it come in handy for.

amonrabr 03-10-2002 10:36 PM

Re: arrays
 
Quote:

Originally posted by la_builder
i dun know nothing about arrays yet i read npc programming bud tough i dont understand and i dun even know where arrays are good for ,can some teach me in this:megaeek:
its simple.. you have 2 balls in different positions.. so..
ballsx={1,2} //arrays
ballsy={1,2} //arrays

ballsx[1]= 12;
ballsy[1]= 10;
ballsx[2]= 13;
ballsy[2]= 9;

or u can use it in any other place where you have 1 name but more numbers for it...

la_builder 03-11-2002 12:09 AM

oo now is see thanks everyone:D
:( and some bad news another noobish question

NPC Code:
 if(playerenters) { putleaps 3,24,23;sleep 5; putleaps 3,2,5}

how do i loop this so it keeps repeating

Python523 03-11-2002 12:39 AM

Quote:

Originally posted by la_builder
oo now is see thanks everyone:D
:( and some bad news another noobish question

NPC Code:
 if(playerenters) { putleaps 3,24,23;sleep 5; putleaps 3,2,5}

how do i loop this so it keeps repeating

...
if (created||timeout){
putleaps 3,24,23;
sleep 5;
timeout=.05;
}

la_builder 03-11-2002 03:33 AM

thanks

screen_name 03-11-2002 04:25 AM

i have never tried this, but would it work??

NPC Code:

if (playerenters) {
message #v(random(0,1));
sleep 3;
callnpc npcid,playerenters;
}



shouldnt that make the npc repeat ??

nyghtGT 03-11-2002 04:48 AM

Quote:

Originally posted by screen_name
i have never tried this, but would it work??

NPC Code:

if (playerenters) {
message #v(random(0,1));
sleep 3;
callnpc npcid,playerenters;
}



shouldnt that make the npc repeat ??

maybe, but it might lag ...

nyghtGT 03-11-2002 04:53 AM

Quote:

Originally posted by Kaimetsu


Yes, but I couldn't guarantee that it would get the timing exactly right - it could have 1.05 seconds between calls occasionally etc. Plus does "npcid" work? I thought it'd just be "id".

i usually would just do something like this ...
NPC Code:

NPC Code:

if (playerenters) {
message #v(random(0,1));
sleep 3;
for (i=0;i<npcscount;i++) {
callnpc i,playerenters;
}
}




nyghtGT 03-11-2002 04:56 AM

Quote:

Originally posted by Kaimetsu


Woah, that's crazy. Then every NPC in the level will run all its initialisation scripts and break up whatever it's doing!

I meant that just for the general idea, I knew what would happen ...

nyghtGT 03-11-2002 05:02 AM

Quote:

Originally posted by Kaimetsu


All in all, I think we can agree that timeouts win the day.

yea ...
:D

screen_name 03-11-2002 05:21 AM

i know that callnpc isnt immediate

and i do agree that timeouts rule

la_builder 03-11-2002 05:43 PM

question agian is it possible to run to npc at a time in one and the same npc editor screen.So i mean that the scripts do there stuff at the same time.

la_builder 03-11-2002 06:25 PM

.....sorry is it possible to fuse 2 diffirent npc' s in one npc.Bud tough they would run at the same time.Can understand me now.:)

la_builder 03-11-2002 08:52 PM

bud wouldnt this do first the x than the y.
let me explain i need to make a pw system and i need to fuse a putleaps with a rain script clear so far?Now i wanna make sure the diong 2 things at 1 time like putting the leaps and raining.
so the wont do putting leaps first and after that rainging uderstand me

la_builder 03-11-2002 09:02 PM

NPC Code:
 raining script<--after this i put ;putleaps 5,34,12;



wouldnt it start raining and put the laps after the end of the raining script.so it will stop raining and than start putting laps

screen_name 03-11-2002 09:11 PM

Quote:

Originally posted by Kaimetsu


Then I suggest you buy a quantum computer, because they're the only kind I know of that can work on two separate tasks simultaneously. But if you're content for it to merely LOOK like everything's happening at once then the script I showed you would work fine. There would be no way for the player to know which of x or y was changed first.

:D

la_builder 03-11-2002 11:14 PM

thanks dude

Saga2001 03-12-2002 01:17 AM

Arrays.
 
Ok, I am goona bust this out supreme style...but I wanted to ask,, I have never used the callnpc command, so could someone tell me about it? Anyway, heres a supreme explanation of arrays. ;)

Arrays are basically values that contain other values, like a long string of numbers (unless unsing string arrays), that can be called and changed, it is one of the best ways I know of to keep organized. Also there are so many great values to arrays, you will end up using them in practiallcy every script. So what I will first define is the different ways to create your arrays. The first way is to actually use the setarray name,size; command.
NPC Code:

setarray this.rainx,100;
setarray this.rainy,100;


The second way of setting arrays is through curly brackets.
NPC Code:

this.rainx = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
this.rainy = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1};



The next thing I will discuss is getting and setting values of arrays. Ok, there are so many ways of actually setting the values, the first I will explain is the simple one.
NPC Code:

setarray this.rainx,100;
setarray this.rainy,100;
this.rainx[0] = 10;
this.rainx[1] = 15;
this.rainy[0] = 5;
this.rainy[1] = 10;


Something to always remember is that arrays start on the value 0 not 1, so the first value in the array is 0 and the last it the arraysize-1. The previous way of setting the array value is best for when setting only one or two values, the next way I will show you is a way for setting arrays when multiple values are needed
NPC Code:

this.rainx = {1,1,1,1,1,1,1,1,1,1};


This will set this.rainx with 10 values with 1 as each, this is a good way when having specific values that will be consistant thruout the script. The next thing I will explain is how to use a for loop to generate random values for an array using the arraylen() variable. If you call arraylen(this.rainx) on the previous example, it will return 10, because it measures how many values are in the array. So using this you could measure the size of an array with undefined values set with setarray; as in this example.
NPC Code:

setarray this.rainx,100;
for (i=0;i<arraylen(100);i++;)
this.rainx[i] = random(0,100);


The next thing I will explain is how to call array values, as in this example.
NPC Code:

setarray this.rainx,100;
for (i=0;i<arraylen(100);i++;) {
this.rainx[i] = random(0,100);
setplayerprop #c,#v(this.rainx[i]);
sleep .05;
}


So this correctly reads the value and sets the player's chat to the random value. The next thing I will exaplin is how to read values and act on them.
NPC Code:

setarray this.rainx,100;
for (i=0;i<arraylen(100);i++;)
this.rainx[i] = random(0,100);
if (this.rainx[5]>=3)
setplayerprop #c,this.rainx[5] is more than or equal to three, its exact value is #v(this.rainx[5]);
else
setplayerprop #c,this.rainx[5] is less than three, its exact value is #v(this.rainx[5]);


Another very little known fact, is that the value is set as it goes, so in this example, all values will be set correctly.
NPC Code:

this.rainx = {32,this.rainx[0]-10,this.rainx[0]-15};


This can be used very often when writing code that depends on other values. Also you can include conditions in arrays like so (if you don't know what a condition is, it can be an if statement or a block like this num = (a==0 ? 1 : 0) what this does is, if a equals 0 than num equals 1 otherwise it equals 0).
NPC Code:

this.rainx = {32,(this.rainx[0]>0 ? 1 : 0),this.rainx[0]-15};


I need to go now, so that is all I will explain for now, maybe later later. I hope that was useful.

la_builder 03-12-2002 03:26 AM

thanks thats really usefull you should make a tutorial

la_builder 03-12-2002 03:38 AM

NPC Code:
//Rain Array by -=GodSpeed=-
--Removed by Kaimetsu--



for example how would i fuse this with this
NPC Code:
// NPC made by Discounter{hiring lats}
if (created||timeout)

putleaps 5,13,36;sleep 2;putleaps 5,30,33
;sleep 2;putleaps 5,70,60;sleep 5
;putleaps 5,50,40; sleep 2;putleaps 5,12,50;sleep 2;putleaps 5,19,23;sleep 3;putleaps 5,14,32;sleep 2;putleaps 5,36,10;putleaps 5,38,33; sleep 3;putleaps 5,34,11;sleep 4;putleaps 5,12,50;sleep3;putleaps 5,30,40;putleaps 5,playerx,playery;timeout=0.5;}



i want them to work at the same time so rain with the putleaps.Some how i still cant get it to work.

Saga2001 03-12-2002 06:49 AM

NPC Code:

--Removed by Kaimetsu--
--Respected by PastAustin--


poor god speed, using his script.
this should work...

Saga2001 03-13-2002 12:49 AM

Quote:

Originally posted by Kaimetsu
GodSpeed might not be here, but I'm sure he doesn't want his scripts posted all around the place, and he certainly doesn't want them stolen for playerworlds.
Well just as a comment, I showed how to fix that, not so it could be used for a playerworld, but to teach someone to script better. La_builder, if i see it on a playerworld you work on, man I would talk smack about that server. I am friends with GodSpeed personally, and I do not think he would really care less, but I will respect the thought and delete it from my previous post, not that it would do anything, because it was already posted by la_builder. La_builder, if you can't script your own weather system, than you don't deserve to use that one.

la_builder 03-13-2002 01:57 AM

aaaaaaaaaaahhhh flipping read example jeez i not meant to use it for my self or something i wanted to post a example caus i didnt feel like posting my own rain thunder time day night script

la_builder 03-13-2002 02:01 AM

i feel so omg dumb i should knew that you where begining to say "o my he stole a script" or something


so agian IM NOT STEALING ANYTHING FROM ANYONE {EXAMPLE} :megaeek:

la_builder 03-13-2002 03:48 AM

well after asking three times i got sick of people not understanding me (thats my fault this is my second year english )
so i tought why dont post an EXAMPLE and make my self clear that way.

Python523 03-13-2002 11:25 AM

1 Attachment(s)
Quote:

Originally posted by la_builder
i feel so omg dumb i should knew that you where begining to say "o my he stole a script" or something


so agian IM NOT STEALING ANYTHING FROM ANYONE {EXAMPLE} :megaeek:

This picture says it all
[EDIT]
The colors got a little messed when I converted it from a bmp to a gif but here's the limit of my talent with gfx =o
[/EDIT]

Saga2001 03-14-2002 01:28 PM

Quote:

Originally posted by Kaimetsu
I understood you. You just weren't listening to my responses.
Its true that you don't need to post a huge script to implement small things.
Sorry Kai, I was just trying to help...


All times are GMT +2. The time now is 05:07 PM.

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