<?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>Building Browsergames &#187; crafting</title>
	<atom:link href="http://buildingbrowsergames.com/tag/crafting/feed/" rel="self" type="application/rss+xml" />
	<link>http://buildingbrowsergames.com</link>
	<description>Ever wanted to build a browsergame?</description>
	<lastBuildDate>Mon, 29 Mar 2010 14:00:39 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Rawrmy&#8217;s Crafting System</title>
		<link>http://buildingbrowsergames.com/2008/11/10/rawrmys-crafting-system/</link>
		<comments>http://buildingbrowsergames.com/2008/11/10/rawrmys-crafting-system/#comments</comments>
		<pubDate>Mon, 10 Nov 2008 14:00:12 +0000</pubDate>
		<dc:creator>Luke</dc:creator>
				<category><![CDATA[diaryofabrowsergame]]></category>
		<category><![CDATA[crafting]]></category>
		<category><![CDATA[doab]]></category>
		<category><![CDATA[frustrations]]></category>

		<guid isPermaLink="false">http://buildingbrowsergames.com/?p=557</guid>
		<description><![CDATA[This week was spent working on Rawrmy&#8217;s escort and crafting system.
One of the things that I struggled with this week was the limitations of Django&#8217;s queryset API &#8211; while it&#8217;s both powerful and flexible, there are a few things that it cannot do. This problem reared it&#8217;s head when I was working on the crafting [...]]]></description>
			<content:encoded><![CDATA[<p>This week was spent working on Rawrmy&#8217;s escort and crafting system.</p>
<p>One of the things that I struggled with this week was the limitations of Django&#8217;s queryset API &#8211; while it&#8217;s both powerful <strong>and</strong> flexible, there are a few things that it cannot do. This problem reared it&#8217;s head when I was working on the crafting system.</p>
<p>When a player goes to craft an item, they are presented with a multi-select that will display all of the craftable items in their inventory. They then select which items they would like to craft with, and we retrieve anything that they can make out of them.</p>
<p>The problem, here, is that &#8216;ingredients&#8217; on our craftables is a ManyToManyField &#8211; and I wanted to retrieve an exact match. For example, if a player had tried to craft with &#8216;flour&#8217; and &#8216;yeast&#8217;, any craftable with &#8216;flour&#8217; or &#8216;yeast&#8217; <strong>and not &#8217;sugar&#8217;</strong> would be returned. Retrieving the &#8216;flour&#8217; and &#8216;yeast&#8217; craftables was easy, using an __in query:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">	craftables = Craftables.<span style="color: black;">objects</span>.<span style="color: #008000;">filter</span><span style="color: black;">&#40;</span>ingredients__in=form.<span style="color: black;">cleaned_data</span><span style="color: black;">&#91;</span><span style="color: #483d8b;">'ingredients])</span></pre></div></div>

<p>However, making sure that the &#8217;sugar&#8217; craftables were not retrieved was slightly more difficult(and took me a while to figure out). Essentially, the process involves first creating a list of ingredients that are <strong>not</strong> in the group of selected ingredients, and then excluding any craftable with ingredients in that list(after we filtered). The new code looked something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">	bad_ids = <span style="color: black;">&#91;</span>ingredient.<span style="color: #008000;">id</span> <span style="color: #ff7700;font-weight:bold;">for</span> ingredient <span style="color: #ff7700;font-weight:bold;">in</span> form.<span style="color: black;">cleaned_data</span><span style="color: black;">&#91;</span><span style="color: #483d8b;">'ingredients'</span><span style="color: black;">&#93;</span><span style="color: black;">&#93;</span>
	craftable = Craftable.<span style="color: black;">objects</span>.<span style="color: #008000;">filter</span><span style="color: black;">&#40;</span>ingredients__in=form.<span style="color: black;">cleaned_data</span><span style="color: black;">&#91;</span><span style="color: #483d8b;">'ingredients'</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>.<span style="color: black;">exclude</span><span style="color: black;">&#40;</span>ingredients__in=Item.<span style="color: black;">objects</span>.<span style="color: black;">exclude</span><span style="color: black;">&#40;</span>id__in=bad_ids<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>Unfortunately, that only seemed to work in <strong>some</strong> cases &#8211; and as a result, I&#8217;ve been debugging and rebugging the same piece of code for most of the week.</p>
<p>This slowdown is unfortunate &#8211; but I think that, moving forward, the crafting system is going to get replaced with a simpler two dropdown system and learnable recipes.</p>
<h2>Completed this week:</h2>
<ul>
<li>Laid the groundwork for crafting and the escort system.</li>
</ul>
<h2>Still to do:</h2>
<ul>
<li>Fix the bugs in crafting item retrieval &#8211; they&#8217;re a gamebreaker right now.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://buildingbrowsergames.com/2008/11/10/rawrmys-crafting-system/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

