Re-using inventory slots
Hi all, been building a point and click game and found a problem with my inventory system which is
when an item is added to the inventory and then used, another item will not re-use it's slot.
Code:
Place an instane of InvMC on the stage:
this.attachMovie('inventoryMC', 'invMC', depth);
setProperty("invMC", _x, "30.65");
setProperty("invMC", _y, "665");
within the invMC declare an array to handle 20 slots:
aryInv = new Array(19);
for(i=0;i<20;i++){
aryInv="none";
}
Place 20 instances of "slotMC" within the inventory MC, number them "inv1", "inv." etc. Then
on each one put this code changing t=0 to t=1, t=2 etc:
onClipEvent (enterFrame) {
t = 0;
if (_root.invMC.aryInv
gotoAndStop(1);
}
if (_root.invMC.aryInv
gotoAndStop(2);
}
if (_root.invMC.aryInv
gotoAndStop(3);
}
if (_root.invMC.aryInv
gotoAndStop(4);
}
if (_root.invMC.aryInv
gotoAndStop(5);
}
if (_root.invMC.aryInv
gotoAndStop(6);
}
if (_root.invMC.aryInv
gotoAndStop(7);
}
if (_root.invMC.aryInv
gotoAndStop(8);
}
if (_root.invMC.aryInv
gotoAndStop(9);
}
if (_root.invMC.aryInv
gotoAndStop(10);
}
if (_root.invMC.aryInv
gotoAndStop(11);
}
if (_root.invMC.aryInv
gotoAndStop(12);
}
if (_root.invMC.aryInv
gotoAndStop(13);
}
}
Put 20 frames into "slotMC" with an MC of each item on the frames. Put this code on the item MCs:
(slightly different targets etc for each item).
on (release) {
if (_global.key1vis == 1) {
startDrag("", true);
_global.key1vis = 2;
} else if (this.hitTest(Object(this._parent).sqReturnTarget)) {
stopDrag();
setProperty(this, _x, 15.95);
setProperty(this, _y, 16.45);
_global.key1vis = 1;
} else if (this.hitTest(Object(_root).gateKeyTarget)) {
this.unloadMovie();
_global.key1vis = 2;
setProperty(_root.gateKeyTarget, _visible, 0);
_root.gotoAndStop("gates open");
_global.castleGatesOpen = 2;
}
}
This works great - except each item takes the next numerical slot even if the previous one has been "vacated" by the item
the user has got rid of - so what do I need to do allow items to use up acted "slots" ?
All and any advice much appreciated - files available if it will help !
Best wishes
Tony