Actionscript Code:
var playerInventory:Array = ["potion", "potion", "ether", "phoenixdown"];
Actionscript Code:
var playerInventory:Array = []; // creates an empty array
function buyItem( itemType:String, price:int ) : void {
if (itemType == "potion") {
if (playerGold >= price) {
playerGold -= price; //subtract price
playerInventory.push(itemType); // adds item to the end of the array
}
} else if (itemType == "ether") {
if (playerGold >= price) {
playerGold -= price; //subtract price
playerInventory.push(itemType); // adds item to the end of the array
}
}
trace("inventory: " + playerInventory); // this will show all items in the inventory
}