In Game Inventory Question

Could someone help me with this, i want to create a normal inventory for my game.
By ‘normal’ i mean a simple menu that has a picture (or a smaller 3D model) of the items i have collected, also i want it to keep score of how much of that item i have. I will also be thankful if you could tell me how to have an item be discarded once its used (like…instead of having 100 keys i’d have 99 once i use one of them)

I cant think of a way to make that sort of inventory, all i can figure it is how to access that screen.

Also as a secondary question, how would i carry the inventorys information onto the next level or room my character enters?

Thank you! :smiley:

This could be done with logicbricks… but it would be a huge pain. You’d probably have to designate a single slot for a single type of item, and no other item could ever appear in that slot (even if you didn’t have that item). You could do this with different properties like “Sticks” and “Stones”. If that property were 0, nothing would be displayed in that slot… if it were greater than that, it’d make the slot “visible” and maybe have a font type object.

A real inventory system would require python, and should be relatively easy to do with lists or dictionaries (data types in Python). You’d have a function to add the object to the list, and then another function to display the items in the list on your screen.

That’s the general idea… but it’s a complicated thing to have. If you’ve not learned Python yet, now would be a great time to do it.


ahh, thank you!

hmm…i still cant figure it out.
Ive looked at some blender games to try and reverse engineer their inventory system but i just cant understand it.
Ive also tried using logic bricks but i havnt come across the right solution yet.

What i really need is someone who knows how to make a normal inventory system (the kind with say…6 slots for an item you pick up) the best example of this is in the resident evil games, i need to someone who knows how to make that and explain it to me in a tutorial sort of way in some detail (explaining how to go about doing something and how something works, like how the item gets transfered to the inventory, how to discard 1 of that item once its used etc.)

Ive even looked on the internet and searched on this site, but nothing helps and no one really explains how to make an inventory properly.

(the best kind of tutorials in my opinion are ones that assume everybody is new at it. I find them to be explained alot more clearly.)

If someone can do any of that for me, it’ll be a great help. Once i know how to do the item/ inventory system i can finaly start making my game.


Did you see these?:

You could use python.

import GameLogic as g
g.inventory = [[‘keys’, 100][‘bars’, 50][‘drinks’, 25]]

for i in g.inventory:
if i[0] == ‘keys’
i[1] -= 1

Something like that.
Using GameLogic as g and using g.inventory makes it part of the GL directory, and thus global through all scene changes, but not game or blendfile changes.

( I know it’s b****** code)

I wouldn’t recommend putting in on GameLogic as GameLogic is cleared every time a new scene loads. As an alternative you can put it on GameLogic.globalDict, e.g:

GameLogic.globalDict['inventory'] = {}
GameLogic.globalDict['inventory']['keys'] = 100[/code
Or, if you're feeling adventurous you can make a module. Just make a text file (blender text file that is) called then you can do things like this:

import cPickle

items = {}
armour = {}
weapons = {}

def save(file):
global items, armour, weapons

data = {}
data['items'] = items
data['armour'] = armour
data['weapons'] = weapons

file = open(file, "w")

pickle = cPickle.Pickler(file)



def load(file):
global items, armour, weapons

file = open(file, "r")

pickle = cPickle.Unpickler(file)

data = pickle.load()
items = data['items']
armour = data['armour']
weapons = data['weapons']


def use_item(item, amount):
global items, armour, weapons
if item in items:
if items[item] >= amount:
items[item] -= amount

You can access that module by doing (in a different script/module):

import Inventory

Add items to the inventory

Inventory.items[‘key’] = 100
Inventory.items[‘gold’] = 50

Use items

if Inventory.use_item(‘key’, 1):
print ‘key used!’
print ‘not enough keys :(’

Weapons and armour:

Inventory.weapons[‘sword’] = 2
Inventory.armour[‘shield’] = 23562 # <-You can never have to many shields

Save and load‘inventory.txt’) # inventory.txt is the filename
Inventory.items[‘gold’] += 1000 # add some gold…
print Inventory.items[‘gold’] # heaps of gold!

print Inventory.items[‘gold’] # not so much gold :frowning:

Do display the items, weapons and armour more tricky. You need to add objects, heres the gist of that:

Inventory Drawing

import Inventory

cont = GameLogic.getCurrentController()
add_object = cont.actuators[‘add_object’] # an add object actuator

def init():
Inventory.objects = [] # make a list for storing all the objects used in drawing the inv.

def draw_items():
x = 0 # co-ordinates for the objects
y = 0
z = 0
for item in Inventory.items:
add_object.object = ‘btn_bg’ # ‘btn_bg’ is a plane that will be a button
add_object.instantAddObject() # add the object
ob = add_object.objectLastCreated # create a variable for that object
ob[‘item’] = item # assign an ‘item’ property to the button for future reference
ob.position = [x,y,z] # move the button

    add_object.object = 'Text' # a real time text object
    ob = add_object.objectLastCreated
    ob['Text'] = item
    ob.position = [x - 0.4, y - 0.4, z + 0.1] # we add some spacing on the text so its close to centered
    y += 1 # increment the y ordinate so it offsets the next object

if not has_attr(Inventory, ‘objects’):

The above codes not complete but after reading up on python you should be able to polish it off (making the buttons work by using mouse over sensors and left click sensors).

Phew, big post.

ah, thank you for the codes! =D