<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>CoderHump.com &#187; tweak</title>
	<atom:link href="http://coderhump.com/archives/tag/tweak/feed" rel="self" type="application/rss+xml" />
	<link>http://coderhump.com</link>
	<description>Game Development Technology, in Flash and Elsewhere</description>
	<lastBuildDate>Tue, 06 Jul 2010 17:18:41 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Tweaking your game with Google Spreadsheets</title>
		<link>http://coderhump.com/archives/385</link>
		<comments>http://coderhump.com/archives/385#comments</comments>
		<pubDate>Sun, 01 Feb 2009 07:42:04 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Cool Stuff]]></category>
		<category><![CDATA[How To]]></category>
		<category><![CDATA[PushButton Engine]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[spreadsheets]]></category>
		<category><![CDATA[tweak]]></category>

		<guid isPermaLink="false">http://coderhump.com/?p=385</guid>
		<description><![CDATA[ Our latest game, Grunts: Skirmish, has 200 tweakable parameters. There are 9 player units with three levels of upgrade, and another 9 enemy units. Each unit has between three and ten parameters that can be altered.
We tried a few approaches &#8211; hand-editing a large XML file (but it was too large and spread out) [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://coderhump.com/wp-content/uploads/2009/02/tweaksheet.png" alt="tweaksheet" title="tweaksheet" width="300" height="270" class="alignright size-full wp-image-386" /> Our latest game, <a href="http://makeitbigingames.com/2009/01/woohoo-grunts-skirmish-has-a-logo/">Grunts: Skirmish</a>, has <b>200 tweakable parameters</b>. There are 9 player units with three levels of upgrade, and another 9 enemy units. Each unit has between three and ten parameters that can be altered.</p>
<p>We tried a few approaches &#8211; <b>hand-editing a large XML file</b> (but it was too large and spread out) and an in-game <b>tweaking UI</b> (but it was too much work to get the UI to be friendly to use). The old standby of having <a href="http://makeitbigingames.com/">the designer</a> and <a href="http://subreal.net/">artist</a> <b>file bug reports</b> to have <a href="http://coderhump.com/">the programmer</a> update the game wasn&#8217;t getting us very far, either.</p>
<p>&#8220;Well,&#8221; says I, &#8220;We&#8217;re some sort of Web 2.0 startup, right? And we&#8217;re developing a Flash game aren&#8217;t we? And Flash can talk to websites, can&#8217;t it? And don&#8217;t we use Google Docs for everything?&#8221;</p>
<p>It turns out there is an <a href="http://code.google.com/apis/spreadsheets/docs/2.0/reference.html#CellFeed">XML feed from public Google spreadsheets</a>. And ActionScript 3 supports <a href="http://en.wikipedia.org/wiki/E4X">E4X</a>, so you can directly manipulate XML without any extra work. <b>Now we tweak our game using a shared spreadsheet up on Google Docs.</b></p>
<p>I wrote a parser for their format:</p>
<pre><code>// Extract the entries. It's namespaced, so deal with that.
var xmlns:Namespace = new Namespace("xmlns", "http://www.w3.org/2005/Atom");
tweakXML.addNamespace(xmlns);

// Parse into a dictionary.
var cellDictionary:Dictionary = new Dictionary();
for each(var entryXML:XML in tweakXML.xmlns::entry)
{
   cellDictionary[entryXML.xmlns::title.toString()] = entryXML.xmlns::content.toString();
}</code></pre>
<p>And wrote a quick component that would fetch the spreadsheet feed, parse it, and stuff it into the right places on named objects or template data. Now I have a little entry in our level file that looks like:</p>
<pre><code>&lt;object id="googleTweaker"&gt;
   &lt;component class="com.pblabs.debug.GoogleSpreadsheetTweaker"&gt;
     &lt;SpreadsheetUrl&gt;http://spreadsheets.google.com/feeds/cells/0d8somekey848x/od6/public/basic&lt;/SpreadsheetUrl&gt;
     &lt;Config&gt;
        &lt;!--  Grunt Level 1 tweaks --&gt;
        &lt;_&gt;&lt;Cell&gt;B3&lt;/Cell&gt;&lt;Property&gt;#TheGruntProxy.creator.WarPointCost&lt;/Property&gt;&lt;/_&gt;
        &lt;_&gt;&lt;Cell&gt;C3&lt;/Cell&gt;&lt;Property&gt;!Grunt.health.mMaxHealth&lt;/Property&gt;&lt;/_&gt;
        &lt;_&gt;&lt;Cell&gt;D3&lt;/Cell&gt;&lt;Property&gt;!Grunt.ai.AttackSearchRadius&lt;/Property&gt;&lt;/_&gt;
     &lt;/Config&gt;
  &lt;/component&gt;
&lt;/object&gt;</code></pre>
<p>Each line maps a cell in the spreadsheet to a property on a template or active game object. Some properties have to be set several places, which the system deals with automatically.</p>
<p>The biggest wrinkle was Google&#8217;s crossdomain.xml policy. Basically they do not allow random Flash apps to access their site. So I had to write a small proxy script, which sits on our development server next to the game and fetches the data for it. Figuring out I had to do this took more time than any other step.</p>
<p>The main difference between the snippet and the full code is the version in our repository is 220 lines long. I only have around 150 of the full set of 200 parameters hooked up, but after a hard afternoon&#8217;s work, the process for tweaking the game has become:</p>
<ol>
<li>Open Google Docs.</li>
<li>Edit a clearly labeled value &#8211; like level 1 grunt health.</li>
<li>Restart the game, which is running in another tab in your browser.</li>
</ol>
<p><b>This takes you about a minute between trials.</b> Not too bad. Before this, the process was:</p>
<ol>
<li>Get the game source from SVN.</li>
<li>Find the right XML file &#8211; there are several.</li>
<li>Find the right section in the XML &#8211; altogether we have 200kb of the stuff for Grunts!</li>
<li>Change the value.</li>
<li>Commit the change.</li>
<li>Wait 5-15 minutes for the build system to refresh the live version of the game.</li>
</ol>
<p><b>Ten minutes per tweak is not a good way to develop.</b></p>
<p>I&#8217;ve heard about developers using Excel spreadsheets for tweaking, but can&#8217;t find anything about using Google Docs to do it. <b>But Google Spreadsheet is obviously a better choice</b>. It has built-in revision tracking. You can edit it simultaneously with someone else. You can access live data in XML either publicly (like we did) or privately via their authentication API. It&#8217;s absolutely worth the half-day of your time it will take to add Google Spreadsheet-based tweaking to your game &#8211; even if it&#8217;s a non-Flash game, downloading and parsing XML is pretty easy with the right libraries.</p>
<p>I strongly suspect this feature will find its way into the next beta of the <a href="http://www.pushbuttonengine.com/">PushButton Engine</a>. Which, by the way, you should sign up for if you are interested in developing Flash games. <b>We&#8217;re bringing people in from the signup form starting this week.</b> If you want more information, or just like looking at cool websites, click below to check out the new version of the PBEngine site, which has a bunch of information on the tech. <a href="http://subreal.net/">Tim</a> did an awesome job on the site design.</p>
<p><a href="http://pushbuttonengine.com/"><img src="http://coderhump.com/wp-content/uploads/2009/02/betashot.png" alt="betashot" title="betashot" width="565" height="217" class="aligncenter size-full wp-image-400" /></a></p>
<p><b>Edit:</b> Patrick over on the GG forums asked about the proxy script. It&#8217;s actually ludicrously simple. Not very secure either so I wouldn&#8217;t recommend deploying it on a public server. I got my script from a post on <a href="http://www.adenforshaw.co.uk/?p=4">Aden Forshaw&#8217;s blog</a>. In the real world you would want to have some security token to limit access to your proxy script&#8230; but since this is for tweaking a game that is in development I didn&#8217;t sweat it.</p>
]]></content:encoded>
			<wfw:commentRss>http://coderhump.com/archives/385/feed</wfw:commentRss>
		<slash:comments>25</slash:comments>
		</item>
	</channel>
</rss>
