BindKey
From Liberty Unleashed Wiki
Revision as of 20:43, 3 March 2013 by IdkanYavuk (Talk | contribs)
This function binds a key to a handler function, which will be called when the player presses the key.
Syntax
bool BindKey( int key, int state, closure func, [ args... ] )
bool BindKey( int key, int state, string func, [ args... ] )
Arguments
- key - This is the key to be bound. For keys 'A'-'Z' and '0'-'9' this value will be the ascii code of the character. For special keys, check a list here
- state - The bind type, either BINDTYPE_DOWN (triggered when the key is pressed down) or BINDTYPE_UP (triggered when the key is released)
- func - Either a pointer to the handler function or the name of the function as a string
- args - Any additional arguments you wish to pass to the handler function
Example
This example will print "Hallo there! 123" to the chatbox when the player presses the H key down.
function onScriptLoad() { BindKey( 'H', BINDTYPE_DOWN, "HalloThere", 123 ); return 1; } function HalloThere( somenumber ) { Message( "Hallo there! " + somenumber ); }
Notes
The function Message and call onScriptLoad were used in in this example. More info about them in the corresponding pages.