Jump to content


Photo

Gamepad Extended - Version 1.1


  • Please log in to reply
51 replies to this topic

#1 Tahnok

Tahnok

    Friendly Madman

  • GMC Member
  • 1830 posts
  • Version:Unknown

Posted 01 June 2008 - 12:18 PM

I finally got tired enough of some of the limitations of GM's built-in gamepad support, so I created this extension. It has the following features:
  • Able to check if a button was pressed or released
  • Analog inputs and POV controls act as buttons, with adjustable dead zone, so all inputs can be handled with the same code
  • Checks whether a joystick exists before attempting to check it's state, since checking non-existent gamepads will slow games down
  • Supports two joysticks
  • Can automatically disable buttons that are being pressed on setup, so they don't interfere with other checks
  • Can suspend the game until a gamepad input is pressed, or until all are released
  • Can automatically find a pressed button on the gamepad
  • Replaces a few other basic functions, but checks whether the gamepad exists first
Download Gamepad Extended

Read the extension's help file for details on how to use it. Also be sure to check out the example, as it demonstrates many of the functions.

Enjoy,
Tahnok

Edited by Tahnok, 02 June 2008 - 04:17 AM.

  • 3

#2 Reshure

Reshure

    Reshure

  • New Member
  • 320 posts

Posted 01 June 2008 - 04:51 PM

Awesome! This is exactly what I need.

Thank you very much!
  • 0

#3 Tahnok

Tahnok

    Friendly Madman

  • GMC Member
  • 1830 posts
  • Version:Unknown

Posted 02 June 2008 - 04:16 AM

OK, I played around with this extension a little more today and found a couple bugs. Apparently, it's possible for the gamepad to change it's state mid-step, which was sometimes causing issues with the press and release functions. I've updated it to now poll all the inputs at the start of the step, so things are a little more predictable.

I also fixed a dead zone issue with the second controller and changed some things around so that updates are now done automatically (though, now you have to manually call the initialization script). See the help file for a full list of fixes/updates. The main link has been updated.
  • 0

#4 IsmAvatar

IsmAvatar

    Good Samaritan

  • GMC Member
  • 2411 posts
  • Version:GM8

Posted 02 June 2008 - 05:08 AM

For a second, I almost thought someone had finally extended upon my GameMaker Notepad (GamePad), but no. lol.

Looks promising, although I wouldn't have much of a use for it.
  • 1

#5 Reshure

Reshure

    Reshure

  • New Member
  • 320 posts

Posted 02 June 2008 - 01:54 PM

I wanted to say thanks again!

It works perfectly :blink:
  • 0

#6 agustusx

agustusx

    GMC Member

  • New Member
  • 27 posts
  • Version:Unknown

Posted 04 June 2008 - 12:41 AM

Thanks a lot this helped me out a great deal :P I can finally used my crusty old sidewiders POV as directional control, same for my 360 controller.

Again thanks for sharing.
  • 0

#7 8-BitTonberry

8-BitTonberry

    GMC Member

  • GMC Member
  • 657 posts
  • Version:GM:Studio

Posted 13 June 2008 - 02:48 PM

Hey, I'm wondering if there is anyway to return the analogs direction in degrees.

Is this possible to do with this extension or at all?

Ex: Aiming a turret in the direction you're holding.
  • 0

#8 Chaos In a Can

Chaos In a Can

    GMC Member

  • New Member
  • 70 posts

Posted 13 June 2008 - 03:40 PM

Hey, I'm wondering if there is anyway to return the analogs direction in degrees.

Is this possible to do with this extension or at all?

Ex: Aiming a turret in the direction you're holding.



Use point_direction() on the x,y position of the joystick.
//Try this:
direction = point_direction(0, 0, joystick_xpos(1), joystick_ypos(1));

//...or if that doesn't work, try this:
direction = point_direction(0, 0, joystick_xpos(1), -joystick_ypos(1));

  • 0

#9 8-BitTonberry

8-BitTonberry

    GMC Member

  • GMC Member
  • 657 posts
  • Version:GM:Studio

Posted 13 June 2008 - 04:10 PM

Sweet! That worked perfectly!

Is there any way to check how far the joystick is actually being pressed?
I know it probably says that in the help, but I can't find it.

And one final thing...

Since each joystick is considered 4 buttons(13, 14, 15, 16 in this case), is there any way to check if it is being pressed at all without checking all of those?

Thanks again!
  • 0

#10 Tahnok

Tahnok

    Friendly Madman

  • GMC Member
  • 1830 posts
  • Version:Unknown

Posted 13 June 2008 - 09:53 PM

Sweet! That worked perfectly!

Is there any way to check how far the joystick is actually being pressed?
I know it probably says that in the help, but I can't find it.

And one final thing...

Since each joystick is considered 4 buttons(13, 14, 15, 16 in this case), is there any way to check if it is being pressed at all without checking all of those?

Thanks again!

GM can natively check how far you're pressing a specific direction. Look in the help manual under GML > User Interaction > The Joystick. You will find functions such as joystick_xpos(id) and joystick_ypos(id), which return between -1 and 1 (0 being centered, most of the time).

No, you have to check each input individually. I suppose I could add a function eventually to check whether all analog stick are released or if any are pressed, but that would kind of defeat the purpose of this extension (making all gamepad code universal, no matter what types of controls a gamepad may have).
  • 0

#11 Warmachine

Warmachine

    GMC Member

  • GMC Member
  • 97 posts

Posted 15 June 2008 - 10:09 PM

Would this actually work with the Xbox360 Pad? I know that some other example shows rumble support etc.
  • 0

#12 Tahnok

Tahnok

    Friendly Madman

  • GMC Member
  • 1830 posts
  • Version:Unknown

Posted 16 June 2008 - 06:34 AM

Would this actually work with the Xbox360 Pad? I know that some other example shows rumble support etc.

If you install drivers for the Xbox 360 gamepad to turn it into a normal windows direct input pad then it should. As far as I know though, it wont work out of the box without the drivers (which is why Sinaz created his extension, which I believe supports it regardless of drivers).

This doesn't have any sort of rumble support, especially for the 360 gamepad. That would require a dll, and this extension is just a wrapper for GM's internal functions to make them easier to use. Sindarin has made the only working force feedback dll for direct input pads and I believe Sinaz's dll supports rumble for the 360 gamepad.

BTW, I don't own a 360 controller to test with.
  • 0

#13 mory

mory

    GMC Member

  • New Member
  • 26 posts

Posted 19 June 2008 - 03:05 PM

well done. tnx

I need somthing Important. Vibration

could you ?
  • 0

#14 Tahnok

Tahnok

    Friendly Madman

  • GMC Member
  • 1830 posts
  • Version:Unknown

Posted 20 June 2008 - 05:22 AM

well done. tnx

I need somthing Important. Vibration

could you ?

No, I can't, but that doesn't matter, someone already has:

http://gmc.yoyogames...howtopic=379111

I was going to put his dll into an extension, but ran into some issues and haven't had a chance to look at it again. It's a fairly easy dll to use though.
  • 0

#15 mory

mory

    GMC Member

  • New Member
  • 26 posts

Posted 29 June 2008 - 02:03 PM

well done. tnx

I need somthing Important. Vibration

could you ?

No, I can't, but that doesn't matter, someone already has:

http://gmc.yoyogames...howtopic=379111

I was going to put his dll into an extension, but ran into some issues and haven't had a chance to look at it again. It's a fairly easy dll to use though.


  • 0

#16 bradshaw

bradshaw

    GMC Member

  • GMC Member
  • 44 posts

Posted 07 July 2008 - 12:43 AM

well done. tnx

I need somthing Important. Vibration

could you ?

No, I can't, but that doesn't matter, someone already has:

http://gmc.yoyogames...howtopic=379111

I was going to put his dll into an extension, but ran into some issues and haven't had a chance to look at it again. It's a fairly easy dll to use though.



Thanks. Perfect.
  • 0

#17 justin123

justin123

    GMC Member

  • New Member
  • 124 posts

Posted 24 July 2008 - 04:29 PM

gamepad_check_button_pressed() doesn't seem to work.
  • 0

#18 Tahnok

Tahnok

    Friendly Madman

  • GMC Member
  • 1830 posts
  • Version:Unknown

Posted 24 July 2008 - 09:26 PM

gamepad_check_button_pressed() doesn't seem to work.

Read the help file. There are two reasons listed in there that could be causing the problem. gamepad_init() has to be called before any other function. Also, make sure any objects calling the press and release checks have a depth between -10,000,000 and 10,000,000.
  • 0

#19 justin123

justin123

    GMC Member

  • New Member
  • 124 posts

Posted 24 July 2008 - 10:45 PM

gamepad_check_button_pressed() doesn't seem to work.

Read the help file. There are two reasons listed in there that could be causing the problem. gamepad_init() has to be called before any other function. Also, make sure any objects calling the press and release checks have a depth between -10,000,000 and 10,000,000.


I still can't get it to work, but i'll give you that part of the code I used:

The create event in objSetup - depth=0
//Declare Variablesgamepad_init()global.button_a_pressed=0;global.button_b_pressed=0;global.button_x_pressed=0;global.button_y_pressed=0;global.button_action_pressed=0;

Now the step event for the same object
global.button_a_pressed=gamepad_check_button_pressed(1,2);global.button_b_pressed=gamepad_check_button_pressed(1,3);global.button_x_pressed=gamepad_check_button_pressed(1,4);global.button_y_pressed=gamepad_check_button_pressed(1,1);global.button_action_pressed=gamepad_check_button_pressed(1,9);

This is what's in the object using those variables. Its depth is also equal to zero.
key_action_pressed  =   global.button_b_pressed;//I used the same variables for gamepad and keyboard.

Note that the keyboard and gamepads are not used at the same time. global.input_config="gamepad" or ="keyboard".
All of the button_pressed functions are always equal to zero for some reason.

Edited by justin123, 24 July 2008 - 10:49 PM.

  • 0

#20 Tahnok

Tahnok

    Friendly Madman

  • GMC Member
  • 1830 posts
  • Version:Unknown

Posted 24 July 2008 - 11:17 PM

I just tried it and it seems to be working just fine. Are you sure you're not just missing the incredibly short press of the button? Try putting this line after that last line of code you gave me:

if(key_action_pressed = true) { show_message("button pressed"); }

If that shows a message then the code is working just fine.

Are you sure you're not mistaking gamepad_check_button_pressed() for gamepad_check_button()? Just like GM's mouse functions, the former will only return true only when the button is pressed down the first time (for a single frame). The latter will return true the whole time the button is held.
  • 0

#21 justin123

justin123

    GMC Member

  • New Member
  • 124 posts

Posted 25 July 2008 - 12:12 AM

I just tried it and it seems to be working just fine. Are you sure you're not just missing the incredibly short press of the button? Try putting this line after that last line of code you gave me:

if(key_action_pressed = true) { show_message("button pressed"); }

If that shows a message then the code is working just fine.

Are you sure you're not mistaking gamepad_check_button_pressed() for gamepad_check_button()? Just like GM's mouse functions, the former will only return true only when the button is pressed down the first time (for a single frame). The latter will return true the whole time the button is held.


I tried this :
if(gamepad_check_button_pressed(1,3)== true) { show_message("button pressed"); }

It didn't working my game, but it worked when i tested it in a new game file.
  • 0

#22 justin123

justin123

    GMC Member

  • New Member
  • 124 posts

Posted 25 July 2008 - 12:22 AM

Problem Solved!!!!!!!!!!

gamepad_check_button_pressed() don't work in begin step. B)
  • 0

#23 Tahnok

Tahnok

    Friendly Madman

  • GMC Member
  • 1830 posts
  • Version:Unknown

Posted 25 July 2008 - 12:46 AM

Problem Solved!!!!!!!!!!

gamepad_check_button_pressed() don't work in begin step. B)

That's odd. I thought I tried that kind of stuff. I'll test it a bit later and see if I can figure it out.
  • 0

#24 songs

songs

    GMC Member

  • New Member
  • 54 posts

Posted 12 August 2008 - 02:33 PM

i cant download the extension its not there ?
  • 0

#25 Tahnok

Tahnok

    Friendly Madman

  • GMC Member
  • 1830 posts
  • Version:Unknown

Posted 12 August 2008 - 07:50 PM

i cant download the extension its not there ?

Try the download again a little later. It's actually one of the few that's being hosted by 64D, not my website that has gone down recently due to money issues. So if it's down just wait for 64D to come back online (it appears to be fine right now).
  • 0

#26 duven60

duven60

    GMC Member

  • New Member
  • 316 posts

Posted 10 September 2008 - 10:09 PM

I just wanted o know if this exstention would help with the Xbox 360 trigger problem with GM or not..
I red the help file and couldn't figure it out..
  • 0

#27 slayer 64

slayer 64

    Slayer of gingers

  • GMC Member
  • 3891 posts
  • Version:GM:Studio

Posted 12 September 2008 - 12:14 AM

nice extension.

i would use it if it could vibrate the game controller.
  • 0

#28 mrsmes

mrsmes

    GMC Member

  • GMC Member
  • 1506 posts
  • Version:GM:Studio

Posted 12 September 2008 - 08:17 AM

that would be rather handy, so long as that function is implemented we will be seeing many new emulators, and even with a rumble pack, to vibrate the controller, and use it as if you r playing the game on the console just with a computer access skin on startup, and accessing it, and a computer cover up over the circuit boards and slightly 1% slower on bootup but even the consoles themselves get like that at times. So it would really give it a lagging console feel.
so long as you edit the way the machine starts up, and it, has those emulators all in their to play practically any kind of game, and yeah what ever now enjoy, it's as close to having as many consoles in one as you can possibly ever get.
few questions though how, does the xbox controller, or xbox 360, controller get attached to the computer, and what about the GII-MOTE with the WII like look, and all, connect with a blue-tooth phone like device and well I heard you can use that kind of controller on your computer to browse through your files and all that, and your desktop, I heard about it on YouTube, although if you wanted to it would require some hacking, into your own computer.

Edited by mrsmes, 12 September 2008 - 08:23 AM.

  • 0

#29 Jakyl11

Jakyl11

    GMC Member

  • GMC Member
  • 3194 posts
  • Version:GM:Studio

Posted 24 September 2008 - 04:35 AM

ok I got it to download fine and the gmk opens fine but the extension will not install says an error has occured...
  • 0

#30 Harvest Moon

Harvest Moon

    GMC Member

  • New Member
  • 158 posts

Posted 14 October 2008 - 07:54 PM

Something is wrong with the gamepad_get_dead_zone(id) code. When I try to write: dead_zone = gamepad_get_dead_zone(1), then I get this error message:

___________________________________________
FATAL ERROR in
action number 1
of  Step Event
for object mouse_c:

COMPILATION ERROR in code action
Error in code at line 8:
	   dead_zone = gamepad_get_dead_zone(1);

at position 38: Wrong number of arguments to function or script.

I think it's because in Game Maker it says (in the help box on the bottom of the code window) just: gamepad_get_dead_zone(). It doesn't say that it needs an argument. If I try to just type (), Game Maker says:

___________________________________________
ERROR in
action number 1
of  Step Event
for object mouse_c:

In extension function gamepad_get_dead_zone:
In extension function gamepad_exists:
Error in code at line 2:
   return gamepadExists[argument0 - 1];

at position 23: Negative array index

because I haven't written the gamepad id. Can you solve this, please?
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users