Skip to main content

Controller

Description:

  An interface for handling game controller inputs.

Controller.AxisName

Type: Enumeration.

Description:

  Enumeration for defining the controller axis names.

Signature:

enum AxisName
"leftx"
"lefty"
"rightx"
"righty"
"lefttrigger"
"righttrigger"
end

Controller.ButtonName

Type: Enumeration.

Description:

  Enumeration for defining the controller button names.

Signature:

enum ButtonName
"a"
"b"
"back"
"dpdown"
"dpleft"
"dpright"
"dpup"
"leftshoulder"
"leftstick"
"rightshoulder"
"rightstick"
"start"
"x"
"y"
end

isButtonDown

Type: Function.

Description:

  Check whether a button is pressed down in current frame.

Signature:

isButtonDown: function(self: Controller, controllerId: integer, name: ButtonName): boolean

Parameters:

ParameterTypeDescription
controllerIdintegerThe controller id, incrementing from 0 when multiple controllers connected.
nameButtonNameThe name of the button to check.

Returns:

Return TypeDescription
booleanWhether the button is pressed down.

isButtonUp

Type: Function.

Description:

  Check whether a button is released in current frame.

Signature:

isButtonUp: function(self: Controller, controllerId: integer, name: ButtonName): boolean

Parameters:

ParameterTypeDescription
controllerIdintegerThe controller id, incrementing from 0 when multiple controllers connected.
nameButtonNameThe name of the button to check.

Returns:

Return TypeDescription
booleanWhether the button is released.

isButtonPressed

Type: Function.

Description:

  Check whether a button is in pressed state.

Signature:

isButtonPressed: function(self: Controller, controllerId: integer, name: ButtonName): boolean

Parameters:

ParameterTypeDescription
controllerIdintegerThe controller id, incrementing from 0 when multiple controllers connected.
nameButtonNameThe name of the button to check.

Returns:

Return TypeDescription
booleanWhether the button is in pressed state.

getAxis

Type: Function.

Description:

  Get the axis value from a given controller.

Signature:

getAxis: function(self: Controller, controllerId: integer, name: AxisName): number

Parameters:

ParameterTypeDescription
controllerIdintegerThe controller id, incrementing from 0 when multiple controllers connected.
nameAxisNameThe name of the controller axis to check.

Returns:

Return TypeDescription
numberThe axis value ranging from -1.0 to 1.0.