<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Joysticks - How can I get more than one working</title>
		<link>http://www.allegro.cc/forums/view/616346</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Fri, 17 Jun 2016 07:02:58 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hey,</p><p>I&#39;m making a game that has 2 or more players using gamepads.<br />I can&#39;t find an event 
</p><div class="source-code snippet"><div class="inner"><pre><a href="http://www.allegro.cc/manual/ALLEGRO_EVENT"><span class="a">ALLEGRO_EVENT</span></a> ev<span class="k2">;</span> 
<span class="k1">if</span> <span class="k2">(</span>ev.type <span class="k3">=</span><span class="k3">=</span> ALLEGRO_EVENT_JOYSTICK_BUTTON_DOWN<span class="k2">)</span>
<span class="k2">{</span><span class="k2">}</span>
</pre></div></div><p>
that allows me to determine<br />what gamepad the button presses are occurring from.<br /> <br />If I use states
</p><div class="source-code snippet"><div class="inner"><pre><span class="c">//im using all the init stuff correctly, </span>
<span class="c">//this is just a snippit to explain what im up to</span>
<a href="http://www.allegro.cc/manual/ALLEGRO_JOYSTICK_STATE"><span class="a">ALLEGRO_JOYSTICK_STATE</span></a> joyState1<span class="k2">;</span>
<a href="http://www.allegro.cc/manual/al_get_joystick_state"><span class="a">al_get_joystick_state</span></a><span class="k2">(</span>joy1, <span class="k3">&amp;</span>joyState1<span class="k2">)</span><span class="k2">;</span>
cout <span class="k3">&lt;</span><span class="k3">&lt;</span> joyState1.button <span class="k3">&lt;</span><span class="k3">&lt;</span> <span class="s">"\n"</span><span class="k2">;</span>
</pre></div></div><p>
I get the same output from all the main buttons (ie. 00E9A5D8) <br />but for some reason it can read select and the triggers.</p><p>Hope someone can help - Thanks Dev
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (devo_au)</author>
		<pubDate>Thu, 16 Jun 2016 17:59:10 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Have you iterated over all joysticks Allegro returns to you? Maybe it&#39;s polling some data from a weird device. Or maybe it&#39;s a driver issue of some sorts.</p><p>As for using ALLEGRO_EVENTs, this page has some more information for you:<br /><a href="https://www.allegro.cc/manual/5/allegro_event#TOC">Manual</a><br />Basically, once you detect a ALLEGRO_EVENT_JOYSTICK_AXIS, ALLEGRO_EVENT_JOYSTICK_BUTTON_DOWN or ALLEGRO_EVENT_JOYSTICK_BUTTON_UP event, you can check joystick.id to get the ID of the joystick. I&#39;m not sure if ALLEGRO_EVENT already has a joystick field right away or if you need to cast it to another type, but I&#39;d expect that it just uses a union internally and that it already has the joystick field, so you can just check that.</p><p>Or in other words: ev.joystick.id
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (RPG Hacker)</author>
		<pubDate>Thu, 16 Jun 2016 19:15:39 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Yes, RPG Hacker is correct. Use ev.joystick.id to get the joystick id. And with joystick button events, use ev.joystick.button to get the button pressed.</p><p>As for <span class="source-code"><a href="http://www.allegro.cc/manual/al_get_joystick_state"><span class="a">al_get_joystick_state</span></a></span>, you&#39;re not using it correctly. joystick_state.button is an array, not a bool value indicating whether a button was pressed. You need to access the specific button that you are asking for first : </p><div class="source-code snippet"><div class="inner"><pre><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> <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>
   <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="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>
   <a href="http://www.allegro.cc/manual/ALLEGRO_JOYSTICK_STATE"><span class="a">ALLEGRO_JOYSTICK_STATE</span></a> joy_state<span class="k2">;</span>
   <a href="http://www.allegro.cc/manual/al_get_joystick_state"><span class="a">al_get_joystick_state</span></a><span class="k2">(</span><a href="http://www.allegro.cc/manual/joy"><span class="a">joy</span></a> , <span class="k3">&amp;</span>joy_state<span class="k2">)</span><span class="k2">;</span>
   <span class="k1">for</span> <span class="k2">(</span><span class="k1">int</span> j <span class="k3">=</span> <span class="n">0</span> <span class="k2">;</span> j <span class="k3">&lt;</span> <a href="http://www.allegro.cc/manual/al_get_joystick_num_buttons"><span class="a">al_get_joystick_num_buttons</span></a> <span class="k2">;</span> <span class="k3">+</span><span class="k3">+</span>j<span class="k2">)</span> <span class="k2">{</span>
      <span class="k1">if</span> <span class="k2">(</span>joy_state.button<span class="k2">[</span>j<span class="k2">]</span><span class="k2">)</span> <span class="k2">{</span>
         <a href="http://www.delorie.com/djgpp/doc/libc/libc_624.html" target="_blank">printf</a><span class="k2">(</span><span class="s">"Joystick number %d has button %d pressed.\n"</span> , i , j<span class="k2">)</span><span class="k2">;</span>
      <span class="k2">}</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>Thu, 16 Jun 2016 21:17:17 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Awesome thank you for your replies..</p><p>RPG - I didn&#39;t know about ev.joystick.id. Iterating them. Hmmm...<br />Edgar - Ah! that hex number is an address of a array.</p><p>Thanks for that loop Edgar. So thats what RPG meant.<br />Plugged it in - problem solved. Just have to hook it<br />up to my players. </p><p>Cheers guys. You have helped me heaps.. Dev
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (devo_au)</author>
		<pubDate>Fri, 17 Jun 2016 07:02:58 +0000</pubDate>
	</item>
</rss>
