Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I am using Unity to build a visualisation of a serious game. I am using the C# programming language.

My problem is that I receive data from a JSON and I parse it and I end up with a list of different 'words' saying for example:

Player - walks to - Carl

or

Carl - says ... to - Player

(note that this list is not limited to 3 words, it can be a longer statement, and it doew not HAVE to contain Player or NPC or whatever, it's very flexible).

An example of the JSON is as follows:

    {
    "_entries": [
        "g0"
    ],
    "_flow": {
        "g1": {
            "_expr": [
                {
                    "word_": "player",
                    "next_": [
                        {
                            "word_": "says",
                            "attr_": {
                                "message": "Hello Carl! How are you doing?"
                            }
                        },
                        {
                            "word_": "to",
                            "next_": [
                                {
                                    "word_": "carl"
                                }
                            ]
                        }
                    ]
                }
            ]
        },
        "g0": {
            "_next": "g1",
            "_expr": [
                {
                    "word_": "player",
                    "next_": [
                        {
                            "word_": "walks to",
                            "next_": [
                                {
                                    "word_": "carl"
                                }
                            ]
                        }
                    ]
                }
            ]
        }
    }
}

I have a list containing all the possible actions & NPC names , so Carl in this example, would be in my NPC list of names so I can recognize him as an NPC. Same goes for the 'actions' to perform.

Now I can successfully parse this file, and thus logically, in this example, i would be starting with g0. So I call my method which returns me a list of strings containing "player" "walks to" "carl" (in that order).

Now as you can see, there will be a lot more g's. This is where I am stuck, how do i efficiently save this data and map it something that Unity has to do. (in this case I would want an object to be highlighted in the world and the player can manually walk here). But there can be other cases, if for example we turn the ,previous example around. The list could be "carl" "walks to" "player", this would imply that the NPC carl will be walking to where the player currently is.

So basically I need a way to save three things:

1) the order of the words

2) the meaning (NPC or action)

3) the word itself

Can anyone point me in the direction of a very efficient structure or design pattern to use to make this work? Thanks

I am not skilled enough in Unity (and just patterns in general) to know what is the most efficient (or just any) way to solve this.

I hope this is clear to everyone.

share|improve this question
2  
What is your educational background? This sort of thing is a straightforward sort of parse tree. –  Telastyn Nov 11 '14 at 21:51

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.