Building an Inventory - Problem with adding the object

Hello all!

I’m trying to build an inventory and have encountered a problem. My setup and idea behind it goes like this:

I have an Inventory object in the overlay scene. I have an actor in my game scene and a demoobject I want to add to the overlay scene,parent that new object to the inventory and then remove the original from the game scene.
So for the triggering I chose a touch sensor because I know how to build it and know that it works. When the demoobject gets touched by the actor it sends a message to the inventory object, which reads the message, gets the object and should add it to the scene.

Only it doesn’t add it to the overlay scene but to the game scene.

The scripts look like this:
the sending script looks like this:

import bge

cont=bge.logic.getCurrentController()
obj=cont.owner
act=obj.actuators
messageact=act[0]
print(obj)
messageact.body=obj.name
overlay=bge.logic.getSceneList()
print(overlay)
print(messageact.body)

and the recieving script like this:


import bge
print("getscalled")
overlay=bge.logic.getCurrentScene()
con=bge.logic.getCurrentController()
inv=con.owner

itemget=con.sensors["Message1"].bodies[0]
print(itemget)
Scenelist=bge.logic.getSceneList()
Gamescene=Scenelist[0]
print(Gamescene)
Item=Gamescene.objects[itemget]
print(Item)

overlay.addObject(Item,inv,10)

If anyone has suggestions how to solve this or do it otherwise or do it better, please tell me. :slight_smile: If you need more info to find the fault, just ask and I’ll do my best to give it to you.

Grinser

You can only add objects that live in the same scene. Therefore you need an object pair:

One object in the main scene.
One object (most-likely inactive) in the inventory scene.

Hint: They can be linked versions of the same object.

In most cases it is better to have two different objects, as an object in the game needs other behavior as an object in the inventory. It is a common method that they even look different.

What you need to do is to create a scheme to match the pairs.
Example:
via Object names:
MyGameObject.game
MyGameObject.inventory

or property:
MyGameObject[“inventoryObjectName”] = MyInventoryObject

etc.