| 02-07-2011, 03:49 AM | #1 |
K i've got a struct 'Item' which acts as a wrapper for each item in the game ~ it holds extra item info. Now here are some relevant snippets of code to show what I've got: JASS:type ItemArray extends Item array[100] struct ItemArea static ItemArray array items static integer array numItems endstruct function PutItemInArray takes nothing returns nothing local item it = GetEnumItem() local Item It = GetItemUserData(it) local integer rarity = It.typ.rarity //put Item into the array corresponding to its rarity set ItemArea.items[rarity][ItemArea.numItems[rarity]] = It set ItemArea.numItems[rarity] = ItemArea.numItems[rarity] + 1 endfunction Then I have a method which includes the following: JASS:set ItemArea.numItems[0] = 0 set ItemArea.numItems[1] = 0 set ItemArea.numItems[2] = 0 set ItemArea.numItems[3] = 0 call EnumItemsInRect(r, null, function PutItemInArray ) Now for my problem: the function PutItemInArray does something really screwy on me. It throws the item into all of the Item array in ItemArea.items instead of just the one i want. ie what its doing is instead of putting an item in .items[0][0], it'll put it into .items[0][0], .items[1][0], .items[2][0], .items[3][0]. I'm finding this completely demented as the integer 'rarity' only points the item into one of the Item Arrays, not ALL of them.. Is there something about dynamic arrays that I've missed? |
| 02-07-2011, 08:40 AM | #2 |
Dynamic arrays must be initialized.:struct ItemArea static ItemArray array items static integer array numItems static method onInit takes nothing returns nothing set .items[0]=ItemArray.create() set .items[1]=ItemArray.create() set .items[2]=ItemArray.create() // Repeat for all rarities. endmethod endstruct |
| 02-07-2011, 09:05 AM | #3 |
ohh right ty! but i ended up deciding to just be conventional and used a regular 2D array instead. |
