<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Question about joystick events</title>
		<link>http://www.allegro.cc/forums/view/617322</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Mon, 19 Mar 2018 14:29:06 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>How do I get the joystick number from the joystick event?</p><p>I can use: joystick.id (ALLEGRO_JOYSTICK *)<br />and get an ALLEGRO_JOYSTICK struct...</p><p>From that I can figure a lot of things about that particular joystick,<br />except that I can&#39;t seem to figure out how to tell if its joystick 0 or 1<br />on a system with 2 joysticks installed.  </p><p>Am I missing something obvious??</p><p>Thanks..
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Michael Weiss)</author>
		<pubDate>Sun, 18 Mar 2018 21:21:21 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I would look at the function <span class="source-code"><a href="http://www.allegro.cc/manual/al_get_joystick"><span class="a">al_get_joystick</span></a><span class="k2">(</span><span class="k2">)</span></span> to get the number.  See also <span class="source-code"><a href="http://www.allegro.cc/manual/al_get_joystick_active"><span class="a">al_get_joystick_active</span></a><span class="k2">(</span><span class="k2">)</span></span> and <span class="source-code"><a href="http://www.allegro.cc/manual/al_get_joystick_name"><span class="a">al_get_joystick_name</span></a><span class="k2">(</span><span class="k2">)</span></span>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Neil Roy)</author>
		<pubDate>Sun, 18 Mar 2018 23:09:40 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Thanks Neil,</p><p>I looked at your answer, but it didn&#39;t help.</p><p>ALLEGRO_JOYSTICK * al_get_joystick(int num)<br />only returns the ALLEGRO_JOYSTICK handle struct, you have to pass it num;<br />I get the same joystick handle struct, from the events it generates.</p><p>OK, so I&#39;ve got the joystick handle struct, what can i do with that?</p><p>bool al_get_joystick_active(ALLEGRO_JOYSTICK *joy)<br />only tells me if a particular joystick is active or not,<br />not very helpful as I can&#39;t imagine that an inactive joystick will be generating events</p><p>const char *al_get_joystick_name(ALLEGRO_JOYSTICK *joy)<br />The text name for both of my joysticks is the same.</p><p>Now I don&#39;t want to be one of those people who say:<br />&quot;This is how it was done in allegro 4, why can&#39;t I do this anymore?&quot;...but...</p><p>This is how it was done in allegro 4:  extern JOYSTICK_INFO joy[n];</p><p>It was very easy to figure out which joystick was which.</p><p>All I want to do is:<br />When I get a joystick event, to be able to tell what joystick it came from.</p><p>Someone must have a multi joystick example, but I have searched and can&#39;t find anything.</p><p>Thanks
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Michael Weiss)</author>
		<pubDate>Mon, 19 Mar 2018 00:29:56 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Untested, but this should do what you want :
</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">int</span> getJoystickNum<span class="k2">(</span><a href="http://www.allegro.cc/manual/ALLEGRO_JOYSTICK"><span class="a">ALLEGRO_JOYSTICK</span></a><span class="k3">*</span> <a href="http://www.allegro.cc/manual/joy"><span class="a">joy</span></a><span class="k2">)</span> <span class="k2">{</span>
   <span class="k1">for</span> <span class="k2">(</span><span class="k1">unsigned</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> <a href="http://www.allegro.cc/manual/al_get_num_joysticks"><span class="a">al_get_num_joysticks</span></a><span class="k2">(</span><span class="k2">)</span> <span class="k2">;</span> <span class="k3">+</span><span class="k3">+</span>i<span class="k2">)</span> <span class="k2">{</span>
      <span class="k1">if</span> <span class="k2">(</span><a href="http://www.allegro.cc/manual/joy"><span class="a">joy</span></a> <span class="k3">=</span><span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_get_joystick"><span class="a">al_get_joystick</span></a><span class="k2">(</span>i<span class="k2">)</span><span class="k2">)</span> <span class="k2">{</span><span class="k1">return</span> i<span class="k2">;</span><span class="k2">}</span>
   <span class="k2">}</span>
   <span class="k1">return</span> <span class="k3">-</span><span class="n">1</span><span class="k2">;</span>
<span class="k2">}</span>
</pre></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Mon, 19 Mar 2018 02:07:02 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>That works perfectly!! Thank you so much for your help!!
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Michael Weiss)</author>
		<pubDate>Mon, 19 Mar 2018 02:14:43 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I don&#39;t disagree with Edgar but take a look at the docs for <span class="source-code"><a href="http://www.allegro.cc/manual/al_reconfigure_joysticks"><span class="a">al_reconfigure_joysticks</span></a></span> - if you want to support plugging/unplugging sticks you may need to do a bit of extra work, in case Allegro renumbers them. I don&#39;t have &gt;1 joystick to test (and I suspect it&#39;s platform dependent) so I don&#39;t know if this will be a problem in practice. <br />I would enumerate the sticks once and put the pointers in my own array, rather than going via <span class="source-code"><a href="http://www.allegro.cc/manual/al_get_num_joysticks"><span class="a">al_get_num_joysticks</span></a></span> and <span class="source-code"><a href="http://www.allegro.cc/manual/al_get_joystick"><span class="a">al_get_joystick</span></a></span> every time. Then, handle the ALLEGRO_EVENT_JOYSTICK_CONFIGURATION event as necessary.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Peter Hull)</author>
		<pubDate>Mon, 19 Mar 2018 14:29:06 +0000</pubDate>
	</item>
</rss>
