Inventory script help?

Hello today i was watching “Blender game engine tutorial: Inventory” by Goran milovanovic, and found out that some of the coding is out-of-date and won’t work. Can someone please provide an updated tutorial of coding of his Inventory script or maybe your own Inventory script that i could use? link to his tutorial: Thank you for any help in advance.

is this inventory persistent at scene changes?

I was looking for where if i press “i” then it will open the inventory.

How is it “out-of-date”? What is the problem exactly?

If you can be specific, I can probably help you.


I think it should be. However, the purpose of a tutorial is to teach, not to provide “ready to use” systems.

When i go to play the game it does not add 4 cell boxes instead nothing shows up it is just blank. Here is what i have for the code:

from bge import types, logic, render


class Inventory(types.KX_GameObject):
def init(self, own):

    scene = logic.getCurrentScene()
    self.cells = cells[]
    for i in range(self("len")):
        cell = Scene.addObject("Cell", self)
        cell.worldPosition.x += i * 3

def main(cont):
own = cont.owner

if not "init" in own:
    own["init"] = True
    own["len"] = 4
    own = inventory(own)

Im looking for one so that when i press “i” it opens the inventory.

Please just code tags when posting code snippets!

As Monster said, you need to use code tags, but in this case, I would say that a .blend would be more effective.

That said: Just because you’re not getting the same results, doesn’t mean that the tutorial is “outdated”. It’s more likely that you simply didn’t do exactly what was done in the video.

up until 7:20 of the video i believe i did everything right give or take where my boxes are compared to yours. But also when i add an empty it ask me a few things to choose i just choose “plain axes”, i don’t know if that would affect it or not. here is the blend file:

Inventoryscript.blend (446 KB)

I looked at the code… Basically I just fixed the errors in the console (which you should look at before asking on the forum) and it worked.

Most of the errors were raised on misspelled methods and objects.
For instance, you’re inheriting an object from “types” into your Cell and Inventory object that doesn’t exist (KX_GameObjects isn’t the same as KX_GameObject).

Also, fyi, Python is case sensitive.

On top of that, you’re not running the main method in You need to run that piece of code before you see anything.

So keep these things in mind when you fix your code:

  1. Make sure you’re running the necessary code.
  2. Make sure everything is spelled correctly.

Just look in the console to locate the errors.

Im sorry i did not notice. I use python a little just getting use to all the modules for blender is a bit difficult. Thank you all for the help. :slight_smile: