Saturday 9 January 2010

Tweaking variables using XML (Part 2)

In my previous post I talked about the method I'll be using to tweak values in runtime. Today, I created some code to demonstrate this method. It's an iterative process, so improvements will follow.

In the provided sample the method is explained using a Vehicle class, with two instances of that class. the static 'FrictionDef' variable will declare the value that every instance of the class should use. a private 'frictionDef' variable will allow an instance to set this static value using the XMLSerializer. You as a developer can manually change the value of 'frictionDef' in the XML file (called 'SuperCar.xml' in this sample) and reload the file to set all instances to the new assigned values in the xml file. You can use this method to quickly change values in runtime on PC. For Xbox, the 'XNA console component' could help us out setting values in the xml file (of course, you will need a 'chatpad' to properly use the console on Xbox) so other solutions are still being explored. I've yet to implement this feature into the engine so I'll save it for a later blog entry.

For PC developers: keeping this type of gameplay specific data in easily readable XML format, will allow for easy cheating by players. You might want to consider running it through the content pipeline (as binary) when you're done tweaking. Alternatively, you might simply remove the whole code used to tweak, and assign the values to the variables in your source code. Doing so, will still safe you a lot of time compared to rebuilding your project for every slightly changed variable while tweaking your game.

Some articles of interest:

Shawn Hargreaves Blog: MotoGP Tweakables

Luminance: Changing constants at runtime

Link to sample code:

XML Tweaking Sample

Video

No comments:

Post a Comment