|
I am sending information from my item to my inventory. Telling the inventory to add the item. Gives me a null reference exception. Item.js : Inventory.js :
(comments are locked)
|
|
this is not a GameObject; its class is derived from MonoBehaviour. You use the correct semantics later on: Using the shorthand for this.gameObject works fine: However, you should use something other than an ArrayList; a List is probably what you want. Using .gameObject on item is useless; I don't even know why that compiles. i tried this but it gave me the same error.
Feb 21 '12 at 04:26 PM
MithosAnnar
i did not read: import System.Collections.Generic; you are absolutely correct. Thank you so much for the many and helpful replies!
Feb 21 '12 at 04:30 PM
MithosAnnar
Sorry, I tried to edit that line to be in the code, as I screwed up the initial answer, but QATO won't take the edit. If you get to the reputation level where you can edit the post, you can see that I actually committed the edit, but it won't display. I am not fond of QATO.
Feb 21 '12 at 05:08 PM
Jessy
yeah no problem(its a problem I get all the time), thanks all the same.
Feb 21 '12 at 05:10 PM
MithosAnnar
(comments are locked)
|

Why are you using an ArrayList if you're only putting one type in it?
the player may want more than 1 item in his/her inventory.
The error is occurring at the line in Inventory.js:
items.Add(item.gameObject);
Still got no idea why.
I'm not asking why you want a collection; I'm asking why you're using an ArrayList. You should only use that if you need to support multiple types.
Ok, im using it because it supports Add().