boneyabba
12-19-2007, 11:07 AM
I am making a small item trading game where the player moves from store to store trying to buy low and sell high. The mechanism for this is a backpack system similar to the game Diablo... Basically a store is a 6x5 grid, the player's backpack is a 3x4 grid, and the items are either 1x1 or 2x2. The store, and player inventories are just arrays with item names.
When the player arrives at a store I read the inventory arrays, and use a loop to create instances of the various inventory item objects. The player sees the store grid, and the backpack grid with these instances. They can move items from one to the other freely, each time an object is dropped from the store to the backpack, or vice versa, the inventory arrays are updated.
I have my code working to read the arrays, and populate the store grid. But I can't figure out how to manage the instances. I globally define a variable that is referenced to a linked object at the start of my AS:
var _inventoryItemTypeA = InventoryItemTypeA_mc
Then, when the loop reads that the inventory array is full of, say 5 of these... I do like this:
var _itemsPlaced:Number = 0
if (_itemsPlaced < _storeInventory.length)
{
_inventoryItemTypeA.addEventListener(blahblah)
_inventoryItemTypeA = new InventoryItemTypeA_mc
addchild(_inventoryItemTypeA)
_inventoryItemTypeA.x = blah
_itemsPlaced = _itemsPlaced + 1
}
So, it places all my stuff. But it is clear that the addEventListeners and the removeChild stuff I haven't written needs to know how to tell the different instances apart... I can't figure out where to look.
Answers are good- but I'd be just as stoked if I was pointed to the right tutorials. I am the suck at finding the right tutorials.
Thanks,
T
When the player arrives at a store I read the inventory arrays, and use a loop to create instances of the various inventory item objects. The player sees the store grid, and the backpack grid with these instances. They can move items from one to the other freely, each time an object is dropped from the store to the backpack, or vice versa, the inventory arrays are updated.
I have my code working to read the arrays, and populate the store grid. But I can't figure out how to manage the instances. I globally define a variable that is referenced to a linked object at the start of my AS:
var _inventoryItemTypeA = InventoryItemTypeA_mc
Then, when the loop reads that the inventory array is full of, say 5 of these... I do like this:
var _itemsPlaced:Number = 0
if (_itemsPlaced < _storeInventory.length)
{
_inventoryItemTypeA.addEventListener(blahblah)
_inventoryItemTypeA = new InventoryItemTypeA_mc
addchild(_inventoryItemTypeA)
_inventoryItemTypeA.x = blah
_itemsPlaced = _itemsPlaced + 1
}
So, it places all my stuff. But it is clear that the addEventListeners and the removeChild stuff I haven't written needs to know how to tell the different instances apart... I can't figure out where to look.
Answers are good- but I'd be just as stoked if I was pointed to the right tutorials. I am the suck at finding the right tutorials.
Thanks,
T