Skip to main content
1 of 5
MarcusM
  • 33
  • 1
  • 5

Best way to store story actions in XML

I been working on a game in UNITY that reads it's story (Actions, scene descriptions, NPC's, ect...) from an XML and have been wondering there was a better way to store actions based on player data such as item in an inventory or attribute.

An example would be the player having a light source greater then 5 on hand while entering a dark room.

<scene>
 <description>You enter a dark room </description>
 <sceneReq>
  <text>and do not have enough light to see it well.</text>
  <action trigger="player.lightLevel > 4"  sceneIndex="5"/>
 </sceneReq>
</scene>

how should I be able to act on the above logic in C# without hard coding the actions and load dynamically from the XML. Also how should I handle logic in XML if it requires multiple actions or parameters.

For example having a crowbar and the strength greater then 15 to open a door.

<scene>
 <description>You see a stuck door in front of you.</description>
 <sceneReq>
  <text>Your effort to remove the door has failed.</text>
  <and>
   <action trigger="player.item == 1"  sceneIndex="10"/>
   <action trigger="player.strLevel > 15"  sceneIndex="10"/>
  </and>
 </sceneReq>
</scene>

Because I am rather new to parsing XML I can't think of a way to break the logic out of the XML and use it in code dynamically. I looked over http://stackoverflow.com/questions/372915/game-logic-in-xml-files and really did not seem to answer my question on how to solve it in C#.

MarcusM
  • 33
  • 1
  • 5