Search Unity

Multiple Choice Events for Player

Discussion in 'Scripting' started by Deleted User, Mar 23, 2015.

  1. Deleted User

    Deleted User

    Guest

    Hi there! I've been working on a strategy game, with a basic top down map prototype.

    A major game mechanic I need to get going is making choices in the face of a random crisis. Lots of strategy games make use of this (Crusader Kings, Europa Universalis), as well as other RPG-influenced games. It's not everyone's cup of tea, but I feel confident this is the game I want to make.

    The events won't appear in any predictable sequence. Players will be presented with a random event, the logic of which will be controlled by a condition/trigger state. The player will then make a choice, and the consequences will unfold.

    An event might be:

    TITLE: Hard Choice
    CONDITION: In Battle && Enemy Mage
    DESCRIPTION: In all the chaos, you turn around to see a fireball hurling towards you. You try to dodge, but you stumble...
    CHOICE 1: Face your fate
    RESULT 1: Health -= 5
    CHOICE 2: Throw your staff into the fireball.
    RESULT 2: Staff = Destroyed
    CHOICE 3: Push your ally* in the way. (*Subcondition: Ally is present/alive.)
    RESULT 3: Ally Health -= 5

    Some examples from other games...



    (Above: A multiple choice card event from the Battlestar Galactica board game)



    (Above: A multiple choice event from FTL)



    (Above: A multiple choice event from King of Dragon Pass)



    (Above: A multiple choice event from Europa Universalis 4 by Paradox Interactive)

    I feel like I could do this easily for one event with an FSM (e.g.: something like playMaker). But I see that becoming really disorganized if I want to design 100+ events. That creates a lot of potential issues for debugging. And while I'd reluctantly take on that mess, I'd also like to create something easy / readable enough that I can have some of the artists and level designers tweaking and rebalancing events as necessary.

    I'm even thinking of defining events in XML and trying to process them through some kind of "Event Processor FSM". The machine would load the suitable text and choices, and then trigger the consequences by looking them up in the XML, but I'm not sure if I'm just making things more difficult for myself.

    Does anyone have any advice for how to approach this? I tend to think in terms of FSMs, but I'm open to trying some other kind of solution.
     
  2. Antistone

    Antistone

    Joined:
    Feb 22, 2014
    Posts:
    2,836
    If you're thinking of making 100+ events, you almost certainly want to take some sort of data-driven approach. Exactly how complicated your data and parser need to look depends on how complicated you want your events to be.

    I'd say finite state machines are overkill if you're making the event system out of BSG or FTL--those are almost all single-choice events, so all you need is a prompt, a list of possible responses, and the effects of each response. (If you occasionally need to do a follow-up, then "run event XYZ" can be one of the possible effects.)

    You could describe the events in XML, but if you're editing the files by hand you might find it easier to work with JSON (or even your own custom format, if you're comfortable writing a parser for it). XML is pretty verbose and has some odd features that I feel aren't helpful for most applications.
     
  3. Deleted User

    Deleted User

    Guest

    This is super helpful. Sidebar: what's the biggest benefit of using JSON over XML for this application?

    Definitely feel like a data-driven approach is the right track. Thanks for confirming. If the events get complicated at all, it will be one event triggering another in some kind of chain. Or picking a choice that itself triggers a dice roll and a semi-random result. Or choices that are available / unavailable depending on a condition. It sounds like you think this is unique enough that I should just develop it from scratch?
     
  4. Antistone

    Antistone

    Joined:
    Feb 22, 2014
    Posts:
    2,836
    JSON maps more directly to typical class structures than XML does, and JSON-encoded objects tend to be smaller than XML-encoded ones. They are both more than powerful enough for something like this, though, and standard serializers/deserializers exist for both. (Basically XML tries to stay close to HTML syntax, while JSON tries to stay close to source code syntax. If you're more familiar with writing source code than hand-writing web pages, JSON will probably seem more natural to you.)

    It's possible that you could find some third-party code that would help with this (perhaps in the asset store?), since it's a common feature (most games call it "dialog trees", but it's roughly the same thing). However, the preconditions for an event and the results of a particular choice are probably going to need to be expressed in a way that is unique to your particular game (since they will presumably refer to game elements outside your event system), so even if you found a third-party tool, I imagine you'd need to customize it significantly in those areas.

    The main benefits to a pre-existing tool would presumably be to handle more complicated logic within a particular event (trees, loops, randomized branches, etc.), and to provide you with a nice editor (so you don't find yourself editing JSON or XML files as raw text)--how much those benefit you would depend on how complex your events are going to be.

    That said, I haven't looked for third-party tools to do this, so I don't know what's out there.
     
  5. Deleted User

    Deleted User

    Guest

    That was my intuition as well: that I'm basically dealing with dialog trees, but there's going to be more complexity under the hood in terms of consequences (setting / storing variables and objects).

    So I guess that's what I'm trying to figure out now... if this is something I could extend easily from a third party asset, or if it's the kind of thing that's going to be unique enough that I should just slog it out on my own. There's the obvious benefits of understanding my own code. But even so, I'd be curious if there's a dialog tree system that has a few extras that are geared towards what I'm trying to do.

    Thanks for explaining the benefits of JSON vs XML...
     
  6. Deleted User

    Deleted User

    Guest

    Just giving this a little bump. Anyone else have suggestions for how to accomplish this?

    Recommendations for third-party tools are welcome.
     
  7. ensiferum888

    ensiferum888

    Joined:
    May 11, 2013
    Posts:
    317
  8. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,694
    There are dialogue tree products on the Asset Store that support variables and custom events and are UI-independent so you can make the interface look however you want. I'd recommend a third-party dialogue tree product if it's within your budget. This way, the code's already written and tested, and it's more data-driven than something like a PlayMaker FSM.
     
  9. Deleted User

    Deleted User

    Guest

    Thanks a ton. This is all really helpful.