3D Game Builder SDK

SDK Functions

gamePadAttached( int n )

Description

Check if a game pad / controller is attached and ready to use.

You need to call gamePadRead( void ) function before you call this function.

Specification

int gamePadAttached( int n )

int n

= the controller number (1 or 2)

return value

= 1 (success) or 0 (failed)

Notes

Use this function to validate that a game pad / controller is attached and ready to use for your game.

You need to call the gamePadRead( void ) function before you call this gamePadAttached( int n ) function. This is because gamePadRead( void ) needs to update the current state for each attached game pad / controller.

If you do not have a game pad / controller attached before the 3D Game Builder starts and then you plug it in, you will need to restart 3D Game Builder to detect the new controller.

You can have up to 2 connected game pad / controllers plugged in at any time. You can refer to each controller independently by passing the controller number (1 or 2) to the game pad function. For example, gamePadAttached(1) and gamePadAttached(2) will tell you the status of each controller.

For Example

#include "3dgamebuilder.h"

// exported game function
DLL_EXPORT int gameLoop(void)
{
	while(1)
	{
		// read the controller input
		gamePadRead();
					
		// display the status of game pad 1
		if (gamePadAttached(1) == 1)
			gameMessage( "Controller 1 is attached" );
		else
			gameMessage( "Controller 1 is NOT attached" );

		// display the status of game pad 2
		if (gamePadAttached(2) == 1)
			gameMessage( "Controller 2 is attached" );
		else
			gameMessage( "Controller 2 is NOT attached" );

		// draw a frame
		gameStartRender();
		// (nothing to draw)
		gameEndRender();
	}

	return 0;
}

See Also

  gamePadRead( void )
  gamePadAttached( int n )
  gamePadButtonDown( int n, int button )
  gamePadButtonPressed( int n, int button )

Go Back

SDK Functions