Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Why does this not seem to work? (array) (https://forums.graalonline.com/forums/showthread.php?t=33282)

konidias 07-11-2002 10:38 AM

Why does this not seem to work? (array)
 
NPC Code:
 setarray this.items,sarraylen(client.invitems);
for (a=0;a<this.items;a++;) {
this.items[a] = a;
}



I'm trying to make it set a variable array for "this.items".

client.invitems is just a string:
client.invitems=0,1,2,3,4

Now, it should set the array length to the string array length, which is 5. Then it runs a for loop to set each array slot to the proper value corresponding the string array.

So basically it should go:
client.invitems=0,1,2,3,4

translates to:
this.items{0,1,2,3,4}


But it isn't working. Any suggestions? :confused:

Falcor 07-11-2002 11:10 AM

Re: Re: Why does this not seem to work? (array)
 
Quote:

Originally posted by Kaimetsu
NPC Code:
 setarray this.items,sarraylen(client.invitems);
for (a=0;a<this.items;a++) {
this.items[a] = a;
}



When did you set this.items?

yeah, arraylen(this.items)

hehe, such little mistakes, such huge problems.

Python523 07-11-2002 11:10 AM

when you set an array, it usually looks something like this:
0/{0,0,0,0}
(that was if i set an array with a length of 4)
the 0 in front (the 0/) is actually the this.items (the rest being the array parts)
so your for loop right now is basically
for(a=0;a<0;a++)

Falcor 07-11-2002 11:15 AM

no hes referencing the value of this.items. This items has no value at all. no matter if the array contained data or not. this.items will never contain data unless it is set to contain it.

Python523 07-11-2002 11:16 AM

Quote:

Originally posted by Falcor
no hes referencing the value of this.items. This items has no value at all. no matter if the array contained data or not. this.items will never contain data unless it is set to contain it.
that's why I said the for loop is basically doing nothing since this.items isnt set to anything (which is 0), I probably shoud've used better wording for my post above

Falcor 07-11-2002 12:39 PM

well every variable defaults to zero. meaning false. So no data would be zero.

konidias 07-11-2002 08:50 PM

NPC Code:
 setarray this.items,sarraylen(client.invitems);
for (a=0;a<arraylen(this.items));a++ {
this.items[a] = a;
}



Okay, well isn't "set array this.items,..." setting the array length of this.items? So now that I have it comparing a to the arraylength of this.items, why is it still not working? The array length would be five, since I'm setting the arraylength of this.items to the client strings array length.

It's still not working, can someone tell me what I need to do instead of what I'm not doing right?

Python523 07-12-2002 01:36 AM

Quote:

Originally posted by konidias
NPC Code:
 setarray this.items,sarraylen(client.invitems);
for (a=0;a<arraylen(this.items));a++ {
this.items[a] = a;
}



Okay, well isn't "set array this.items,..." setting the array length of this.items? So now that I have it comparing a to the arraylength of this.items, why is it still not working? The array length would be five, since I'm setting the arraylength of this.items to the client strings array length.

It's still not working, can someone tell me what I need to do
instead of what I'm not doing right?

NPC Code:

setarray this.items,4;
for (a=0;a<arraylen(this.items);a++) {
this.items[a] = a;
}


that worked for me, maybe yours didnt because you had a simple typo or client.invitems wasnt set yet, you had
a<arraylen(this.items));a++
should be
a<arraylen(this.items);a++)

Aknts 07-12-2002 09:41 AM

NPC Code:

setarray this.items,sarraylen(client.items);
for (a=0;a<arraylen(this.items);a++) {
this.items[a] = strtofloat(#I(client.items,a));
}
this.items=arraylen(this.items);



I fixed it. It seems I have to use setarray before setting all the variable array values in the for loop, and then set the array to the it's own array length.

This works wonderfully, and it's the only way I know of converting a string array to a variable array. :)

Python523 07-12-2002 09:55 AM

it's like a konidias poser :O


All times are GMT +2. The time now is 06:15 PM.

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