In game text/messages - First Person

Hi,

I have made some more progress on my game and added a video if anybody is interested.

http://www.youtube.com/watch?v=5Myo1Ba8dhI
I need some help - I explain in the video. I want messages to display at the bottom of the screen when I click on and interact with objects. I have tried using available tutorials but I haven’t found anything that is suitable for my game.

If somebody can suggest a tutorial or has an example file I would be very grateful!

Thanks.

send a message with the subject clearly for a global (unique) object
and so the global object with sensor message with a filter that has the same “key”
the key can be this -> “message for GUI”
so,

any object(supposing a cube):
leftmouse -> and -> message [message for GUI][Cube clicked]
mouseover

any object(supposing a cone):
leftmouse -> and -> message [message for GUI][Cone clicked]
mouseover

any object(supposing a sphere):
leftmouse -> and -> message [message for GUI][Sphere clicked]
mouseover

global object (a -> TEXT object)
message [message for GUI] -> python


#####
import bge

own = bge.logic.getCurrentController().owner
message_sensor = own.sensors["Message"]
if message_sensor.positive:
    bodyofmessage = message_sensor.bodies[0]
    own.text = bodyofmessage


##### 

code tested … script mode

I’m not 100% sure what you mean, but if you mean something similar to a sign then this should help:

Try using some dynamic text in an overlay scene (Scene Actuators->Add Overlay) and have it invisible or have no text when in use.

I made this basic demo back in the day when starting off, and took it from there. Might be what you’re looking for / help you start off!

[ATTACH]362149[/ATTACH]

Pete

I modded your dialogue system.Here is the blend.

Attachments

Dialog.blend (623 KB)

Haha, colorful!

Just noticed I didn’t remove the render module and the showMouse(1) line from the Dialog function. It is not supposed to be there.

Why would you want to do that?

In the file I posted above, I put a separate function in there for the mouse visibility. It’s pointless to import the render module in the Dialog section, and have it do something it’s already done every time the script runs. Did u look into the script or did u just change the monkey colours haha :smiley:

For quicker logic however, I recommend using the new Mouse Actuator if you just want to show / hide the cursor. For little tasks like this, if you can do it with logic, do it. For (almost) anything else, you have python.

Pete

Hi thanks for all of the replies!!! I like the example .blend file you sent above so I am trying to make it work for my game. Because of the first person perspective the text object needs to be in a separate scene so I have put it in the Crosshair scene. How can I code between the two scenes? I have tried as per below but it’s not working:


def Dialog(cont):
from bge import logic, render

render.showMouse(True)

own = cont.owner

scene = logic.getCurrentScene()

camera = scene.Crosshair_camera

text = camera.children['Text']

message = str(own['prop']) 

… etc as per your example.

You were close, but you need to get the scene first, then you can get objects from it.

crosshair_scene = [scene for scene in scenes if scene.name == "CROSSHAIR SCENE NAME GOES HERE"][0]

Then, in a new line, camera = crosshair_scene.objects['Camera.001"] or whatever the 2nd camera is called. Or - (I think) you can also do crosshair_scene.active_camera, to get whichever camera is active in that scene.

Note:

Getting object from other scenes will only work once the scene has been added, regardless of whether it’s an overlay or background scene.

Pete

Hi that makes sense, I have tried editing my code but it’s still not changing the Text object.
My scene is called ‘Crosshair’
My camera is called ‘Camera.001’
I made a ‘Text’ object called Text and parented it to the camera.
I have assigned a book to run the python module like in your example with a string ‘prop’.

Can you please make sure the first part of my code is OK?

Thanks

def Dialog(cont): from bge import logic, render

render.showMouse(True)

own = cont.owner

scene = logic.getCurrentScene()

crosshair_scene = [scene for scene in scenes if scene.name == 'Crosshair'][0]

camera = crosshair_scene.objects['Camera.001']

text = camera.children['Text']

message = str(own['prop'])

Why not simply send a message with a specific subject (e.g. “text to display”) with the text in the body?

All you need is a simple code that reads the message body and shows it on screen. No need to hard-code any scene or object names. [Imagine what happens when you rename “Camera.001” to a proper name.]

If you do not feel save to extract the message body have a look at S2A.firstBodyToValue.

To see the advantages of using messages I suggest to read the BGE Guide to Messages.

Enhanced:
If you want to translate your texts, you do not directly send a text. You send a key (text key) that can be looked up to get the text to be shown.
E.g.
Key = “cube.infotext”:
en: “I’m a cube”
de: “Ich bin ein Würfel”

This also helps to keep all the texts together at one place. You distribute text keys within you scene.

DustScatter - Here ya go. Just needed to get the scenes list first.

[ATTACH]362350[/ATTACH]

You can also track how many times something has been examined, by adding 1 to a second property on each item, set to Int. Then, you can easily change the dialog-message on an object in runtime, through logic. So if player has clicked on a pen 50 times, you can display stuff like “Stop examining this pen. This is the 50th time… It’s just a pen!!!” just for fun, like easter eggs in ur game, or hidden info for hardcore fans and stuff haha.

As Monster said, you can use messages too. They are a cool and clean way to have 2 objects communicate without having to use python, or even link their logic bricks together. They work once an overlay/background scene has been added, OR if u send the message AT THE SAME TIME as adding the overlay/bg scene. That information helped me out a lot back in the day.

In your case, I’m assuming the crosshair scene will always be running.

You’ll have to figure out what will determine when the dialog ends/disappears off screen.

Pete

Hi,

Monster: I tried using Messages in the first place but I couldn’t get it to work so that’s why I started this thread :slight_smile: . It looks like a really good system but I would need an example so I’ll try hreidmarrs suggestion first.

Thanks for the example hreidmarr! It’s perfect except for some reason in my game I am having problems… It seems to be with this part of the script:

    
m_over = cont.sensors['Mouse_Over']    
m_click = cont.sensors['Mouse_Click']
    
    if m_over.positive and m_click.positive:

I can not figure out why because my book and cabinet objects seem to have the same properties as your monkeyhead objects. Maybe it’s something to do with my game being in first person but I dont see why that would be a problem. If you have any suggestions let me know otherwise I will keep playing with it and see if I can get it to work.

[’ NAME GOES HERE '] represents the name of the sensors from your logic brick editor/window.

If your sensors have a different name on your objects (e.g. “Mouse” & “Mouse1”) you will have to change the script to cont.sensors[‘Mouse’] and [‘Mouse1’]. Otherwise the console will say that the sensors the script is looking for are not found.

It’s best to name the sensors & actuators.

Then, the “if” statement just checks whether both “Mouse Left Button” and “Mouse Over” sensors are positive.

Other than that, I can honestly not think of anything else why it shouldn’t work.

Pete

AH YES! It works :smiley: ! Thanks such a relief… Yes I had it named Mouseover without the underscore. So I have fixed it and added a near sensor:

m_over = cont.sensors['Mouse_Over']
m_click = cont.sensors['Mouse_Click']
n_sen = cont.sensors['Near']

if m_over.positive and m_click.positive and n_sen.positive:
    text['Text'] = message

So now I just need to figure out how to make it disappear which I will try tomorrow and let you know if I get stuck but I think it is the easier part.

Thanks again!

You’re welcome :slight_smile:

Personally, I would freeze the player (put them on a new state) when dialog is displayed, then, when you click the 2nd time, dialog disappears, player can move again, back to default state. This could work in a FPS game, allowing you for animations to be played or have the player say stuff, play a sound, and just in general have control over when text is displayed.

But there’s many ways, depending on how you imagined your gameplay.

I like your idea but I had the idea that the gameplay would be smooth so you can keep walking around while you read the messages without freezing the game.

So I got it to work by sending a message to the text object which adds a value to a timer which counts down, when it’s above 0 you see the text object, otherwise it’s invisible. But this makes me wonder if I could just have had the message in the ‘body’ of the message if I could figure that out. But for now it works so I’ll run with it and I might change systems later.

I’m also worried about all the mouse click, mouse over and near sensors on every single object, since my house will have 100s of objects it might start to lag. But that’s a question for another topic I guess. My original request was answered thanks again!

You just need one object with one mouse sensor in “mouse over any” Mode.
This way you have the “info text handling” at a single place.

Yes this would be ideal but I wouldn’t know where to start do, you have an example of this that I can look at??