help with logic across scenes.

So I’m working on my game, and I manged to get to a point where I can send logic across my HUD and my main scene, where the HUD is an overlay scene. but there are certain parts where i need to suspend the main scene so you can use your mouse to interact with the HUD. currently I’m using messages to send the data between scenes, but when I suspend the main scene, the messages don’t update the data upon resuming the scene. I have to suspend the scene because the mouse look interferes with the mouse on the overlay. If anyone knows how to do this i would really appreciate it! Thanks in advanced

Can’t you just disable the mouselook when you bring up the HUD cursor? Have whatever sensor brings up the cursor move the mouselook object to a state without mouselook logic. When you are done with the cursor, set the mouselook object state back.

I did some research and it appears that using GlobalDict is the best way to achieve this, i tried using the script bellow to get what i need, but its not working, i keep getting an error in line 16 "KeyError: ‘property’ Im not great at python so any help would be appreciated (:

import bge

def setTip():
	cont = bge.logic.getCurrentController()
	own = cont.owner


	TipSet = 'prop1'


	bge.logic.globalDict['property'] = own[TipSet]


def getTip():
	cont = bge.logic.getCurrentController()
	own = cont.owner


	TipGet = 'prop1'
	own[TipGet] = bge.logic.globalDict['property']

Initially I planned on doing this, but Ill need a similar system for property values (health, ammo, etc) accross levels, so I think its better that I just learn it now :stuck_out_tongue:

tried redoing my script

import bge

def setTip():
	cont = bge.logic.getCurrentController()
	own = cont.owner
    
    bge.Logic.globalDict["TipSet"] = own["Tip"]
    
def getTip():
	cont = bge.logic.getCurrentController()
	own = cont.owner
       
    Tip = bge.logic.globalDict.get("TipSet")
    if Tip is None:
        return
    own["Tip"] = Tip

Still getting errors at the end of line 7, I think I’m just not writing it properly.

Your indentation is messed up in the setTip and getTip functions. The first two lines of each function (the cont = line and own = line) are indented differently from the rest of the funcions. Make them consistent, as Python relies on indentation to identify blocks of code.

Tried making them all consistent but no luck, still getting errors, now on line 9

import bge

def setTip():
    cont = bge.logic.getCurrentController()
    own = cont.owner
    
    bge.Logic.globalDict["TipSet"] = own[
    
def getTip():
    cont = bge.logic.getCurrentController()
    own = cont.owner
       
    TipGet = bge.Logic.globalDict.get("TipSet")

Whoops, i think i see where i went wrong, this is what ive got so far. no more errors in the console, but its not working :confused:

import bge

def setTip():
    cont = bge.logic.getCurrentController()
    own = cont.owner
    
    TipSet = 'TipSet'
    
    bge.logic.globalDict["TipSet"] = own[TipSet]
    
def getTip():
    cont = bge.logic.getCurrentController()
    own = cont.owner
    
    TipGet = bge.logic.globalDict.get("TipSet")

Okay, I think I see what’s going on. You never do anything with the variable you retrieve in getTip(). You get the value, but then what?

um init vs run

Check this file

note the script Initiate

this sets up the list,

the other scripts add to it, or read it.

Attachments

KeyDictandDoor(Commented).blend (550 KB)

Basically what Im aiming for, Is whatever the value of the property TipSet in the first scene was, i want the value of TipGet in the second scene to become
Tried this but alas no luck, sorry if I’m asking repetitive questions, I tried searching it before I made a thread, but I havent been able to figure this out for a couple of days now.

import bge

def setTip():
    cont = bge.logic.getCurrentController()
    own = cont.owner
    
    TipSet = own["TipSet"]
    
    bge.logic.globalDict["TipSet"] = own[TipSet]
    
def getTip():
    cont = bge.logic.getCurrentController()
    own = cont.owner
    
    TipGet = bge.logic.globalDict.get("TipSet")
    if TipSet == 1:
        own["TipGet"] = 1
    if TipSet == 2:
        own["TipGet"] = 2
    if TipSet == 3:
        own["TipGet"] = 3

So for this scene you are using globalDict to send properties between objects in the same scene? also, what happens if you leave the right half of globalDict as ?

bge.logic.globalDict['KeyList'] = []

you empty the list

your re-initializing it as empty,

The scenes sets global which are read by a object in the same scene,

it will work across scenes though

initialize = sets up the list,

Okay, so ive got an always attached to the object i want to send the data, and the one i want to load the data. as well as a separate empty with all initiate script. Im still getting errors, I think this is because i took a complete guess on how to set the property as the other one.

import bge

def TipSet():
    cont = bge.logic.getCurrentController()
    own = cont.owner


    #Get property name
    TipSet = own["TipSet"]


    #store property TipSet in globalDict
    bge.logic.globalDict['TipSet'] = own["TipSet"]
    
def TipGet():
    cont = bge.logic.getCurrentController()
    own = cont.owner
    always = cont.sensors["tip"]


    #Get property name
    TipGet = own["TipGet"]


    #load property TipSet from globalDict
    own[TipGet] = bge.logic.globalDict["TipSet"]
    if always.positive:
        own["TipGet"]=["TipSet"]

Do you think it would be better to add a background scene upon suspending my main scene, so that the overlay scene sends data to the background scene, then when i resume the main scene, the background scene sends the data back to the main scene? i could do it with messages, although for some reason, using messages in my scene really drops the framerate.

may I see the .blend

Does the message have a target?

the blend is pretty big cause its my game project, so ill do an example one real quick, when i was using messages i wasnt using targets, probably why it was lagging haha.

Heres the example blend. Normally I’d use pasteall but Its been uploading for like 10 minutes now :stuck_out_tongue:

ok,

you had a few " " that should have been ’ ’

and you did not initiate the item in the dictionary before trying to set it,

Attachments

LogicAcrossScenesExample.blend (587 KB)

and here it is working :smiley:

press space to change the property in the gun, then the property is fed to the dictionary, then back to the gun

So

[‘TipSet’] = 1

then

bge.logic.globalDict[‘TipSet’’] = own[‘TipSet’]

then

own[‘TipGet’]= bge.logic.globalDict[‘TipSet’]

Attachments

LogicAcrossScenesWorking.blend (594 KB)

Note - I added the counter and key-press so you could see it working