Efficient Text Parsing For Textadventure

Get help using Construct 2

Post » Thu Sep 06, 2012 2:12 pm

Hey,

i was wondering if someone has an idea how to do efficient text parsing for textadventure games?

Maybe you saw my test "game" here:

https://dl.dropbox.com/u/45711709/INside/index.html

While this works, it's ALOT of work to setup the events and i have no idea how to save / load the game once it gets bigger because i'd have to store all variable and group states :O

Here is a realtime version of my parser so you can see how it works currently and what i could change / redo / add to make it better:

https://dl.dropbox.com/u/45711709/parse.capx

Solution: take key, unlock door with key, open door

Thansk in advance for any input / ideas you guys can give :)
B
33
S
6
G
7
Posts: 338
Reputation: 7,424

Post » Fri Sep 07, 2012 8:13 am

no one?
where is @Kyatric when you need him?
B
33
S
6
G
7
Posts: 338
Reputation: 7,424

Post » Fri Sep 07, 2012 7:31 pm

Ize,

I was working on something like this a while back. See if this helps you (if it makes any sense): https://dl.dropbox.com/u/38038537/examples/TextParsingExample.capx

I updated it for R102, and modified it to better match what you had in your capx.

The solution I used was to create multiple dictionaries, one each for verbs, nouns, prepositions, and language patterns. The parsing engine only checks to make sure the string entered is valid, it does not check for game logic. The parser then passes a valid token string to a global variable, which can be used by the game logic.

Using dictionaries makes it very easy to add verbs and such to the game, and the parser works dynamically to verify the input string, so no changes are required to it when adding words (except for the bugs I probably missed :D).

My example doesn't have much proper game logic, but I think it should show you where I was going with it.

I hope it helps.

Thanks!Wastrel2012-09-07 20:09:57
Don't see the fnords and they won't eat you!
B
75
S
16
G
12
Posts: 322
Reputation: 11,608

Post » Sun Sep 09, 2012 4:18 am

@Wastrel
I like your idea, I was trying to figure out a way to parse sentences and you pointed me in the right direction.

I used a slightly simplified approach by using pattern sentences:
eg.
take 1
open 1
unlock 1 with 2

The sentences the player types needs to match one of those with the numbers replaced with object names, otherwise it will say "i don't understand" or "I don't know what 'foo' is".

Besides the parsing the game logic is made simple as possible. The command and object names are put into global variables so there are no "tokenat" expressions cluttering it up. The end result is the bare minimum number of conditions to do game logic.
ex.
object="key":
--inventory has "key":
----set text to "you already have the key"
--else
----set text to "you take the key"
----delete "key" from room_objects
----add "key" to inventory

The room objects and inventory are dictionaries. I didn't implement it but room changing is as simple as changing the room objects. You could add room persistence by storing the AsJSON of the room objects somewhere when leaving the room. A save would consist of the room objects of each room and the inventory asJSON.

Only about 15 events for the sentence parsing, the rest was for game content (~30 events).
http://dl.dropbox.com/u/5426011/examples14/text_adventure.capx
B
79
S
24
G
54
Posts: 4,749
Reputation: 40,761

Post » Sun Sep 09, 2012 12:33 pm

Wow thanks alot guys, alot cleaner and easier than my approach! :D
B
33
S
6
G
7
Posts: 338
Reputation: 7,424

Post » Mon Sep 10, 2012 3:35 pm

@R0J0hound, that is a much less complex approach. Very nice.

My original intent was to emulate the Infocom Z-machine, which explains why my approach seems a bit overboard. :D
Don't see the fnords and they won't eat you!
B
75
S
16
G
12
Posts: 322
Reputation: 11,608

Post » Mon Sep 10, 2012 4:36 pm

@R0j0hound nice capx. I loled at the winning text :)
Sorry Ize, I didn't get a warning for this thread. Also I don't think I would have proposed a nice solution like R0j0's.

Adding this thread to the how do I FAQ.
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 7,000
Reputation: 57,795


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 25 guests