between scenes

I have two properties currently attached to an empty which is parented to my player FPS cam. one is an ammo property and the other is a property which determines the active weapon as it is chosen from the inventory screen.


I have a cave that you walk into and, upon making contact with the doorway, it sends you to scene 2 (inside the cave). The problem is that none of the properties transfer with the scene change. ie. the player has ammo of 20 in scene 1 and in scene 2 it is zero. 

What I’ve tried:

*Sending a message from the hud “text” property which stores the current amount of ammo from scene 1. it appears that this also resets to 0 between scenes? it seems strange because the hud is in a scene all its own so it seems unlikely. the ammo display ( text box ) still reads the accurate amount between scenes but I’m not sure what the property is doing. debug just shows zero in scene 2.

*Making an always from the ammo property in HUD that constantly updates the amount of ammo to the player empty that produces a bullet when ammo prop is greater than zero. In scene 2 this is not happening. I’m almost certain that I was desperately over-thinking this one.

*I’ve tried a few other things like un-linking the player and just using a duplicate between scenes and misc ridiculous issues.

I use bare level python because I’m not very well versed in it (striving to learn it) so if you give me 40 lines of code then it might need more explaining than you are willing to do. I’m hoping for a logic brick fix if anyone has run into this problem before.

I looked for this problem in other threads before I posted this but couldn’t find anything. if it has already been solved and you know about it, a link would be just as helpful as anything else. Thanks in advance!

If your HUD scene is an overlay it is probably removed when the main scene is changes and then re-added, hence it resets too. However, you can store variables in bge.logic (for example, bge.logic.ammo) to access them independently of scenes within the same blend, or write entries to bge.logic.globalDict (EG bge.logic.globalDict[‘ammo’] = own[‘ammo’]) if you are transitioning between blend files. Another advantage of globalDict is the function bge.logic.saveGlobalDict() and bge.logic.loadGlobalDict(), which write and load the global dictionary to and from a file- this means anything you want to keep when the player saves or they reach a checkpoint, or whatever (such as current ammo, current position, health, inventory, whether X character is alive or Y mission is complete) you can write to the global dict and then save it to a file automatically.

Thanks for the quick reply! I’ve done many variations of what you’re explaining but the root of it is that im not entirely sure how to implement it. i have written a script to save the ammo property from player in scene one. in the logic bricks, I added an “always” sensor that i linked to a python controller and selected the save script that looks EXACTLY like this (bear in mind i have little practice with python):

import bge
dict = bge.logic.globalDict
dict[“ammo”] = bulletspawn[‘ammo’]

** there is literally nothing else in this script

Now in scene 2, I wrote a load scrip for ammo and created an always sensor connected to a python controller that is associated with the this load script:

import bge
dict = bge.logic.globalDict
bulletspawn.001[‘ammo’] = dict[“ammo”]

this is word for word/note for note what i put in there. no “main()” no “def” nothing. Just based on all of the reading I have done, i assumed that anything else is unnecessary. I have tried other things besides always sensors such as a keystroke entry but still cant seem to get those values across scenes. Again, thanks in advance for any help.

ps if you can help me figure this out with some patience ill gladly paypal you 5 bucks. id offer more but just spent most of my savings on school book for the summer semester.

Have a look in the system console, terminal or whatever you call it (if you’re on windows go to window-> toggle system console) and you’ll probably see an error like:
“line 3 bulletspawn001 undefined”

You need to get the object first, before you can read or write values.
Try something like:
bulletspawn.001 = bge.logic.getCurrentScene.objects[‘bulletspawn.001’]

yes that just sent me farther into the rabbit hole unfortunately. ive tried every variation on that as well now. i just cant get it to save and reload at the next scene. im not even getting any errors in my console at the moment :frowning: i can say that my HUD values do transfer over into the next scene so i attempted to use the copy property actuator which also has no result. ill keep trying everything i can i guess.

found the answer here. works GREAT!