- Title: Example-Inventory / Example-Inventory-Lite
- Description: An example of how to do an inventory system in your game.
- GM Version: GM81,
- Registered: Yes and no
- File Type: .gm81, .gmk
- File Size: 212 kB registered, 213 kB lite
- File Link: (Registered: .gm81, .gmk) (Lite: .gm81, .gmk)
- Required Extensions: None
- Required DLLs: None
This example shows one of many inventory systems, using a ds_grid for an item database, and the inventory itself. The inventory can have a maximum number of items to be held in it, and the item database can be added to at any time in the game, even if the initial size is reached, by extending the grid. The whole inventory can also be drawn and interacted with, only using one object. With the Lite version, arrays are substituted for the grid.
The shops are done in the same manner, though they are a grid that is created by a shopkeeper, and is removed when the shop is closed to conserve memory. The scripts that this example includes are:
- inv_init() > Create the grids and input the initial values
- new_item(name, description, sellPrice, buyPrice, maximumQuantity, sprite) > Easily add an item to the item database
- update_item(index, field, replacement) > Change the information about the item in the item database
- inv_read(slot, value) > Get the item index or the quantity of the item in the slot
- itemdb_read(index, value) > Get information on an item by using it's index or name
- inv_add(item, quantity) > Add the given amount of an item to the inventory
- inv_buy(item, quantity) > The the item to the inventory, and subtract the buying price from the money variable
- inv_subtract(slot, quantity) > Remove the amount of items from the slot of the inventory
- inv_sell(slot, quantity) > Remove the items from the inventory, and add the selling price to the money variable
- new_shop() > Make a new shop
- shop_add(item) > Add the item to the shop's merchandise
- shop_close() > Close the shop, freeing the memory used
- shop_get(slot) > Get the item from the shop in the slot
- findInItemDB(item) > Find the index of the item in the item database (only in Lite version)
- findInInventory(item) > Find the slot the item is in in the inventory (Lite only)
Along with the inventory and shop, this example also shows a simple top down movement and collision system with doors, how to add a font from a sprite, how to do a custom cursor with the cursor turned off, and a pause system.
All code is commented and described so that you will hopefully be able to understand how it works.
If any more features are requested, I will be happy to add them in!
This example also includes a script by Ivaxlar for wrapping strings to a certain width.
Edited by thegame, 26 August 2012 - 04:01 PM.