Mythruna Scripted Dialogs

Given that we’re all developers here and the topic of embedded scripting languages comes up from time to time, I decided to share some of the power I manage to squeeze out of my scripting language of choice. Here is a repost of a topic I just added to the dedicated Mythruna forum (http://mythruna.com/forum)



While actual conversations with NPCs will generally take a different form in the full up Mythruna game, there is still something about an old school scripted dialog system that gives me warm and fuzzy feelings.



My experiences on Neverwinter Nights modding showed me that this sort of system could be used for a variety of scripted user interfaces by modders, etc. and it’s a pretty good way to present interactive information. Any add on quests that the custom content community will end up putting together will surely have one or two of these… either to propel the story through an NPC dialog in a proper way or to represent a book of information, etc…



So, Mythruna just got one… and it’s pretty powerful because it’s pretty much entirely based on the embedded scripting engine.



As a test, I’ve used it to make an in-game help system. You can see it in action in the screen shot below:

http://i.imgur.com/wR1fW.jpg



And here is the dialog script that makes that happen:

[java]

defOption( id:“place”, text:“What is this place?” ) {



showPrompt( “”"

This is the public server setup to help test the networking

support of the Mythruna test builds. This server is run

by the creator of the game and it is common to meet him here.

“”"

) {

option( “build” )

option( “objects” )

option( “blueprints” )

option( “map” )

option( text:“Done” );

}

}



defOption( id:“build”, text:“How do I build?” ) {



showPrompt( “”"

When a block material is shown in the bottom of the

screen, the right mouse button will place that block

type and the left mouse button will remove any type

of block.

“”"

) {

option( “build2” )

option( text:“Done” );

}

}



defOption( id:“build2”, text:“How do I change block type?” ) {



showPrompt( “”"

The mouse wheel will scroll through the major block

groups and other tools. The ctrl key + mouse wheel

will change the sub-type or shape of a material.

“”"

) {

option( “place” )

option( “objects” )

option( “blueprints” )

option( “map” )

option( text:“Done” );

}

}



defOption( id:“objects”, text:“How do I place objects?” ) {



showPrompt( “”"

Use the mouse wheel to find the ‘Objects’ tool.

Ctrl + mouse wheel changes object to be placed.

Right mouse button places or opens the menu of

an existing object. Left mouse button drags.

“”"

) {

option( “place” )

option( “build” )

option( “blueprints” )

option( “map” )

option( text:“Done” );

}

}



defOption( id:“blueprints”, text:“How do I make my own objects?” ) {



showPrompt( “”"

The in game object builder can be accessed using one of the

following methods:<br>

  • press TAB and click ‘Blueprints’<br>
  • press ‘b’

    “”"

    ) {

    option( “blueprints2” )

    option( text:“Done” );

    }

    }



    defOption( id:“blueprints2”, text:“How does the blueprint editor work?” ) {



    showPrompt( “”"

    The controls work similar to in game. Use the move keys to

    rotate the platform. Mouse wheel, ctrl + mouse wheel, left

    click, and right click all work the same as in game.

    Select an existing object to edit or click ‘New’ to start a

    new one.<br>

    After editing, click ‘Save’ to save your work and have it

    available to be placed in game.

    “”"

    ) {

    option( “place” )

    option( “build” )

    option( “objects” )

    option( “map” )

    option( text:“Done” );

    }

    }



    defOption( id:“map”, text:“How do I see the map?” ) {



    showPrompt( “”"

    The in game overland map can be accessed using one of the

    following methods:<br>
  • press TAB and click ‘Map’<br>
  • press ‘m’

    “”"

    ) {

    option( “place” )

    option( “build” )

    option( “objects” )

    option( “blueprints” )

    option( text:“Done” );

    }

    }



    showPrompt( “”"

    Welcome to the Mythruna Public Server.

    Please select a help option from below.

    “”"

    ) {

    option( “place” )

    option( “build” )

    option( “objects” )

    option( “blueprints” )

    option( “map” )

    option( text:“Never mind” )

    }

    [/java]



    The power of the scripting language (Groovy) is that I can customize it to make things flow more fluently. Hopefully those of you interesting in the future of customization can understand what’s going on above and can see the possibilities. And you fellow monkeys can see the power that a scripting language and a decent integration harness can bring.



    Because that’s actually Groovy code, making any of those options or prompts conditional is simply a matter of adding the appropriate “if” statement.
3 Likes

I’ve used scripting languages before (PHP, Python), but i’ve never combined them with a compiled language. The only thing I thought they were really used for is for other people to create their own “plugins” using scripts for the game. Is that why you use it? or is there a bigger picture which i’m missing, where they have specific advantages. Cus it seems a lot of extra work integrating them to do something which can be done using java exclusively. Thanks for any info :slight_smile:

@wezrule I dont think its a lot of extra work. I was reading this tutorial (from Oracle) the other day and it seemed quite straight forward.



But, I wonder why he choose Groovy over all others.

probably because it sounds the best

I chose Groovy because it is very Java like and I’ve been coding in Java for 15 years… and because it supports things that allow the language to feel customized to the task. Like the above.



Integration isn’t hard at all. Figuring out how you want to run it in a multiplayer environment takes some consideration… but really most of the time was spent building the API so that I could get simpler code for the scripts. (For example, the tricky functions, builders, and such to support the dialog syntax… or the fact that I’ve overloaded my EntityId to support direct access to components through the entity system… or used operator overloading to support math directly on vectors.) Many of these things are features I cringe at when they are in Java but they feel very natural in a scripting language.



I use it for the non-core engine game systems whenever I can because I can more rapidly iterate and it supports later customization. Even I use it to add admin commands and such to my server that aren’t shipped with the game by default. You can see the admin command init script that I posted on the Mythruna wiki: http://mythruna.com/script-distros/admin-command.init.groovy When the server starts up, it runs all *.init.groovy scripts and that script adds a hook to the player’s onConnected even so that it can add commands to their command shell… or add tools to their tool list, etc… I do similar to add tree tools, water tools, and other anti-griefing tools.



Also, the entire property system is scripted. Partly because it was easy and partly because as it evolves this is throw-away code… and it’s really easy to iterate this way.