Skip to main content

Set the directional-pad state (:set_dpad)

This method is available in versions after 20260805

Declaration

success, err = pad:set_dpad(x, y)

Parameters

  • x Integer. Must be -1, 0, or 1; 1 means right and -1 means left
  • y Integer. Must be -1, 0, or 1; 1 means up and -1 means down

Returns

  • success Boolean. True if the directional-pad state is set; false if the device is disconnected or busy, or if input delivery fails
  • err String. Error message when the operation fails

Description

  • Nonzero x and y values select a diagonal direction
  • 0, 0 releases the directional pad
  • Invalid argument types and out-of-range values raise Lua argument errors

Example

local pad = assert(gamepad.connect())

assert(pad:set_dpad(1, 0)) -- right
assert(pad:set_dpad(-1, 1)) -- up-left
assert(pad:set_dpad(0, 0)) -- release
assert(pad:disconnect())