<?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>Michael Hartmayer - Portfolio &#187; Games</title>
	<atom:link href="http://www.michaelhartmayer.com/tag/games/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.michaelhartmayer.com</link>
	<description>Have a Leet Smoothy</description>
	<lastBuildDate>Wed, 21 Jul 2010 04:04:47 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Custom Scripting Language for Items</title>
		<link>http://www.michaelhartmayer.com/php/custom-scripting-language-for-items/</link>
		<comments>http://www.michaelhartmayer.com/php/custom-scripting-language-for-items/#comments</comments>
		<pubDate>Sun, 21 Jun 2009 02:15:13 +0000</pubDate>
		<dc:creator>Michael Hartmayer</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Games]]></category>
		<category><![CDATA[Item Scripting]]></category>

		<guid isPermaLink="false">http://www.michaelhartmayer.com/?p=253</guid>
		<description><![CDATA[I&#8217;ve been working on some new software.. Below is a prototype version of my proprietary itemScript parser, written in PHP. The goal is to have a pseudo-scripting language available for game-items that can be read dynamically by the server, so that new items can be added without additional hard coding. function scriptToArr&#40;$str&#41; &#123; # Parse [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been working on some new software.. Below is a prototype version of my proprietary itemScript parser, written in PHP. The goal is to have a pseudo-scripting language available for game-items that can be read dynamically by the server, so that new items can be added without additional hard coding.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> scriptToArr<span style="color: #009900;">&#40;</span><span style="color: #000088;">$str</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
   <span style="color: #666666; font-style: italic;"># Parse for Whitespace
</span>   <span style="color: #000088;">$str</span> <span style="color: #339933;">=</span> <span style="color: #990000;">preg_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;#(<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>|<span style="color: #000099; font-weight: bold;">\r</span>|<span style="color: #000099; font-weight: bold;">\n</span>|<span style="color: #000099; font-weight: bold;">\t</span>|\s)#&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$str</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #666666; font-style: italic;"># Event Handlers
</span>   <span style="color: #990000;">preg_match_all</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;#(.*?)\{(.*?)\}(,|)#is&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$str</span><span style="color: #339933;">,</span><span style="color: #000088;">$findEventHandlers</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #000088;">$arrEvents</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$j</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span><span style="color: #000088;">$j</span><span style="color: #339933;">&lt;</span>sizeof<span style="color: #009900;">&#40;</span><span style="color: #000088;">$findEventHandlers</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #000088;">$j</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #666666; font-style: italic;"># this event
</span>      <span style="color: #000088;">$thisEvent</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$findEventHandlers</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$j</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #666666; font-style: italic;"># these functions
</span>      <span style="color: #000088;">$getFunctions</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$findEventHandlers</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$j</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$allFunctions</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;;&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$getFunctions</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #666666; font-style: italic;"># get all parameters
</span>      <span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$allFunctions</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$function</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
         <span style="color: #666666; font-style: italic;"># read and parse function
</span>         <span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;#(.+?)\((.*)\)#&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$function</span><span style="color: #339933;">,</span><span style="color: #000088;">$functionAndPara</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
         <span style="color: #000088;">$thisFunction</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$functionAndPara</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
         <span style="color: #000088;">$thisParaSet</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$functionAndPara</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>               
&nbsp;
         <span style="color: #666666; font-style: italic;"># parse and arr strings
</span>         <span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;#\'(.+),(.+)\'#&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$thisParaSet</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$thisParaSet</span><span style="color: #339933;">=</span><span style="color: #990000;">preg_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;#\'(.+?),(.+?)\'#&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;'<span style="color: #006699; font-weight: bold;">$1</span><span style="color: #660099; font-weight: bold;">\0</span>COMMA<span style="color: #660099; font-weight: bold;">\0</span><span style="color: #006699; font-weight: bold;">$2</span>'&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$thisParaSet</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
         <span style="color: #009900;">&#125;</span>
         <span style="color: #000088;">$thisParaSet</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;,&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$thisParaSet</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
         <span style="color: #666666; font-style: italic;"># get each parameter
</span>         <span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$thisParaSet</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$parameter</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$addPara</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #660099; font-weight: bold;">\0</span>COMMA<span style="color: #660099; font-weight: bold;">\0</span>&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;,&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$parameter</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
               <span style="color: #000088;">$arrEvents</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$thisEvent</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$thisFunction</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$addPara</span><span style="color: #339933;">;</span>
         <span style="color: #009900;">&#125;</span>
      <span style="color: #009900;">&#125;</span>
   <span style="color: #009900;">&#125;</span>
   <span style="color: #b1b100;">return</span> <span style="color: #000088;">$arrEvents</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Here is a sample script I created:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">      onDraw <span style="color: #009900;">&#123;</span>
         setMana<span style="color: #009900;">&#40;</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> thisPlayer<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
         doOtherThing<span style="color: #009900;">&#40;</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">,</span> thisPlayer<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
      onExert <span style="color: #009900;">&#123;</span>
         sendToHand<span style="color: #009900;">&#40;</span> thisTile<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> thisPlayer<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> x<span style="color: #339933;">,</span> y<span style="color: #339933;">,</span> z<span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
      onDestroy <span style="color: #009900;">&#123;</span>
         setMana<span style="color: #009900;">&#40;</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">,</span> thisPlayer<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span></pre></div></div>

<p>The script then gets torn apart and dumped into a multi-dimensional array. See Screenshot.</p>
<p><a href="http://www.michaelhartmayer.com/wp-content/uploads/2009/06/phpItemParse.jpg" rel="lightbox"><img class="alignnone size-medium wp-image-261" title="PHP Item Script Parser" src="http://www.michaelhartmayer.com/wp-content/uploads/2009/06/phpItemParse-300x241.jpg" alt="PHP Item Script Parser" width="300" height="241" /></a></p>

<div class="sociable">
<div class="sociable_tagline">
<strong>Share and Enjoy:</strong>
</div>
<ul>
	<li class="sociablefirst"><a rel="nofollow"  target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.michaelhartmayer.com%2Fphp%2Fcustom-scripting-language-for-items%2F&amp;title=Custom%20Scripting%20Language%20for%20Items&amp;bodytext=I%27ve%20been%20working%20on%20some%20new%20software..%20Below%20is%20a%20prototype%20version%20of%20my%20proprietary%20itemScript%20parser%2C%20written%20in%20PHP.%20The%20goal%20is%20to%20have%20a%20pseudo-scripting%20language%20available%20for%20game-items%20that%20can%20be%20read%20dynamically%20by%20the%20server%2C%20so%20that%20ne" title="Digg"><img src="http://www.michaelhartmayer.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://sphinn.com/index.php?c=post&amp;m=submit&amp;link=http%3A%2F%2Fwww.michaelhartmayer.com%2Fphp%2Fcustom-scripting-language-for-items%2F" title="Sphinn"><img src="http://www.michaelhartmayer.com/wp-content/plugins/sociable/images/sphinn.png" title="Sphinn" alt="Sphinn" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://delicious.com/post?url=http%3A%2F%2Fwww.michaelhartmayer.com%2Fphp%2Fcustom-scripting-language-for-items%2F&amp;title=Custom%20Scripting%20Language%20for%20Items&amp;notes=I%27ve%20been%20working%20on%20some%20new%20software..%20Below%20is%20a%20prototype%20version%20of%20my%20proprietary%20itemScript%20parser%2C%20written%20in%20PHP.%20The%20goal%20is%20to%20have%20a%20pseudo-scripting%20language%20available%20for%20game-items%20that%20can%20be%20read%20dynamically%20by%20the%20server%2C%20so%20that%20ne" title="del.icio.us"><img src="http://www.michaelhartmayer.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.michaelhartmayer.com%2Fphp%2Fcustom-scripting-language-for-items%2F&amp;t=Custom%20Scripting%20Language%20for%20Items" title="Facebook"><img src="http://www.michaelhartmayer.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.mixx.com/submit?page_url=http%3A%2F%2Fwww.michaelhartmayer.com%2Fphp%2Fcustom-scripting-language-for-items%2F&amp;title=Custom%20Scripting%20Language%20for%20Items" title="Mixx"><img src="http://www.michaelhartmayer.com/wp-content/plugins/sociable/images/mixx.png" title="Mixx" alt="Mixx" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fwww.michaelhartmayer.com%2Fphp%2Fcustom-scripting-language-for-items%2F&amp;title=Custom%20Scripting%20Language%20for%20Items&amp;annotation=I%27ve%20been%20working%20on%20some%20new%20software..%20Below%20is%20a%20prototype%20version%20of%20my%20proprietary%20itemScript%20parser%2C%20written%20in%20PHP.%20The%20goal%20is%20to%20have%20a%20pseudo-scripting%20language%20available%20for%20game-items%20that%20can%20be%20read%20dynamically%20by%20the%20server%2C%20so%20that%20ne" title="Google Bookmarks"><img src="http://www.michaelhartmayer.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fwww.michaelhartmayer.com%2Fphp%2Fcustom-scripting-language-for-items%2F&amp;title=Custom%20Scripting%20Language%20for%20Items&amp;source=Michael+Hartmayer+-+Portfolio+Have+a+Leet+Smoothy&amp;summary=I%27ve%20been%20working%20on%20some%20new%20software..%20Below%20is%20a%20prototype%20version%20of%20my%20proprietary%20itemScript%20parser%2C%20written%20in%20PHP.%20The%20goal%20is%20to%20have%20a%20pseudo-scripting%20language%20available%20for%20game-items%20that%20can%20be%20read%20dynamically%20by%20the%20server%2C%20so%20that%20ne" title="LinkedIn"><img src="http://www.michaelhartmayer.com/wp-content/plugins/sociable/images/linkedin.png" title="LinkedIn" alt="LinkedIn" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="https://favorites.live.com/quickadd.aspx?marklet=1&amp;url=http%3A%2F%2Fwww.michaelhartmayer.com%2Fphp%2Fcustom-scripting-language-for-items%2F&amp;title=Custom%20Scripting%20Language%20for%20Items" title="Live"><img src="http://www.michaelhartmayer.com/wp-content/plugins/sociable/images/live.png" title="Live" alt="Live" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.myspace.com/Modules/PostTo/Pages/?u=http%3A%2F%2Fwww.michaelhartmayer.com%2Fphp%2Fcustom-scripting-language-for-items%2F&amp;t=Custom%20Scripting%20Language%20for%20Items" title="MySpace"><img src="http://www.michaelhartmayer.com/wp-content/plugins/sociable/images/myspace.png" title="MySpace" alt="MySpace" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://reddit.com/submit?url=http%3A%2F%2Fwww.michaelhartmayer.com%2Fphp%2Fcustom-scripting-language-for-items%2F&amp;title=Custom%20Scripting%20Language%20for%20Items" title="Reddit"><img src="http://www.michaelhartmayer.com/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" class="sociable-hovers" /></a></li>
	<li class="sociablelast"><a rel="nofollow"  target="_blank" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.michaelhartmayer.com%2Fphp%2Fcustom-scripting-language-for-items%2F&amp;title=Custom%20Scripting%20Language%20for%20Items" title="StumbleUpon"><img src="http://www.michaelhartmayer.com/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" class="sociable-hovers" /></a></li>
</ul>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.michaelhartmayer.com/php/custom-scripting-language-for-items/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
