beetlebug▾
/

ztk::game action

Names an action and the keys and the zones of the screen that press it.

ztk::game action
ztk::game action NAME
ztk::game action NAME ?-keys KEYS? ?-touch ZONES? ?-pad BUTTONS?

Description

With options, makes the action NAME, or puts a new one in its place. NAME has 1 to 64 bytes. -keys is a list of key names as bind names them, such as space, Up, and a. A letter key matches with and without Shift. -touch is a list of zones: tap (the whole view), left-half, right-half, left-third, middle-third, right-third, a box {X0 Y0 X1 Y1} in logical pixels of the view, or swipe-up, swipe-down, swipe-left, or swipe-right. A swipe is a move of 24 logical pixels from the start of a press.

Each key and each pointer or finger in a zone holds the action. The first holder gives a press and the last one a release, so a key and a finger give one press, and a key that repeats gives no new press. -pad names the buttons of a controller. Controllers come in stage 3, so the names are kept with no effect now.

With NAME alone, gives the options of the action. With no argument, gives the names of the actions.

Returns

An empty string, the options as a dict, or a list of names.

Examples

% ztk::game action jump -keys {space Up} -touch tap
> ztk::game action jump
-keys {space Up} -touch tap -pad {}

% ztk::game action fire -keys x
> ztk::game action left -touch {left-third {0 0 40 40}}
> ztk::game action
jump fire left

Errors

% ztk::game action jump -keys Nokey
bad key "Nokey"
-errorcode ZTK GAME KEY Nokey

% ztk::game action jump -touch top
bad zone "top": must be tap, left-half, right-half, left-third, middle-third, right-third, swipe-up, swipe-down, swipe-left, swipe-right, or a box {x0 y0 x1 y1}
-errorcode ZTK GAME ZONE top

% ztk::game action nosuch
no action "nosuch"
-errorcode ZTK GAME ACTION nosuch

Facts

Capability
None.
Tcl release
Tcl 9.1 and 8.6.
Since
ztk 1.0.0-beta.7

See also