How do you keep the item you picked up for the next scene?

I want to be able to do this when you progress to the next level and when returning to a level and not just able to get the same items as you return if I don’t want that.

have a dictionary associated with the scene, each entry is a game object
use it to spawn the items when the scene starts.

when the actor picks up an item, delete the item from the dictionary.

save the scene dictionary to disk using pickle or JSON or similar means.

this way the next time you load it’s updated.

“Serialize” the object and use a function to “rebuild” it. Dicts are good.

Me, rather than having the objects directly placed on the scene, I might record their position and any required properties that must be set, and spawn them as soon as the scene is loaded. This way things are not set in stone as I can modify entries anytime.

Some example code,

#dict[str(position)] = [0]: obj_name, [1]: property dict
test_objDict = {
    "5,0,0":
    ["defaultActor",
    {"_name":"This Guy", "race":"Mutant", "klss":"Dude",
    "isPlayer":False, "team":1, "etc":None}]
}

#call this when done loading scene,
def onLoadLevel(scene, object_dict):
    for position, obj in object_dict.items():
	new_object = scene.addObject(obj[0])
	new_object.worldPosition = [float(num) for num in position.split(",")]
	setObjectProps(new_object,obj[1])

#use to set properties
def setObjectProps(obj, prop_dict):
    for prop_name, prop_value in prop_dict.items():
	obj[prop_name] = prop_value

Note that scenes do not share objects and meshes. Any such data you need has to be present on each scene. You might want to look into libLoad to bring in needed assets rather than linking them on every level.

NINJA EDIT: typos

Does this also work for say you have 100 rounds of ammo and you use 10 and have 90 and when you go to the next level it remembers that’s how much you have left?

that is a player inventory, I would have a scene inventory and a player inventory separated.

(when the player picks up a item, remove it from the scene dictionary, and place it in the player dictionary)

dropping things is going in reverse however you have to store pos / rot etc about the item to spawn it in world space.

^I’d listen to BPR if I were you.

But that aside, you store ammo count on a property dict then update it.
Also keep in mind the code is only an example; you’d have to rework it to fit your use case.

You should use globalDict for it, it’s build for this task(s)

you can even save and load the dict

from bge import logic

def storing():

    GD = logic.globalDict
    
    health = 100
    ammo = 20
    
    GD['player_stats'] = {
                        'health' : health, 
                        'ammo':ammo
                        }

def loading():
        
    #in other scene (same .blend file)
    GD = logic.globalDict['player_stats']
    
    if not GD:
        print('No GD found')
        return
    
    ammo = GD['ammo']
    health = GD['health']
    
    print('loaded:', 'ammo:', ammo , 'health:', health)

to save it to a .bgeconf file you can either use the bricks or

logic.saveGlobalDict()
logic.loadGlobalDict()