3
\$\begingroup\$

I've started working in a quest system for my game, but I stumble in a zone where I have to many, if/else conditions to handle a quest, whether you have X and Y item in your inventory, whether you have already talk with a NPC, or whether some other quest stage is a given value and so on.

This end ups making the code very unclean, hard to fix and extend.

I'm wondering what's a good way to handle this.

I've read that keeping your quest as XML file is a good practice, but I've never worked with XML before(I know what they are, but I'm unfamiliar with how to properly make one)

I made a template quest to handle fetch/talk quests in a CSV file. Which looks something like this:

quest-system

But I'm not that I'll end-up shooting my own foot with this custom system.

The branches of a quest can depend on items, previous quests, npc status, player status... So, what's a good way to deal with this?


EDIT:

This is not a duplicate of this question since the answers for this question are either using XML (which I said I don't have the know-how) or use multiple if/else conditions, which is my start problem.

\$\endgroup\$
  • 1
    \$\begingroup\$ At first glance the system you've built doesn't look that bad. Can you try to explain what concrete problems you have with it? Without a clear problem description we can not provide a good solution. I could dump the format for the dialog scripting for my MMORPG engine I developed a while ago or the visual novel I am developing right now, but without knowing what you are looking for I have no idea if it would be better or worse for your particular game. \$\endgroup\$ – Philipp Jun 4 '15 at 16:06
  • \$\begingroup\$ possible duplicate of Designing a scriptable questing system \$\endgroup\$ – Philipp Jun 4 '15 at 16:10
  • \$\begingroup\$ I'm looking for a clean way to deal with quest which required multiple conditions and that spam multiple branches dialogs for each of those conditions. My current problem is that my quest system have way to many if/else conditions to handle very few quests. Also, this is not a duplicate of the linked question since the answers for that question are either using XML or using if/else. Which I addressed both. \$\endgroup\$ – f.rodrigues Jun 4 '15 at 16:19
  • 2
    \$\begingroup\$ N.B. that "duplicate" means *the question is fundamentally the same (or similar enough)". It has nothing to do with the answers. I think this is probably a duplicate as well, although not enough that I'm willing to unilaterally close it... yet. I'd suggest editing your question to focus on a more specific aspect of the problem you're having, that would help make it unique. Questions asking for "a good way to solve [broad problem X]" tend to be a bad fit for this site anyway. \$\endgroup\$ – Josh Jun 4 '15 at 16:29
  • \$\begingroup\$ Is the problem here with the CSV format, with the code you're writing to parse it, or both? Or is it a conceptual problem? \$\endgroup\$ – Anko Jun 5 '15 at 7:36
5
\$\begingroup\$

One way of handling this could be to implement some form of graph system:

http://en.wikipedia.org/wiki/Graph_%28mathematics%29

Or as a state machine:

http://en.wikipedia.org/wiki/Finite-state_machine

In both cases you describe your quest states (stages) as nodes, and the edges/transitions as the actions that can be performed to move from one state to the next.

The example you provided would lend itself quite nicely to this setup (with a bit of modification).

By using something generic like a state machine allows you to reuse the same code for everything, but the only issue area is coming up with a way of tying in player actions/conversations trees. But if you also represent your item database as a spreadsheet/in xml it becomes a bit easier.

In this article there is an example of how Grim Fandango has it's first "quest" laid out: http://www.squidi.net/three/entry.php?id=158

\$\endgroup\$
  • \$\begingroup\$ FSM are cool. I'll try this, I started learning a bit about xml maybe it will come in hand. \$\endgroup\$ – f.rodrigues Jun 4 '15 at 20:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.