![]() |
Retrieving a subarray?
Assuming I even know what I'm talking about, I've run into a problem where I cant seem to get the npcserver to check arrays within an array.
for example: PHP Code:
PHP Code:
I could do something like if("b" in this.somearray[0]) but then theres the obvious problem that it wont check this.somearray[1]. Any advice? |
When using the in operator, Graal is checking whether the specified element is inside the specified array. Since the specified array only contains two other arrays, "b" can't be found using the in operator.
|
so if i cant use in what should i use?
|
The only way I can think of...
PHP Code:
|
Okay, I've now laid out the arrays in this manner:
Array 1 contains two arrays (Array 2 and Array 3). One contains valid equip types. the other contains valid armor types. Array 2 contains the multiple main weapon groups (sword axe etc). And contains the various weapon subgroups. (short sword, long sword etc. would be under the sword group.) (the subgroups are arrays) Array 3 contains the multiple main armor groups (armor, accessories, etc). In this array are more arrays containing the various armor subgroups. I've somehow managed to end up with this: PHP Code:
edit:Actually, I could probably figure the rest of this out myself if i could explicitly understand how for loops work. Since it's absolutely impossible to search for this myself, what with the fact that 3 letter words are ignored by the search feature, and the graalbible nets you hundreds of unrelated results, does anyone have like a link on a tutorial on this or something? ยบ_o; |
for (a: b) { ... } means that b should be an array, and the {} block is going to be executed once for every element in b, with a refering to each element in turn.
If b was an array of two sub-arrays, then the {} block would be executed twice, once with a as the first subarray and once with a as the second subarray. : is magical as part of the for thing here, the : in ? : is something different: (a ? b : c) is an expression that is going to return b if a is true and c if a is not true. It tends to be a good idea not to use ? :. Hope this helps. |
Quote:
|
Quote:
NPC Code:int bytesCount = c >= 0xfc ? 5 : |
Quote:
|
Since arrays are strings, you can use variable.pos("b") if you know what kind of data you're receiving each time.
You should try a different approach instead of having multi-dimensional arrays. |
Quote:
|
Well if you're making an equipment system there's quite a few ways you can store the information:
PHP Code:
or simply: PHP Code:
Of course the examples above will have to be modified to meet your needs, and proper flags. |
Quote:
PHP Code:
|
| All times are GMT +2. The time now is 01:29 AM. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.