Opinion poll, how would you do this?

Say you’re making a game that is basically a series of random events.

Example Event 1:
Show prompt with two options.
Take player response from one of two buttons.
Based on the response the player is given some supplies.
Event ends.

Example Event 2:
Random party member is damaged.
Message tells player about the damage.
Player is given a choice to wait for party member to heal or continue on.
Player chooses to wait.
Resources removed from inventory.

Example Event 3:
Player is told that one party member has learned a new skill.
Player is given the choice to encourage or discourage the skill.
Player chooses to encourage.
Event goes into remission for x turns.
Event comes up again after x turns.
The skill has come in handy in some way and the party is happier for it.
Party stats up.

All very different events, but how to script an event system that can handle so many different variable types and outcomes.

The first method I’ve tried and have taken pretty far is to create a base event class and just make child classes off of that. Each one does different things and allows for great customization. The problem I’m running into with this method, though, is that while I can try to keep things broadly the same as much as possible so my class count doesn’t blow up, I find that any time I want to make a little tweak I run the risk of either changing how a bunch of existing events work or just needing a new class, adding to the already growing pile.

The second method I’ve looked into but have not taken nearly as far is to create a node - based system. Each node would store some info and possibly a function to perform much like Kismet in Unreal.

Each solution has pros and cons. I lean towards the first only because it does allow me to have a lot more control, but the downfall is that it also limits the other developers because every time they need a tweak to how the event works they either need to come to me or limit how they want to make their event play out.

So what are your thoughts? Which would you prefer creating if you were in my shoes or which would you prefer to use if you were in the content creator’s shoes? Can you think of another option that trumps these two entirely?

How about using PlayMaker (or any other visual scripting FSM system) to combine both methods? You can encapsulate each specific event in a tidy little FSM without creating a lot of child classes. You can write some custom actions for PlayMaker that your other developers can use, such as “Show Prompt” or “Take Damage”. It’s also easier for the other developers, since they’re insulated from the underlying code implementation, and it’s easy for everyone to understand the flow of each event in a clear visual layout.

That’s definitely an option. I was hoping to avoid a purchase, though. Plus I like the learning experience of rolling my own.

It wouldn’t be visual, but you could do the same thing for free with Lua. Write some general-purpose high-level functions like ShowPrompt and TakeDamage, and register them with Lua. Then each event can be defined in a string on a component, where the string is a short, high-level Lua script like:

TakeDamage(GetRandomPartyMember());
Message("Took damage!");

Another advantage of Lua is that it’s interpreted, so you can modify and/or assign different scripts at runtime.

I’m sure others can suggest a dozen other approaches. I’m just suggesting this as a specific, concrete way to do it that doesn’t require a bunch of C# or UnityScript classes. You could do something similar in JSON or XML, but they just define data; they lack Lua’s control syntax (if…then, while…, etc.).

Hmm, never really used Lua. Sounds promising. I’ll surf the Googles and try and get some more info. Any suggestions for reading up on it?

Check out George Foot’s Lua and Unity thread as well as Danny Goodayle’s Integrating Unity with Lua in Two Minutes article.

Awesome, thanks very much.