How do I improve my code (game of dialogues and choices)

0 favourites
  • 2 posts
From the Asset Store
5 levels with simple coding Source-code (.c3p) + HTML5 Exported
  • Hello guys. I'm trying to create a game with dialogues. For example, "you are in a hallway with two doors, which door do you want to open?".

    So far so good. The problem is that I think it's getting very complicated. I would like tips to make the code simpler.

    Here's the CAPX: drive.google.com/file/d/1UmrVI63UbiQaurfhP-KuOMvCfJ8TcnYD/view

    Thank you. =)

    (sorry my bad English, it's not my native language)

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • If you really want to scale the amount of dialogue and choices, you need a system that reads the dialogue/choices from external files and puts them in Construct in a way that's easy to reference and read (e.g. storing them in Dictionaries). Also, you need to think through how a dialogue is intialised, and how a choice leads to another dialogue. It involves some care in planning and executing, but it will serve as the framework for any kind of dialogue, and you'll be able to edit/revise your text and the flow of the dialogue more easily than if you were to do everything within events.

    (FYI, I am making an ARPG prototype -- in C2 -- that has a lot of dialogue. I've implemented my own dialogue system which is partly based on a nodal graph format. But it was originally just a specially formatted technical writer's nomenclature, and this is where I'm basing my advice.)

    I think you should think about designing a text-based writing format that makes sense to you. I'll give a simple example:

    init_topic=intro
    
    intro.text=You are in a hallway. Choose a door.
    intro.choices=door_a,door_b
    door_a.choicetext=Door A
    door_b.choicetext=Door B
    
    door_a.text=You enter a room with a lever on the floor. What do you do?
    door_a.choices=lever,nothing
    
    lever.choicetext=Triggers the lever
    nothing.choicetext=Does nothing and returns
    
    lever.text=A trapdoor opens into the ceiling and a zombie falls right in front of him.
    lever.choices=fight
    
    door_a.text=You enter a room with a lever on the floor. What do you do?
    door_a.choices=lever,nothing
    
    door_b.text=You enter an empty chamber, everything in this place is a picture on the wall.
    door_b.choices=examine_picture,come_back
    
    examine_picture.text=Nothing happens
    examine_picture.choices=come_back
    
    come_back.text=You enter a room with a lever on the floor. What do you do?
    come_back.choices=door_a,door_b
    
    

    This text file can be read and then parsed into a Dictionary so that the text before the `=` is the dict key, and the string after `=` is the key value.

    E.g.

    dialogue_dict['init_topic'] = 'intro'
    

    The `init_topic` shows where to begin. The system will search for the intro topic, then get the text of the topic, and the choices,. Pseudo-code:

    topic = dialogue_dict.Get('init_topic')
    topic_text = topic&'.text'
    choice_key = topic&'.choices'
    for(i=0;i<tokencount(choice_key,',');i++)
    {
     choice_text = tokenat(choice_key, i, ',')
     DisplayThisChoice(choice_text[/ic])
    }
    

    The basic idea here is that choices are the selectors for another topic. However, they share the same internal name, so when you choose `door_a` you're actually going to the topic `door_a`. But when you're in the `door_a` topic, the dialogue display will read from the value of `door_a.text`. For the choices being displayed, a list of keywords are given: `lever,nothing`. If you look at `lever.choicetext` it reads `Triggers the lever`. This is what is written in the choice text (not the dialogue text). And then it keeps on going as far as you're able to write it.

    Just note that the format I wrote above doesn't support multiple `choicetext` or `text` so you might have noticed that I had to repeat the `intro` text in the `come_back` and `nothing` topics. However, you can think through your own requirements and re-format it so that it suits your purpose.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)