<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Quitting game when player fails</title>
		<link>http://www.allegro.cc/forums/view/596518</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Thu, 29 May 2008 19:39:54 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>My game will end when player fails to complete one level. So I thought of making one function that plays the level and returns true if player succeeds and false otherwise. Each level will be harder than the previous and at some point the levels are impossible, so I might not need a final &quot;Congrats, end of game jadajada&quot; thing. So I thought of this: [edit] I lined up the columns
</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">if</span> <span class="k2">(</span>play_level<span class="k2">(</span><span class="n">1</span>,  <span class="n">60</span>,  <span class="n">120</span><span class="k2">)</span> <span class="k3">&amp;</span><span class="k3">&amp;</span>
    play_level<span class="k2">(</span><span class="n">2</span>,  <span class="n">70</span>,  <span class="n">125</span><span class="k2">)</span> <span class="k3">&amp;</span><span class="k3">&amp;</span>
    play_level<span class="k2">(</span><span class="n">3</span>,  <span class="n">80</span>,  <span class="n">130</span><span class="k2">)</span> <span class="k3">&amp;</span><span class="k3">&amp;</span>
    play_level<span class="k2">(</span><span class="n">4</span>,  <span class="n">90</span>,  <span class="n">135</span><span class="k2">)</span> <span class="k3">&amp;</span><span class="k3">&amp;</span>
    play_level<span class="k2">(</span><span class="n">5</span>, <span class="n">100</span>,  <span class="n">140</span><span class="k2">)</span> <span class="k3">&amp;</span><span class="k3">&amp;</span>
    play_level<span class="k2">(</span><span class="n">6</span>, <span class="n">110</span>,  <span class="n">140</span><span class="k2">)</span><span class="k2">)</span>
        my_alert<span class="k2">(</span><span class="s">"Congrats, end of game jadajada"</span><span class="k2">)</span><span class="k2">;</span>

<span class="c">// do stuff with the score...</span>
</pre></div></div><p>
The parameters of the function call are level number, number of items to collect, available time (I might extend the parameter list). But my question is, will this work. The play_level calls are supposed to happen consecutively, until one of them returns false, and after that the following lines are not executed.</p><p>Some compiler settings might force all calls to be executed, no matter whether true or false. But is it possible that some compilers will force all calls in any case? And can I rely on that every compiler makes the functions to be called in that exact order?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Johan Halmén)</author>
		<pubDate>Thu, 29 May 2008 13:44:33 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="source-code snippet"><div class="inner"><pre><span class="k1">if</span> <span class="k2">(</span><span class="n">0</span> <span class="k3">&amp;</span><span class="k3">&amp;</span> foo<span class="k2">(</span><span class="k2">)</span><span class="k2">)</span> <span class="k2">{</span><span class="k2">}</span>
</pre></div></div><p>

foo() is guaranteed to never be called. Anything else would be a tragedy.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Matthew Leverton)</author>
		<pubDate>Thu, 29 May 2008 13:48:14 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>&amp;&amp; : The C standard guarantees order of evaluation from left to right, and no evaluation of the right part if the left part evaluated to 0.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Audric)</author>
		<pubDate>Thu, 29 May 2008 13:48:24 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Why not use a for loop?
</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">bool</span> playmore <span class="k3">=</span> <span class="k1">true</span><span class="k2">;</span>
<span class="k1">int</span> level <span class="k3">=</span> <span class="n">1</span><span class="k2">;</span>
<span class="k1">int</span> numitems<span class="k2">[</span><span class="n">6</span><span class="k2">]</span> <span class="k3">=</span> <span class="k2">{</span> <span class="n">60</span>,<span class="n">70</span>,<span class="n">80</span>,<span class="n">90</span>,<span class="n">100</span>,<span class="n">110</span> <span class="k2">}</span><span class="k2">;</span>
<span class="k1">int</span> timeavail<span class="k2">[</span><span class="n">6</span><span class="k2">]</span> <span class="k3">=</span> <span class="k2">{</span> <span class="n">120</span>,<span class="n">125</span>,<span class="n">130</span>,<span class="n">135</span>,<span class="n">140</span>,<span class="n">140</span> <span class="k2">}</span><span class="k2">;</span>

<span class="k1">for</span><span class="k2">(</span> <span class="k2">;</span> level<span class="k3">&lt;</span><span class="n">6</span> <span class="k3">&amp;</span><span class="k3">&amp;</span> playmore<span class="k2">;</span> i<span class="k3">+</span><span class="k3">+</span><span class="k2">)</span>
<span class="k2">{</span>
  playmore <span class="k3">=</span> play_level<span class="k2">(</span>level,numitems<span class="k2">[</span>level<span class="k2">]</span>,timeavail<span class="k2">[</span>level<span class="k2">]</span><span class="k2">)</span><span class="k2">;</span>
<span class="k2">}</span>

myalert<span class="k2">(</span><span class="s">"GZ, you made it to level &amp;d"</span>,level<span class="k2">)</span><span class="k2">;</span>
<span class="c">// do stuff with the score</span>
</pre></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (ixilom)</author>
		<pubDate>Thu, 29 May 2008 14:04:10 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hehe, reminds me of a bug I read about in one game, where they had what basically amounts to<br /><span class="source-code"> <span class="k1">if</span> <span class="k2">(</span>Random<span class="k2">(</span><span class="k2">)</span> <span class="k3">+</span> modifiers <span class="k3">&gt;</span> Random<span class="k2">(</span><span class="k2">)</span> <span class="k3">+</span> other_modifiers<span class="k2">)</span> <span class="k2">{</span><span class="k1">do</span> stuff<span class="k2">;</span><span class="k2">}</span></span><br />And on some OSs the left Random() would be called first, and on some the right would be called first.<br />This meant that recreating the same results by using the same seed failed between different OSs.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Slartibartfast)</author>
		<pubDate>Thu, 29 May 2008 14:09:01 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
And on some OSs the left Random() would be called first, and on some the right would be called first.
</p></div></div><p>

That&#39;s because the order of evaluation is not defined here. In case of operators <tt>&amp;&amp;</tt>, <tt>||</tt> and <tt>?:</tt> it is, though, as already stated. For all other operators, it&#39;s best not to rely on the order of execution. If you need the guarantee, extract those bits to local variables.</p><p>That said, what you&#39;re trying to achieve works with all <i>ISO C compliant</i> compilers, Mr. Halmén.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Indeterminatus)</author>
		<pubDate>Thu, 29 May 2008 14:32:06 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
That said, what you&#39;re trying to achieve works with all ISO C compliant compilers, Mr. Halmén.
</p></div></div><p>
However I would prefer a loop method, since the above idea looks uncomfortable to me. At least the loop will save you some typing.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (OICW)</author>
		<pubDate>Thu, 29 May 2008 17:00:49 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">OICW said:</div><div class="quote"><p>
However I would prefer a loop method, since the above idea looks uncomfortable to me.
</p></div></div><p>

Seconded, albeit that was not the question <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Indeterminatus)</author>
		<pubDate>Thu, 29 May 2008 17:15:21 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I don&#39;t count copy+paste as typing. I don&#39;t care whether I have 20 or 50 lines of those play_level calls. I like it when the parameters get in columns. I might write:<br /><span class="source-code">play_level<span class="k2">(</span><span class="n">00</span>, <span class="n">060</span>, <span class="n">120</span><span class="k2">)</span> <span class="k3">&amp;</span><span class="k3">&amp;</span></span><br />Then I copy, then I paste 50 times. Then I quickly number the levels (the two zeros),  right hand pushes on down arrow and backspace, left hand runs over keys 0-9 repeatedly - yes, <i>that&#39;s</i> typing, but simple, systematic and fast. Then I change the other parameters to whatever I want. The lines and columns in my code tell me more about the levels than the separate int arrays in ixilom&#39;s example. Of course one can line up the values in the arrays with spaces or tabs, but fifty ints on one line of code won&#39;t work. Especially if you want to make them match with an array on the next line.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Johan Halmén)</author>
		<pubDate>Thu, 29 May 2008 17:32:01 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Just take care, in source 060 ist not exactly what you might expect...
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (tobing)</author>
		<pubDate>Thu, 29 May 2008 17:34:03 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
Then I change the other parameters to whatever I want. The lines and columns in my code tell me more about the levels than the separate int arrays in ixilom&#39;s example.
</p></div></div><p>You can easily merge the two arrays you know.</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">int</span> levels<span class="k2">[</span><span class="n">6</span><span class="k2">]</span><span class="k2">[</span><span class="n">2</span><span class="k2">]</span> <span class="k3">=</span> <span class="k2">{</span>
  <span class="c">/* num, time */</span>
   <span class="k2">{</span> <span class="n">60</span>,  <span class="n">120</span> <span class="k2">}</span>,
   <span class="k2">{</span> <span class="n">70</span>,  <span class="n">125</span> <span class="k2">}</span>,
   <span class="k2">{</span> <span class="n">80</span>,  <span class="n">130</span> <span class="k2">}</span>,
   <span class="k2">{</span> <span class="n">90</span>,  <span class="n">135</span> <span class="k2">}</span>,
   <span class="k2">{</span> <span class="n">100</span>, <span class="n">140</span> <span class="k2">}</span>,
   <span class="k2">{</span> <span class="n">110</span>, <span class="n">140</span> <span class="k2">}</span>,
<span class="k2">}</span><span class="k2">;</span>

<span class="k1">for</span><span class="k2">(</span> <span class="k2">;</span> level<span class="k3">&lt;</span><span class="n">6</span> <span class="k3">&amp;</span><span class="k3">&amp;</span> playmore<span class="k2">;</span> i<span class="k3">+</span><span class="k3">+</span><span class="k2">)</span>
<span class="k2">{</span>
        playmore <span class="k3">=</span> play_level<span class="k2">(</span>level,levels<span class="k2">[</span>level<span class="k2">]</span><span class="k2">[</span><span class="n">0</span><span class="k2">]</span>,levels<span class="k2">[</span>level<span class="k2">]</span><span class="k2">[</span><span class="n">1</span><span class="k2">]</span><span class="k2">)</span><span class="k2">;</span>
<span class="k2">}</span>
</pre></div></div><p>

Or somesuch.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Thu, 29 May 2008 17:42:17 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Just to nitpick some. I wouldn&#39;t hardcode those values at all <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (ixilom)</author>
		<pubDate>Thu, 29 May 2008 18:10:36 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
Just to nitpick some. I wouldn&#39;t hardcode those values at all <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" />
</p></div></div><p>Neither would I...
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Thu, 29 May 2008 18:13:15 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">ixilom said:</div><div class="quote"><p>
Just to nitpick some. I wouldn&#39;t hardcode those values at all <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" />
</p></div></div><p>

KISS. <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" /> There&#39;s nothing wrong with Johan&#39;s way, it gets the job done, and only requires very little development time in doing so. Everything else (loading those parameters from [external, ed.] data, for instance) can be added later on, should it be needed at all.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Indeterminatus)</author>
		<pubDate>Thu, 29 May 2008 18:20:55 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>TF&#39;s array works exactly as well as my calls!</p><p>And I <i>will</i> hardcode them. The alternative would be to have some script system, like cfg files, and that would require error checking and stuff to be as reliable as hardcoding.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Johan Halmén)</author>
		<pubDate>Thu, 29 May 2008 18:36:33 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I have only one observation, it&#39;s that this single C statement from &quot;if&quot; to &quot;;&quot; handles many things at once: <br />which level is first,<br />which level follows which one,<br />detect when player loses,<br />detect when player quits,<br />detect when player wins and launch endgame sequence.</p><p>In most games, the sequence of events varies, especially if you start adding cheat keys to warp to any level (It makes it way easier to test the game).<br />It&#39;s one of the rare cases where I&#39;d recommend a very loose program structure:
</p><ul><li><p>A while(true) loop, so you can repeat the level-init and level-play parts as many times as there is a &quot;level&quot; to play.</p></li><li><p>After level-play: individual if() blocks that identify if the level was won, lost, aborted, etc, and what you want to happen in each case.In these blocks you can use return to exit the current function, &quot;break&quot; to stop the loop (execution will resume at the instruction after &quot;while() {}&quot; ), or &quot;continue&quot; to go back to the beginning of the loop, where a new level will start.</p></li></ul><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Audric)</author>
		<pubDate>Thu, 29 May 2008 19:39:54 +0000</pubDate>
	</item>
</rss>
