In game\engine scripting?

BlitzMax Forums/BlitzMax Programming/In game\engine scripting?

coffeedotbean(Posted 2014) [#1]
I am looking for some pointers around in game\engine scripting specificity with conversation tree's. Think NPC's in RPG games where their text and player reply options change depending on other factors such as what items the player is carrying or other quests completed.

I am not making an RPG but the same kind of system I'll be looking to implement, for example I might script up the following in an editor.

If player.inventory.contains(23)
   showDialog(78)
Else
   If npc.hostile
       showDialog(12)
   Else
       showDialog(173)
   End
End


I am already thinking I'd need a Dialog Object that holds the main text and the possible replies. And ofc an Inventory object that hold s the list of items the player is holding. Each having a unique ID value.

The issue I have is visualising how to get all this to work in game, I guess I'd need some kind of interpretor to read the script, and then call internal functions created in the game using the arguments supplied in the script.

If any one has any links to some resources or discussions on this kind of system please post them. I am travelling until the weekend so unable to sit down and test out any of my thoughts but have all the time in the world to read up on this kind of thing.


zoqfotpik(Posted 2014) [#2]
One way of solving this problem would be to write a small assembly language that runs in a virtual machine, along with extension commands for dialog-related functions. This might sound difficult to implement but it's really not. If you are thinking of writing an interpreter, this way might actually be easier. It's basically the simplest of all possible interpreters.


Yasha(Posted 2014) [#3]
Well if you really want to write "code-like" scripts as in post #1, you may as well use an existing full programming language like Lua. No need to reinvent that particular wheel.

However, conversation trees are a very constrained form of program so you should probably devise a much more restricted flow-based language (you really don't want or need those If statements clogging up your tree with unnecessary cruft when all the language does is branch).

A potential good base is the conversation/quest script system used by the Elder Scrolls/Fallout games (example). In this model, a quest is a numbered, linear sequence of states that you can advance through by meeting conditions; small branches and alternate endings are handled by goto-ing ahead over certain numbers. The system doesn't allow you to go backwards. More complex branching or looping quest structures are created by threading these sequences together so that the last event in one triggers the start of another.

(How the game actually checks conditions or applies effects is not part of the model... hook a secondary scripting system in to handle these things, maybe with some inline Lua code.)


zoqfotpik(Posted 2014) [#4]
I liked the way that Ultima IV handled it. You could actually type english sentences and it would look for various keywords. And that ran on the Apple II!

My current system has one million times as much RAM space as the first Apple did.


Calibrator(Posted 2014) [#5]
If I remember correctly Ultima IV only recognized four letter words (or rather: The first four letters of a word), not complete sentences. It just would discard the rest.

AFAIK there are no real conversation trees in Ultima IV. I'm not even sure that the game checks if keywords can be already known by the gamer.

The first Ultima that included conversation trees with a mouse-driven dialog system was Ultima VII.
Ultima VII also uses a complex scripting language called "AGIL" ("A Goofy Interpreted Language" ;)) and they describe it as a "use-code and conversation language".

The "complete edition" version of U7 available for $2,39 on GOG.com includes about 30 design documents as "bonus materials" (including descriptions of AGIL, conversation functions and a conversation "style book") and I think they alone might be worth the humble price...
http://www.gog.com/game/ultima_7_complete


Leon Drake(Posted 2014) [#6]
I had one a while back i wrote, i posted it on the code archives but i didn't realize some of it got cut off. i'll see if i can find it.

There is a MiniC module on monkey-x that could probably be ported to blitzmax