Game Logic in XML Files

前端 未结 5 1482
迷失自我
迷失自我 2020-12-22 20:24

I\'m dealing with game dialogue files (conversation between player and non-playable-characters) where dialogue choices and their outcome depend on certain conditions and res

相关标签:
5条回答
  • 2020-12-22 21:07

    Because you're writing this in Ruby I think that doing it in XML should be sufficient. That way you could make a web application that allows you to work on the dialogue and game logic from anywhere. And other people can collaborate with you, or possibly create user mods - which is always a plus.

    As long as you keep your XML files well organized (flowcharts on paper will help) you shouldn't run into any issues, and might even thank yourself for going through the pain of parsing it :)

    0 讨论(0)
  • 2020-12-22 21:18

    To get inspiration, or maybe even adoption, take a look at AIML and BuddyScript. AIML is XML for chatbots, BuddyScript is another variant - now owned by Microsoft.

    The following is a sample of AIML from http://www.alicebot.org/aiml.html

    <category>
    <pattern>WHAT ARE YOU</pattern>
    <template>
        <think><set name="topic">Me</set></think> 
        I am the latest result in artificial intelligence,
        which can reproduce the capabilities of the human brain
        with greater speed and accuracy.
    </template>
    

    If you were to integrate AIML technology (which I think is free) into your game, your NPC's would have AI that your players could talk to. Wouldn't that be interesting?

    AIML is modular so all your NPCs could have a common file describing all the standard knowledge about their world. Then you could add specific files for the stuff that would be typic to each race, class, place, individual or task. There are plenty of interesting sample AIML files, for example Eliza.

    Situational information, can be added at the start of a conversation, and you may have some software outside the AIML engine listening for "magic" words from the NPC indicating that the NPC wants something to happen in the "real" game world. like "***GIVE PLAYER 20 BUFFALO WINGS".

    0 讨论(0)
  • 2020-12-22 21:19

    Unless your game will have less than half a dozen unique dialogs, you should definitely put this information in some kind of data file. XML is a strong contender for the format. I don't speak Ruby, so it may not work in this case, but another option would be to define the dialog as data directly in Ruby code. (I know this would work pretty well in Lua, Python, and Javascript... I assume defining nested data structures is also easy in Ruby.)

    We used XML files to define all the static data in Pirates of the Burning Sea, and it was a great way to go. Having a data format like this lets non-programmers control the data and frees up the programmers to work on features instead of data entry. Having those data files be text means that you can keep them under source control so you can tell when they change.

    0 讨论(0)
  • 2020-12-22 21:24

    A DSL would be a Mercedes-Benz implementation for this and would be fun to write in Ruby. You are right, it would take a lot of work but it might pay off if it was well written and this game really took off.

    One thing to consider if going the XML route is the parser/engine you will be using to render it. Last I checked, REXML was the only show in town for Rubyists. If you like REXML then XML sounds like a good way to go, but if you have not tried it I would suggest doing that before making this decision. I am not picking on REXML, just advising a little caution since you will be completely dependent on this library, whatever you use.

    0 讨论(0)
  • 2020-12-22 21:27

    If you haven't heard of YAML, have a look at it. It's like XML, but XML isn't really made to be written by hand--it's a machine-machine interface that happens to be human-readable (so you are really supposed to create an editor for it). YAML is a human-machine interface, much more writable.

    I wouldn't bother with a DSL, YAML maps perfectly.

    0 讨论(0)
提交回复
热议问题