Sign in to follow this  
AndreaTucci

NPC dialogues : file or script?

Recommended Posts

I'm developing an action rpg with some friends. I would like to know the differences and pros/cons of making NPC's dialogue using a file in xml format instead of using a script. I see that script method is often used by game developers for NPC's text, but is it better then a xml file? We've thought that a xml file with tags like [text1] [text2] etc is perfect for NPC's text and also for possible quests to give the player. So what are the differences between this two methods? Is a script suitable for this aim? Thanks

Share this post


Link to post
Share on other sites
What do you define as a "script" in this case? I don't really see any difference between what you're calling a script and an XML description of a conversation tree, except possibly formatting and markup. Use whatever you prefer.

Share this post


Link to post
Share on other sites
Depends. If the dialogue is determined upon some previous logic or if the dialogue results in some arbitrary logic, then you would probably need to call some code within your project. Thus a script would probably be better.
On the other hand, if the dialogue is premeditated and always the same depending on some set actions, then a static file would be better.

But as ApochPiQ mentioned, the way you mention "script" is a bit different than what I'm thinking of. When I think of scripting, I think of LUA being integrated with a C++ project for example. A script would of course work, but in your case, I believe a standard XML file will suffice. Edited by french_hustler

Share this post


Link to post
Share on other sites
Yes, i mean Lua scripting for example (integrating with java/c++). The dialogue is always the same, the only "logic" operation is for the quests that NPC could give to the player: npc have to know all the completed quests for choosing which quest he can offer to the player! Edited by AndreaTux

Share this post


Link to post
Share on other sites
[quote name='AndreaTux' timestamp='1344281171' post='4966769']
Yes, i mean Lua scripting for example (integrating with java/c++). The dialogue is always the same, the only "logic" operation is for the quests that NPC could give to the player: npc have to know all the completed quests for choosing which quest he can offer to the player!
[/quote]

It could still be done without a script but it will greatly diminish flexibility. It'll also make it much harder to expand of tweak in the future. But if the behavior is set (which it looks like it is at the moment), I would do it the easy way first, and that would be with a static file, handling the set logic in code.

Share this post


Link to post
Share on other sites
I would like to see an example in which writing a script is required (in lua for example), because I didn't found anything on the web..Most of examples I've read are writable in a simple XML format file! So when is suggested using scripting language? Ok, when the behaviour isn't static like NPC dialogue, but I can't figure that kind of situation!

Share this post


Link to post
Share on other sites
[quote name='AndreaTux' timestamp='1344287105' post='4966811']
I would like to see an example in which writing a script is required (in lua for example), because I didn't found anything on the web..Most of examples I've read are writable in a simple XML format file! So when is suggested using scripting language? Ok, when the behaviour isn't static like NPC dialogue, but I can't figure that kind of situation!
[/quote]

You could store flags and/or condition keys with the XML file, so that certain dialog node is only produced if the attached flag/condition is true. You can also store "magic" attributes to do hardcoded actions, such as "Open Store" or "Give Key to Dungeon". You can insert special embedded strings into the dialog to control things such as "Pause Here" or "Ask for yes/no".

At some point, however, you will realize that you are basically re-inventing a scripting language, as the list of attributes and magic keys and embedded codes grows. Animations, taking player items, healing the player, etc. You may find that your design has become brittle, in that you now have to go back to the source code to change & add dialog logic, do a full re-compile etc to test.

At his point, it may be worth looking into leveraging full scripting, where all of the dialog logic is isolated into seperate scripts. These scripts can be modified (sometimes during runtime!) during testing & debugging without having to change the main source code.

The tradeoff is the complexity of adding the scripting support, which isn't exactly trivial.

If you haven't already, plan out exactly what the extant of and logic of your dialog will be. From your OP, if that is the extent of your dialog system, then it looks like you can just implement [Condition Flag][Dialog Node] nodes in a data file and call it day.

Share this post


Link to post
Share on other sites
What about a little of both? XML stores the actual strings and gives them names (i.e. <string id="hello">Hello, <var ref="playerName" />!</string>) and a scripting language allows you to conditionally display the strings by ID and change player state based on the selected responses and other conditions.

Share this post


Link to post
Share on other sites
[quote name='laztrezort' timestamp='1344288358' post='4966822']
[quote name='AndreaTux' timestamp='1344287105' post='4966811']
I would like to see an example in which writing a script is required (in lua for example), because I didn't found anything on the web..Most of examples I've read are writable in a simple XML format file! So when is suggested using scripting language? Ok, when the behaviour isn't static like NPC dialogue, but I can't figure that kind of situation!
[/quote]

You could store flags and/or condition keys with the XML file, so that certain dialog node is only produced if the attached flag/condition is true. You can also store "magic" attributes to do hardcoded actions, such as "Open Store" or "Give Key to Dungeon". You can insert special embedded strings into the dialog to control things such as "Pause Here" or "Ask for yes/no".

At some point, however, you will realize that you are basically re-inventing a scripting language, as the list of attributes and magic keys and embedded codes grows. Animations, taking player items, healing the player, etc. You may find that your design has become brittle, in that you now have to go back to the source code to change & add dialog logic, do a full re-compile etc to test.

At his point, it may be worth looking into leveraging full scripting, where all of the dialog logic is isolated into seperate scripts. These scripts can be modified (sometimes during runtime!) during testing & debugging without having to change the main source code.

The tradeoff is the complexity of adding the scripting support, which isn't exactly trivial.

If you haven't already, plan out exactly what the extant of and logic of your dialog will be. From your OP, if that is the extent of your dialog system, then it looks like you can just implement [Condition Flag][Dialog Node] nodes in a data file and call it day.
[/quote]

Thank you, now it's clear!
@Firestryke31 it seems interesting, but I think doing controls and logic operations in java with an XML class handler is quick and easier!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this