learn


Simple Input
Complex Input

Simple Input
The first type of input available in TNT Basic is simple input.  These commands can be used to test if certain buttons on the keyboard are pressed.  The first group of commands are the Direction Controls...

Up    ' Test the up arrow on the keyboard
Down  ' Test the down arrow on the keyboard
Left  ' Test the left arrow on the keyboard
Right ' Test the right arrow on the keyboard
Space ' Test the space bar on the keyboard

These commands return true or false depending on whether or not their button is pressed.

There is also a command for testing any button on the keyboard.  Any of these keys can be tested using the Pressed function.

In order to test a button one of these key codes needs to be passed to the function.

Pressed 122

This command tests if the F1 button has been pressed.

Note: Do not use the escape button for input because that is already used by TNT Basic.

Complex Input
This type of input is more complex to set up in TNT Basic but is much more powerful.  Whereas simple input can only work with the keyboard and mouse, this works with all kinds of input device (e.g. joysticks, game pads etc) and automatically provides an interface for the user to configure controls for the game.

To set up complex input you first need to create an Input Sprocket Setup ('INPT') resource.  The controls for what your game needs can be set up inside this.

Loading Input
Before any input testing can be performed the input resource you created needs to be loaded into memory, this can be done using Load Input.

Load Input 128

This loads input resource 128 into memory ready to be tested.

Configuring Input
Complex input automatically provides an interface for the user to configure the controls for the game.  This is provided in all TNT Basic games that use complex input.  When playing a TNT Basic game, if you press escape it will pause and display a menu.  There is a menu option which will allow the user to configure their controls.

It is also possible to display the interface yourself.  If you call the command Edit Input...

Edit Input

... while an input resource is loaded then it will display the interface for configuring controls.

Note: It is usually not good practice to display this interface every time the game is run.  Instead, let the user select an option to configure controls and then call the Edit Input command.

Activating and Deactivating Input
After an input resource has been loaded it can then be activated, only when input is active can it be tested. It can be activated using the command Activate Input.

Activate Input

This command activates the currently load input resource so it is ready to be tested.  When input is active the mouse will not move and simple input will not work, complex and simple input can never be used at the same time.  Fortunately, you only ever need to use one at once and to disable complex input and enable simple input again TNT Basic provides the command Deactivate Input.

Deactivate Input

This will return the input to normal.

Testing Input
Once an input resource is loaded and activated it can be tested using the command Poll Input.

Poll Input 0

This tests the first input device in your input resource and returns the value for it.  This value can vary depending on what kind of device it was...

For a button it returns:
0 = Not Pressed
1 = Pressed

For a dpad it returns:
0 = Idle
1 = Left
2 = Up-Left
3 = Up
4 = Up-Right
5 = Right
6 = Down-Right
7 = Down
8 = Down-Left

For an x axis it returns in the range:
-100 = Maximum Left
0 = Middle
100 = Maximum Right

For a y axis it returns in the range:
-100 = Maximum Up
0 = Middle
100 = Maximum Down

It is then up to your program to decide how to change the game depending on these values.


Table of contents