Text Object in Overlay Scene

Hey peeps,

I decided to turn to the wise ones once again, because I’m struggling with something that would be essential (for me) to know how to do.

I have 2 scenes in the same .blend file. Main and DialogScene. Blender version 2.71

1 - I’m trying to get a text object called “dialog” and it’s string property “Text” into pythonm so that I can set the “Text” property from the main scens (depending on what happends in main scene, the text willchange). I want to set the property of the text-bar in the main scene, but since the object is in a different scene.

I’ve tried (after looking on the internet):

scenes = bge.logic.getSceneList()

my_scene = [scene for scene in scenes if scene.name == “DialogScene”][0]
object = my_scene.objects[‘dialog’]
object [‘Text’] = “INSERT DiALOG TEXT HERE”
It returns an error. So please if anyone has 2 minutes to help me out with how I can control this dialog object and it’s property in the main scene, I’d be ever so grateful.

Thank you very much in advance! :eyebrowlift:

Pete

also…

2 - This is just a little question - I don’t necessarely want explanation just pretty much a yes/no answer will do.

Is it possible to control animations in an overlay scene? (e.g. ScreenFader - plane in fron to famera - black texture - alpha from 1 - 0 fades in, 0 - 1 fades out. Like, get frame number, set frame number, play, stop, that sort of thing? (without using actuators) - OR - if actuators onlyif I can control it from the main scene’s script.

I want to have a screenfader on an overlay scene as the project I’m working on includes fixed camera setup. Camera’s change depending on where player is, and it’d be a pain to parent the plane the fader animation is on to each and every camerain the scene and so on. It’d be easier to have it overlay everithing.

But again, this is a secondary thing so most importantly, I want the dialog system implemented first.

Thanks again!!!

Can you show us your error, along with the full script? It’ll help pinpoint what’s wrong.

correction it’s DialogScene. Apologies, so 2 scenes - Main and DialogScene

Hi, sure, thanks!

import bge

def door1():

# Definitions

scene = bge.logic.getCurrentScene()
cont = bge.logic.getCurrentController()
own = cont.owner    
my_scene = [scene for scene in scenes if scene.name == "DialogScene"][0]
object = my_scene.objects['dialog']        
pla = scene.objects ['Player'] # Player Object
coll = cont.sensors ['Collision'] 



keyboard = bge.logic.keyboard    
space = bge.logic.KX_INPUT_JUST_ACTIVATED == keyboard.events[bge.events.SPACEKEY]

# Actuators

act_scene = cont.actuators ['ADD'] # ADDS Overlay Scene Actuator
deact_scene = cont.actuators ['RMV'] # REMOVES Overlay Scene Actuator
sound = cont.actuators ['Gong']



#Door "LOCKED" - Enter Dialog

if coll.positive and space and own['indialog'] == False and own['open'] == False:
    cont.activate(act_scene)
    pla ['freeze'] = True
    cont.activate(sound)
    own['indialog'] = True
    object ['Text'] = "It's Locked!"

door1()

  1. Firstly, any time you get an error from running a script, PLEASE INCLUDE IT IN YOUR ORIGINAL POST (in addition to the relevant lines of code. Not trying to pick on you in particular, but this happens fairly often and it takes a bit of coaxing to get the OP to post the original error. Generally it will save time if you include all the relevant information up front. Python’s error messages tell you exactly what went wrong and where, so it would behoove you to learn to read and understand them.

With that out of the way, here’s the error I suspect you’re getting:

IndexError: list index out of range

This means that there is not item at index 0 of the scenes list you try to create. This leads to the conclusion that there is no scene named “Dialog"Scene” in the currently existing scene list.

Assuming you have the name of the scene correct, you’ve probably made the fairly common error of trying to access an overlay scene on the same frame you’ve added it. Scenes are not available until the frame after they are added to the game (Hint: reading the API can be helpful). So the easiest way to fix your problem is just to delay running the script until the frame after you’ve added the overlay scene.

  1. Yes, you can control animations in an overlay scene from a controller in the main scene. You can do pretty much anything in an overlay scene this way with a few exceptions (LibLoading objects into the overlay scene for example).

Indeed that is the error. Apologies for missing that out.

Basically, when player is on collision with door_coll object, it executes the script. There’s only the collision sensor going into it, and then there’s an “Add Overlay Scene” actuator and a “Remove Scene” actuator coming out of it. This is what I had:

  if space and own['open'] == False and own['haskey'] == False:        cont.activate(act_scene) #Adds Overlay Scene
        pla ['freeze'] = True
        cont.activate(sound)
        own['indialog'] = True
        object['Text'] = "It's Locked!"

So, I have to delay the “object[‘Text’]” bit… hmm. Sorry I’m just fairly new to python (as you can probably tell haha)

How do I delay that to by 1 frame?

Thanks for understanding and for the patience.

Pete

Also I can post the blend file if ya want! (it’s a bit big cause of the sounds packed in there though)

Yess, got it working. Thanks Mobious, you were right. All I had to do was add another “if” statement after the first one. Works like a dream!

Thanks again!