Re: The basics of inventory

the way I would code an inventory is as follow.
Let's start from the inventory item which is the easiest.
An inventory item is just a plain object which has 2 properties: name and amount.
An inventory, is an object which acts as a manager for items.
This inventory has an array/list which contains the inventory items.
It should have some utilities function which can help you retrieve information from the objects stored in it.
get_item(name) should allow you to retrieve an object which is contained in the object list if the name matches, and if the item in question exists.
item_exists(name) should check if the inventory item with the specified name is contained in the array/list containing the object.
add(name, amount) should allow you to add an other item to the inventory. If the item is already present, then that item would just receive the amount specified. Hope I was clear enough.

-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
  • ... AudioGames . net Forum — Developers room : Zarvox via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : pauliyobo via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : visualstudio via Audiogames-reflector

Reply via email to