<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Timers</title>
		<link>http://www.allegro.cc/forums/view/586247</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Mon, 03 Jul 2006 22:58:43 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Is there a possible way I can wait a certain number of seconds(Even down to the fractions if possible) so that it&#39;s the same speed on all computers?  I think that if you used rest it would work, but I have to be precise with the timing with this program.  I&#39;m not very well versed in delta time or any of that stuff, so an explanation on how I can wait &quot;real&quot; seconds would be great.  Thanks.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Paladin)</author>
		<pubDate>Mon, 03 Jul 2006 20:53:15 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="source-code snippet"><div class="inner"><pre><span class="k1">volatile</span> <span class="k1">unsigned</span> <span class="k1">int</span>    timer<span class="k2">;</span>
</pre></div></div><p>

somewhere else...</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">void</span> tick<span class="k2">(</span><span class="k2">)</span>
<span class="k2">{</span>
    timer<span class="k3">+</span><span class="k3">+</span><span class="k2">;</span>
<span class="k2">}</span>
<a href="http://www.allegro.cc/manual/END_OF_FUNCTION" target="_blank"><span class="a">END_OF_FUNCTION</span></a> <span class="k2">(</span>tick<span class="k2">)</span>
</pre></div></div><p>

elsewhere...</p><div class="source-code snippet"><div class="inner"><pre>    <a href="http://www.allegro.cc/manual/LOCK_VARIABLE" target="_blank"><span class="a">LOCK_VARIABLE</span></a><span class="k2">(</span>timer<span class="k2">)</span><span class="k2">;</span>
    <a href="http://www.allegro.cc/manual/LOCK_FUNCTION" target="_blank"><span class="a">LOCK_FUNCTION</span></a><span class="k2">(</span>tick<span class="k2">)</span><span class="k2">;</span>
    <a href="http://www.allegro.cc/manual/install_int" target="_blank"><span class="a">install_int</span></a><span class="k2">(</span>tick, <span class="n">1</span><span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>

timer increases 1 every millisecond.  that&#39;s about it :p 1,000 ms to a second</p><div class="source-code snippet"><div class="inner"><pre>        <span class="k1">if</span> <span class="k2">(</span>timer % <span class="n">10</span> <span class="k3">=</span><span class="k3">=</span> <span class="n">0</span><span class="k2">)</span>
        <span class="k2">{</span>
            Logic-&gt;DoLogic<span class="k2">(</span>scene<span class="k2">)</span><span class="k2">;</span>
        <span class="k2">}</span>
</pre></div></div><p>

Do logic 100 times per second.  Note that yours won&#39;t look exactly the same... I just ripped this right out of something I&#39;m working on right now, hehe
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (BrknPhoenix)</author>
		<pubDate>Mon, 03 Jul 2006 20:57:01 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Ok so now that I have the timer code, how can I like use &quot;rest()&quot; with this function?  I want the gamae to use a for loop and at the end of the loop, wait 2 seconds(example) and then repeat the for loop.  Is this possible?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Paladin)</author>
		<pubDate>Mon, 03 Jul 2006 21:17:07 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Warning: You probably need to rethink your design! You should do something where an object has a counter counting up to 2 seconds, then goes into the loop state afterwards, where it sotres its iterator. Basically, instead of using rest, look into state-based programming.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (CGamesPlay)</author>
		<pubDate>Mon, 03 Jul 2006 21:20:46 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
Ok so now that I have the timer code, how can I like use &quot;rest()&quot; with this function? I want the gamae to use a for loop and at the end of the loop, wait 2 seconds(example) and then repeat the for loop. Is this possible?
</p></div></div><p>

You don&#39;t want to use rest with it <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" />  See the line that says:</p><p><span class="source-code"><span class="k1">if</span> <span class="k2">(</span>timer % <span class="n">10</span> <span class="k3">=</span><span class="k3">=</span> <span class="n">0</span><span class="k2">)</span></span></p><p>Since your timer is incrementing by 1 every millisecond, that event will occur every 10 milliseconds, which amounts to 100 times per second consistently through the duration of the program.  If you are looking to just keep the program running the same speed on all systems as you said in your original post, just put your logic in that if block and you have done it <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" /></p><p>If you want to time in another way, then you need to store the end time and do...something... until you reach the end time.</p><p>So if you just wanted to pause two seconds, you could do something like:</p><div class="source-code snippet"><div class="inner"><pre>eTime <span class="k3">=</span> <a href="http://www.delorie.com/djgpp/doc/libc/libc_821.html" target="_blank">time</a> <span class="k3">+</span> <span class="n">2000</span><span class="k2">;</span> <span class="c">// 2 seconds from now</span>
<span class="k1">while</span><span class="k2">(</span><a href="http://www.delorie.com/djgpp/doc/libc/libc_821.html" target="_blank">time</a> <span class="k3">&lt;</span> eTime<span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>

edit: whoops made a mistake
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (BrknPhoenix)</author>
		<pubDate>Mon, 03 Jul 2006 21:21:17 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Damnit, I&#39;m getting confused.  So would something like this work?</p><div class="source-code snippet"><div class="inner"><pre><span class="c">//This is the main loop</span>
<span class="k1">while</span><span class="k2">(</span><span class="k3">!</span><a href="http://www.allegro.cc/manual/key" target="_blank"><span class="a">key</span></a><span class="k2">[</span>KEY_ESC<span class="k2">]</span><span class="k2">)</span>
<span class="k2">{</span>
 <span class="k1">if</span><span class="k2">(</span>timer <span class="k3">=</span><span class="k3">=</span> <span class="n">230</span><span class="k2">)</span><span class="c">//.23 Seconds I think according to brknphoenix</span>
 <span class="k2">{</span>
  doaction<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
  timer <span class="k3">=</span> <span class="n">0</span><span class="k2">;</span>
 <span class="k2">}</span>
<span class="k2">}</span>
</pre></div></div><p>

Is that what you mean cgamesplay?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Paladin)</author>
		<pubDate>Mon, 03 Jul 2006 21:27:46 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>That won&#39;t work because it&#39;ll reset your timer every .23 seconds...  Just do timer % 10...  Every tenth millisecond it will run your logic, so it will end up doing it 100 times per second.  Let the number count up without resetting it, it can go up to like over 4 billion <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" /></p><p>edit: And note what the actual number is, is not important... the value of it, I mean.  we&#39;re just using it to time with...</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">if</span> <span class="k2">(</span>timer % <span class="n">10</span> <span class="k3">=</span><span class="k3">=</span> <span class="n">0</span><span class="k2">)</span>
<span class="k2">{</span>
    <span class="c">//do stuff</span>
<span class="k2">}</span>
</pre></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (BrknPhoenix)</author>
		<pubDate>Mon, 03 Jul 2006 21:32:34 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Here is an example, done in C because C++ requires too much indenation:
</p><div class="source-code"><div class="toolbar"></div><div class="inner"><table width="100%"><tbody><tr><td class="number">1</td><td><span class="c">// BallState variables</span></td></tr><tr><td class="number">2</td><td>&#160;</td></tr><tr><td class="number">3</td><td><span class="p">#define BS_FROZEN 1</span></td></tr><tr><td class="number">4</td><td><span class="p">#define BS_BOUCING 2</span></td></tr><tr><td class="number">5</td><td>&#160;</td></tr><tr><td class="number">6</td><td><span class="k1">struct</span> ball</td></tr><tr><td class="number">7</td><td><span class="k2">{</span></td></tr><tr><td class="number">8</td><td>    <span class="k1">int</span> state<span class="k2">;</span></td></tr><tr><td class="number">9</td><td>    <span class="k1">int</span> <a href="http://www.delorie.com/djgpp/doc/libc/libc_821.html" target="_blank">time</a><span class="k2">;</span></td></tr><tr><td class="number">10</td><td>    <span class="k1">int</span> x, y<span class="k2">;</span></td></tr><tr><td class="number">11</td><td>    <span class="k1">int</span> dx, dy<span class="k2">;</span></td></tr><tr><td class="number">12</td><td><span class="k2">}</span><span class="k2">;</span></td></tr><tr><td class="number">13</td><td>&#160;</td></tr><tr><td class="number">14</td><td><span class="k1">void</span> upd_ball<span class="k2">(</span>ball<span class="k3">*</span> b<span class="k2">)</span></td></tr><tr><td class="number">15</td><td><span class="k2">{</span></td></tr><tr><td class="number">16</td><td>    <span class="c">// This function adds to the ball's timer.</span></td></tr><tr><td class="number">17</td><td>    <span class="k3">+</span><span class="k3">+</span>b-&gt;time<span class="k2">;</span></td></tr><tr><td class="number">18</td><td>    <span class="c">// If the ball is frozen and 2 secodns has elapsed, start bouncing again.</span></td></tr><tr><td class="number">19</td><td>    <span class="k1">if</span><span class="k2">(</span>b-&gt;state <span class="k3">=</span><span class="k3">=</span> BS_FROZEN <span class="k3">&amp;</span><span class="k3">&amp;</span> b-&gt;time <span class="k3">&gt;</span><span class="k3">=</span> <span class="n">2000</span><span class="k2">)</span></td></tr><tr><td class="number">20</td><td>        goto_ball_state<span class="k2">(</span>b, BS_BOUNCING<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">21</td><td>    <span class="k1">else</span></td></tr><tr><td class="number">22</td><td>    <span class="k2">{</span>   <span class="c">// Otherwise if the ball has been bouncing for 3 seconds, freeze it.</span></td></tr><tr><td class="number">23</td><td>        <span class="k1">if</span><span class="k2">(</span>b-&gt;time <span class="k3">&gt;</span><span class="k3">=</span> <span class="n">3000</span><span class="k2">)</span></td></tr><tr><td class="number">24</td><td>            goto_ball_state<span class="k2">(</span>b, BS_FROZEN<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">25</td><td>        <span class="c">// Bounce the ball around the screen.</span></td></tr><tr><td class="number">26</td><td>        b-&gt;y <span class="k3">+</span><span class="k3">=</span> b-&gt;dy<span class="k2">;</span></td></tr><tr><td class="number">27</td><td>        b-&gt;x <span class="k3">+</span><span class="k3">=</span> b-&gt;dx<span class="k2">;</span></td></tr><tr><td class="number">28</td><td>        <span class="k1">if</span><span class="k2">(</span>b-&gt;x <span class="k3">&gt;</span> <a href="http://www.allegro.cc/manual/SCREEN_W" target="_blank"><span class="a">SCREEN_W</span></a> <span class="k3">|</span><span class="k3">|</span> b-&gt;x <span class="k3">&lt;</span> <span class="n">0</span><span class="k2">)</span></td></tr><tr><td class="number">29</td><td>            b-&gt;dx <span class="k3">=</span> <span class="k3">-</span>b-&gt;dx<span class="k2">;</span></td></tr><tr><td class="number">30</td><td>        <span class="k1">if</span><span class="k2">(</span>b-&gt;y <span class="k3">&gt;</span> <a href="http://www.allegro.cc/manual/SCREEN_H" target="_blank"><span class="a">SCREEN_H</span></a> <span class="k3">|</span><span class="k3">|</span> b-&gt;y <span class="k3">&lt;</span> <span class="n">0</span><span class="k2">)</span></td></tr><tr><td class="number">31</td><td>            b-&gt;dy <span class="k3">=</span> <span class="k3">-</span>b-&gt;dy<span class="k2">;</span></td></tr><tr><td class="number">32</td><td>    <span class="k2">}</span></td></tr><tr><td class="number">33</td><td><span class="k2">}</span></td></tr><tr><td class="number">34</td><td>&#160;</td></tr><tr><td class="number">35</td><td><span class="k1">void</span> goto_ball_state<span class="k2">(</span>ball<span class="k3">*</span> b, <span class="k1">int</span> ns<span class="k2">)</span></td></tr><tr><td class="number">36</td><td><span class="k2">{</span></td></tr><tr><td class="number">37</td><td>    <span class="c">// Set time in the new state to 0</span></td></tr><tr><td class="number">38</td><td>    b-&gt;time <span class="k3">=</span> <span class="n">0</span><span class="k2">;</span></td></tr><tr><td class="number">39</td><td>    <span class="c">// Set new state</span></td></tr><tr><td class="number">40</td><td>    b-&gt;state <span class="k3">=</span> ns<span class="k2">;</span></td></tr><tr><td class="number">41</td><td><span class="k2">}</span></td></tr></tbody></table></div></div><p>Now, 1000 times each second, call upd_ball on your ball and it will bounce around the screen for 3 seconds, then stop for 2, and repeat.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (CGamesPlay)</author>
		<pubDate>Mon, 03 Jul 2006 21:36:18 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Ahh I see, so I could do something like:</p><div class="source-code snippet"><div class="inner"><pre><span class="c">//This is the main loop</span>
<span class="k1">while</span><span class="k2">(</span><span class="k3">!</span><a href="http://www.allegro.cc/manual/key" target="_blank"><span class="a">key</span></a><span class="k2">[</span>KEY_ESC<span class="k2">]</span><span class="k2">)</span>
<span class="k2">{</span>
 <span class="k1">if</span><span class="k2">(</span>timer % <span class="n">230</span> <span class="k3">=</span><span class="k3">=</span> <span class="n">0</span><span class="k2">)</span><span class="c">//.23 Seconds I think according to brknphoenix</span>
 <span class="k2">{</span>
  doaction<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
 <span class="k2">}</span>
<span class="k2">}</span>
</pre></div></div><p>

Possibly?</p><p>EDIT:  Sorry CGamesPlay, I posted after you posted and didn&#39;t see that.  Would my idea here still work?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Paladin)</author>
		<pubDate>Mon, 03 Jul 2006 21:36:51 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Nope, this:</p><div class="source-code snippet"><div class="inner"><pre><span class="c">//This is the main loop</span>
<span class="k1">while</span><span class="k2">(</span><span class="k3">!</span><a href="http://www.allegro.cc/manual/key" target="_blank"><span class="a">key</span></a><span class="k2">[</span>KEY_ESC<span class="k2">]</span><span class="k2">)</span>
<span class="k2">{</span>
 <span class="k1">if</span><span class="k2">(</span>timer % <span class="n">10</span> <span class="k3">=</span><span class="k3">=</span> <span class="n">0</span><span class="k2">)</span>
 <span class="k2">{</span>
  <span class="c">//logic here</span>
 <span class="k2">}</span>
 <span class="c">//drawing here</span>
<span class="k2">}</span>
</pre></div></div><p>

1) You can&#39;t reset the timer, else you&#39;ll never be able to time things up to even one second.  You just have to let it count up for the duration of your program.</p><p>2) 230 milliseconds is too long.  That means your logic is only updating 4 times per second, which is EXTREMELY slow.  Your computer and most others should be able to do 100 times per second easy, so if you use the number 10 there, you will accomplish that <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" /></p><p>If you do it like that, it should run the same speed for everyone.  Note that you shouldn&#39;t draw in there, you should draw after it.  You want to draw as fast as possible <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" />  Only the logic that comes before drawing anything goes in there
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (BrknPhoenix)</author>
		<pubDate>Mon, 03 Jul 2006 21:41:26 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Well, for the main loop, the ideal solution is:
</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">while</span><span class="k2">(</span><span class="k3">!</span><a href="http://www.allegro.cc/manual/key" target="_blank"><span class="a">key</span></a><span class="k2">[</span>KEY_ESC<span class="k2">]</span><span class="k2">)</span>
<span class="k2">{</span>
    <span class="k1">while</span><span class="k2">(</span>timer <span class="k3">&gt;</span> <span class="n">0</span><span class="k2">)</span>
    <span class="k2">{</span>
        <span class="k3">-</span><span class="k3">-</span>timer<span class="k2">;</span>
        upd_ball<span class="k2">(</span>b<span class="k2">)</span><span class="k2">;</span>
    <span class="k2">}</span>
    <span class="c">// Draw everything outside of the timed loop.</span>
    <a href="http://www.allegro.cc/manual/circlefill" target="_blank"><span class="a">circlefill</span></a><span class="k2">(</span><a href="http://www.allegro.cc/manual/screen" target="_blank"><span class="a">screen</span></a>, b-&gt;x, b-&gt;y, <span class="n">32</span>, <span class="k3">-</span><span class="n">1</span><span class="k2">)</span><span class="k2">;</span>
<span class="k2">}</span>
</pre></div></div><p>

[append]</p><p>Now what BrokenPhoenix is saying is also fine, but I prefer my OO approach instead.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (CGamesPlay)</author>
		<pubDate>Mon, 03 Jul 2006 21:41:38 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I don&#39;t think you guys are seeing what I&#39;m trying to accomplish.  This isn&#39;t to update the screen and such, this is to just simply do one action.  I want to have an action occur every so-and-so seconds.  I&#39;m not trying to update the game logic every .230 seconds.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Paladin)</author>
		<pubDate>Mon, 03 Jul 2006 21:47:47 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>That would be what I posted at the end of my second post in this topic.</p><p>If you want the value of 2 seconds from now, store the current value of the timer + 2000.  If you wanted 10 seconds from now, store the current value of the timer + 10,000.  Then do whatever you want to occur or pause whatever you want to pause using that time.</p><div class="source-code snippet"><div class="inner"><pre><span class="c">//wait for 2 seconds</span>
eTime <span class="k3">=</span> timer <span class="k3">+</span> <span class="n">2000</span><span class="k2">;</span>
<span class="k1">while</span> <span class="k2">(</span>timer <span class="k3">&lt;</span><span class="k3">=</span> eTime<span class="k2">)</span><span class="k2">;</span> <span class="c">//it will end the loop once the current time</span>
                       <span class="c">//exceeds the target time of 2 seconds from when this started</span>
</pre></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (BrknPhoenix)</author>
		<pubDate>Mon, 03 Jul 2006 21:50:39 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>You don&#39;t see what we just said. I will only speak for my method, but look:</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
I want the gamae to use a for loop and at the end of the loop, wait 2 seconds(example) and then repeat the for loop.
</p></div></div><p>In my example, inside the &quot;for&quot; loop you are bouncing the ball. And that for loop lasts for 3 seconds. Then the program pauses for 2 seconds, and continues. If you wanted to have something happen instantly, try the same thing, just differently:</p><div class="source-code"><div class="toolbar"></div><div class="inner"><table width="100%"><tbody><tr><td class="number">1</td><td><span class="k1">void</span> upd_ball<span class="k2">(</span>ball<span class="k3">*</span> b<span class="k2">)</span></td></tr><tr><td class="number">2</td><td><span class="k2">{</span></td></tr><tr><td class="number">3</td><td>    <span class="c">// This function adds to the ball's timer.</span></td></tr><tr><td class="number">4</td><td>    <span class="k3">+</span><span class="k3">+</span>b-&gt;time<span class="k2">;</span></td></tr><tr><td class="number">5</td><td>    <span class="c">// If the ball is frozen and 2 seconds has elapsed, start bouncing again.</span></td></tr><tr><td class="number">6</td><td>    <span class="k1">if</span><span class="k2">(</span>b-&gt;state <span class="k3">=</span><span class="k3">=</span> BS_FROZEN <span class="k3">&amp;</span><span class="k3">&amp;</span> b-&gt;time <span class="k3">&gt;</span><span class="k3">=</span> <span class="n">2000</span><span class="k2">)</span></td></tr><tr><td class="number">7</td><td>        goto_ball_state<span class="k2">(</span>b, BS_BOUNCING<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">8</td><td>    <span class="k1">else</span></td></tr><tr><td class="number">9</td><td>    <span class="k2">{</span>   <span class="c">// Otherwise bounce the ball for 300 pixels</span></td></tr><tr><td class="number">10</td><td>        <span class="k1">for</span><span class="k2">(</span><span class="k1">int</span> i <span class="k3">=</span> <span class="n">0</span><span class="k2">;</span> i <span class="k3">&lt;</span> <span class="n">300</span><span class="k2">;</span> i<span class="k3">+</span><span class="k3">+</span><span class="k2">)</span></td></tr><tr><td class="number">11</td><td>        <span class="k2">{</span></td></tr><tr><td class="number">12</td><td>            <span class="c">// Bounce the ball around the screen.</span></td></tr><tr><td class="number">13</td><td>            b-&gt;y <span class="k3">+</span><span class="k3">=</span> b-&gt;dy<span class="k2">;</span></td></tr><tr><td class="number">14</td><td>            b-&gt;x <span class="k3">+</span><span class="k3">=</span> b-&gt;dx<span class="k2">;</span></td></tr><tr><td class="number">15</td><td>            <span class="k1">if</span><span class="k2">(</span>b-&gt;x <span class="k3">&gt;</span> <a href="http://www.allegro.cc/manual/SCREEN_W" target="_blank"><span class="a">SCREEN_W</span></a> <span class="k3">|</span><span class="k3">|</span> b-&gt;x <span class="k3">&lt;</span> <span class="n">0</span><span class="k2">)</span></td></tr><tr><td class="number">16</td><td>                b-&gt;dx <span class="k3">=</span> <span class="k3">-</span>b-&gt;dx<span class="k2">;</span></td></tr><tr><td class="number">17</td><td>            <span class="k1">if</span><span class="k2">(</span>b-&gt;y <span class="k3">&gt;</span> <a href="http://www.allegro.cc/manual/SCREEN_H" target="_blank"><span class="a">SCREEN_H</span></a> <span class="k3">|</span><span class="k3">|</span> b-&gt;y <span class="k3">&lt;</span> <span class="n">0</span><span class="k2">)</span></td></tr><tr><td class="number">18</td><td>                b-&gt;dy <span class="k3">=</span> <span class="k3">-</span>b-&gt;dy<span class="k2">;</span></td></tr><tr><td class="number">19</td><td>        <span class="k2">}</span></td></tr><tr><td class="number">20</td><td>        <span class="c">// Pause again</span></td></tr><tr><td class="number">21</td><td>        goto_ball_state<span class="k2">(</span>b, BS_FROZEN<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">22</td><td>    <span class="k2">}</span></td></tr><tr><td class="number">23</td><td><span class="k2">}</span></td></tr></tbody></table></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (CGamesPlay)</author>
		<pubDate>Mon, 03 Jul 2006 21:51:32 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>So are you saying to put that in the main loop if I want it to occur every 2 seconds?    I just see a problem with that because I thought that it would wait 2 seconds and NOTHING would occur.  The thing is I want everything in the background to continue as normal but just have the action occur every 2 seconds.  Will that while loop do what I described?  I just thought that the if statement wouldn&#39;t do that.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Paladin)</author>
		<pubDate>Mon, 03 Jul 2006 21:53:08 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
So are you saying to put that in the main loop if I want it to occur every 2 seconds? I just see a problem with that because I thought that it would wait 2 seconds and NOTHING would occur. The thing is I want everything in the background to continue as normal but just have the action occur every 2 seconds. Will that while loop do what I described? I just thought that the if statement wouldn&#39;t do that.
</p></div></div><p>

</p><div class="source-code snippet"><div class="inner"><pre><span class="c">//stuff happening all the time</span>
<span class="k1">if</span> <span class="k2">(</span>timer % <span class="n">2000</span> <span class="k3">=</span><span class="k3">=</span> <span class="n">0</span><span class="k2">)</span>
<span class="k2">{</span>
  <span class="c">// stuff that happens every 2 seconds</span>
<span class="k2">}</span>
<span class="c">//stuff happening all the time</span>
</pre></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (BrknPhoenix)</author>
		<pubDate>Mon, 03 Jul 2006 21:55:40 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p><span class="source-code"><span class="k1">if</span><span class="k2">(</span>timer % <span class="n">10</span> <span class="k3">=</span><span class="k3">=</span> <span class="n">0</span><span class="k2">)</span></span><br />won&#39;t work properly because it relies on you being able to catch that exact millisecond. In general, timers are only accurate to 10ms or so (about .01 seconds, about 100 times a second). Allegro&#39;s timers are a bit worse than this due to overhead from all installed timers.</p><p>But, even if they really were accurate, say one time you check, timer is 9 (which means you won&#39;t do anything yet). The OS interrupts your game to run other threads. You get back and timer is now 22 (~13ms later). You just missed two executions, and won&#39;t make them up since timer%10 still doesn&#39;t == 0.</p><p>It&#39;s best to run the timer as fast as you want the game to update, and just do an update whenever the timer is &gt; 0 (while decrementing timer every time you do an update).
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Kitty Cat)</author>
		<pubDate>Mon, 03 Jul 2006 21:55:53 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>If, Brian, you were talking to me, I gave a main loop that calls that function in my post. My main loops works the same way as KittyCat&#39;s.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (CGamesPlay)</author>
		<pubDate>Mon, 03 Jul 2006 22:01:46 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Sorry CGamesPlay, I consistently miss what you&#39;re saying.  If I used your method, would I have to install a timer for that variable and such?  I&#39;m really sorry if I seem stupid, I just don&#39;t know very much about this topic.</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">void</span> function<span class="k2">(</span><span class="k2">)</span>
<span class="k2">{</span>
 timer<span class="k3">+</span><span class="k3">+</span><span class="k2">;</span>
 <span class="k1">if</span><span class="k2">(</span>timer <span class="k3">&gt;</span><span class="k3">=</span> <span class="n">2000</span><span class="k2">)</span>
 <span class="k2">{</span>
  <a href="http://www.allegro.cc/manual/play_sample" target="_blank"><span class="a">play_sample</span></a><span class="k2">(</span>...<span class="k2">)</span><span class="k2">;</span>
 <span class="k2">}</span>
<span class="k2">}</span>
</pre></div></div><p>

Ok, now assuming I check that every millisecond, would that work to fit my needs?  I&#39;m trying to incorporate what you&#39;re all saying into what I make, but it&#39;s difficult because of my lack of experience.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Paladin)</author>
		<pubDate>Mon, 03 Jul 2006 22:03:15 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>No, you would use the same timer variable that BrknPhoenix said to use, except the main loop would look like mine. What I posted is pretty much the standard way of timing. What I would do in your case is this: (since all you need is a single event)</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">int</span> sound_last_played <span class="k3">=</span> <span class="n">0</span><span class="k2">;</span>
<span class="k1">int</span> game_time <span class="k3">=</span> <span class="n">0</span><span class="k2">;</span> <span class="c">// This is the variable updated 1000 times each second by your timer interrupt.</span>
<span class="k1">while</span><span class="k2">(</span><span class="k3">!</span><a href="http://www.allegro.cc/manual/key" target="_blank"><span class="a">key</span></a><span class="k2">[</span>KEY_ESC<span class="k2">]</span><span class="k2">)</span>
<span class="k2">{</span>
    <span class="k1">if</span><span class="k2">(</span>game_time <span class="k3">-</span> sound_last_played <span class="k3">&gt;</span> <span class="n">2000</span><span class="k2">)</span>
    <span class="k2">{</span>
        <a href="http://www.allegro.cc/manual/play_sample" target="_blank"><span class="a">play_sample</span></a><span class="k2">(</span>...<span class="k2">)</span><span class="k2">;</span>
        sound_last_played <span class="k3">=</span> game_time<span class="k2">;</span>
    <span class="k2">}</span>
<span class="k2">}</span>
</pre></div></div><p>

But do keep that state-based programing in mind for when you want to have multiple unrelated objects acting at the same time.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (CGamesPlay)</author>
		<pubDate>Mon, 03 Jul 2006 22:09:34 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Ok that makes sense.  I&#39;m going to have to use the state-based programming though because I have to update a pixel&#39;s location every so and so seconds as well.  I guess I have enough knowledge to get it done and if I have any problems I should be able to figure it out.  Thanks a lot everyone.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Paladin)</author>
		<pubDate>Mon, 03 Jul 2006 22:16:10 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>haha, switching to the other timing method fixed the keyboard problem i was having in the other topic I made :p
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (BrknPhoenix)</author>
		<pubDate>Mon, 03 Jul 2006 22:58:43 +0000</pubDate>
	</item>
</rss>
