Simple interactive dialogue in BGE

Hello, BA community. I keep asking newb questions about BGE. Even that i already have (thanks to you) some basic knowleges how to use logic bricks to create simple games i still have lot of questions. This time i need help with dialogue system i want to add to npc (non-playable personages). Nothing special just simple interactive dialogue. It should be simple to set up and edit.
For example player approaching to npc and there is appearing option to start dialog on screen. Player has options what answer to choose. One answer leads to end of dialogue, and other answer leads to next text lines. Something like that:


What is easiest way in BGE to implement such feature?
And i am not sure if i should use inbuilt text in blender or just textures with text pre-made in Photoshop. Cause blender text is very blurry sometimes and can’t use materials.

I don’t know if there is a simple way to do this with the logic bricks, if there is a simple way I would also like to know :slight_smile:

Here is nice simple python tutorial, if you choose the python route.

The easiest would be: using a property to keep track of the line you reading, then use 2 buttons to in/decrease the property. So you can simply use the property to grab the right line out of a file. Or with answers you set the right line number and load that.


file = open('text.txt', 'r')
lines = file.readlines()

title = lines[0]
other_line = line[property]

You can also use other setups, but they are more advanced, you can find some dialog examples in the resource section.

Thank you for your answer. I will search resourse thread for examples. As for your method, if it’s not too hard could you create small example to let me (and other newbs) see how it actually works.

What about a xml with tree structure? Previous question as parent to current?

if you want to do it in logic bricks you need the use states.

Well, i would like to try if i knew how to.:slight_smile:

Well this idea of a dialogue tree is actually super cool, the node system in Blender can even be modded to support this, but I guess its out of the scope of a beginner, that’s normal.

For the XML approach, there is a little think to have about the way to define the dialogues with question/answer, but for the Python part you can read this: https://pymotw.com/2/xml/etree/ElementTree/parse.html
There is a bit of text but first you can try to see how to arrange your data (the dialogues).

Just some random design:


<dialogues>
    <message id=0>
        <text>Hey there !</text>
        <answers>
            <answer next=1>
                <text>Hello</text>
            </answer>
        </answers>
    </message>
    <message id=1>
        <text>Cool !</text>
    <message>
</dialogues>

But at this point I would almost see some JSON… I don’t know what is the best thing to do, maybe try things and tell us back :slight_smile:

edit: mkay https://blenderartists.org/forum/showthread.php?220924-dialogue-py-display-interactive-dialogue-tree
more links: https://stackoverflow.com/questions/372915/game-logic-in-xml-files

here is an example of a xml tree i used in a test of mine.



<npc name="Lorenna Padfield">
    
    <dialog dialogID="Get Appels">
        <part>
            <require dialogID="Get Appels" value="none"/>
            <require level="1" />
            
            <text audio="make_you_an_apple_pie.mp3">
                if you get me some apples then i will make you an apple pie.
                    
            </text>
            
            <action value="exit">Later</action>
            <action value="accept" close="False">accept</action>
        </part>
        
        <part>
            <require dialogID="Get Appels" value="accept"/>
            <require level="1" />
            <require item="apple" under="10" />
            
            <text audio="apple_pi_10_apples.mp3">
                hi again.
                Did you get all the apples?
                oh you don't have them yet!
                10 apples is needed to make the pie.
            </text>
            
            <action value="None" close="True">bye</action>
        </part>
        
        <part>
            <require dialogID="Get Appels" value="accept"/>
            <require level="1" />
            <require item="apple" value="10"/>
            
            <text audio="ah_you_just_got_the_apples_that_i_need_to_make_the_pie..mp3">
                ah you just got the apples that i need to make the pie.
                
                
                Reward.
                -----------------------------
            </text>
            
            <reward xp="500"/>
            <reward gold="5" />

            
            <action value="exit">Later</action>
            <action value="done" close="False">Done</action>
        </part>
        
    </dialog>
    
    <dialog dialogID="apple pi">
        <part>
            <require dialogID="Get Appels" value="done"/>
            <require dialogID="apple pi" value="none"/>
            
            <text audio="furelise.mp3">
                tra la la la
            </text>
            
            <action value="exit">Later</action>
            <action value="accept" close="False">accept</action>
        </part>
        
        <part>
            <require dialogID="apple pi" value="accept"/>
            
            <text audio="Andy_Kim_-_Rock_Me_Gently.mp3">
                some text
            </text>
            
            <reward xp="500"/>
            <reward gold="5" />
            <reward select="apple pie,staff of wonder" />

            <action value="exit">Later</action>
            <action value="done" close="False">Done</action>
        </part>
    </dialog>
    
</npc>

if you want to see the test.
here is a zip file that have all thats needed to run it.

http://15b.dk/blendfiles/dialog.zip

sure i have an example for you.

try adriansnetlis Cold Days Game example

Thank you guys for help. I will check all examples you suggested and will learn how to recreate them and then will decide what method better for me. I have made folder where i download all usefull BGE examples and small games made by BA community and will use it as templates for some game mechanics - dialogues, inventory, etc.

Very interesting example of dialog system. Looks very simple with only one script containing all dialog lines with questions and answers which are changing game states. This is what i was looking for. Will try to adopt this system to my needs. Anyway learning basics of Python scripting will make things easier in future!
Thank you for your help laifa, you helped me a lot again! :slight_smile: