MODULE: Story State.

Started by Calin Leafshade, Fri 16/03/2012 04:26:51

Previous topic - Next topic

Calin Leafshade

Here's a very quick module that may or may not be useful to people.

It's essentially an easy to use tree structure for story nodes.

http://dl.dropbox.com/u/27247158/StoryState.scm

So in game_start you can register all your story nodes.

Code: ags

  StoryState.RegisterNode("Start", null);
  StoryState.RegisterNode("GotSword", "Start");
  StoryState.RegisterNode("GotMonkey", "Start");
  StoryState.RegisterNode("StabMonkey", "GotMonkey,GotSword");
  StoryState.RegisterNode("EnterParty", "StabMonkey");


The first parameter is the node name, the second parameter is a comma delimetered list of its parent nodes (you MUST use null for the first node, however you SHOULD be able to have multiple first nodes for different/multiple characters and things)

Then you can set the flag in game when something happens

Code: ags

  StoryState.SetFlag("GotSword", true,  false);

  // You can check a flag with:
  if (StoryState.GetFlag("GotSword")) // etc


The first param is the node you want to set, the second is the value you want to give it and the third is whether or not you want the setting to be recursive. Which means...

If you want to skip ahead to a part of your game you can set a single node and it will set all the nodes that are parents (and their parents) to the same value.

So you might have a (simple linear for our purposes, it can have multiple branches) tree like this:

Start -> Get Key -> Open Door -> Kill Monster -> Get Girl.

then you can recursively set Open Door to true and the game will assume that the previous steps have been accomplished for other purposes within your game.

The recursion should be good for about 50 levels which may not be enough for a larger game. If it becomes a problem I'll have to come up with a different way of recursion (populating a list and iterating through it probably in stead of functional recursion) but this will serve as a test to see if its actually useful.

Providing you use the system as a replacement for global variables in all cases and set room states and stuff in room load it *should* make story tracking much simpler. I say should because I havent actually tried this in a game yet and it may be more trouble than its worth but i thought i'd throw it out there anyway.

Also it might prove very useful for multiple endings and things because you can easily keep track of the progress of the tree and it progresses and easily set the game state to any point in the story with a single function call.

Let me know if any other functionality would be useful.

EDIT:

This was in response to this thread ( http://www.adventuregamestudio.co.uk/yabb/index.php?topic=44784.msg598839#msg598839 ) but ive only just got round to releasing it.

Dave Gilbert

This is extremely useful, sir! I'll definitely be checking this one out.

Ghost

Good job, Calin! I need to test-drive it a bit more but what I've seen is useful and easy to set up- nicely done!

Knox

This is awesome, integrating it now! Thanks once again :)
--All that is necessary for evil to triumph is for good men to do nothing.

SMF spam blocked by CleanTalk