Engine:CCMD bind: Difference between revisions

From AddOn Studio
Jump to navigation Jump to search
No edit summary
No edit summary
 
(10 intermediate revisions by the same user not shown)
Line 8: Line 8:


== Associations ==
== Associations ==
*Key bindings are global, and not a part of any context.
* Key bindings are global, and not a part of any context.


== Details ==
== Details ==
A 'bind' acts like a custom command for a key. It runs the assigned text as a script, which can contain a single-word command, statement, or script.
A 'bind' acts like a custom command for a key. It runs the assigned text as a script, which can contain a single-word command, statement, or script.


Aliases do not have any parameters and will run the command, statement, or script verbatim. If for example, an alias named 'bob' is set to 'echo', it will always run exactly 'echo' which will print nothing, even if you run 'bob "some text". Here the second parameter was ignored.
By default, binds do not work while input focus is in console or in text mode.


Thus, aliases act like simple static macros. But when run they can do anything a script in the same context run by any other means could do. And because aliases are treated like commands, they can have direct key bindings.
Binds have a special relationship with commands and aliases, where specially named commands will get run during special key or device states. For example, if an alias is named '+bob' and is bound to a key, it will only get called when that key is pressed down, and if named '-bob' will get called when the key goes up.


== Examples ==
== Examples ==
=== Default values ===
=== Default values ===
* Check alias 'bob' for script value. No alias exists named 'bob'.
* Check bind 'Z' for script value. No bind exists for key 'Z'.
<kua>
<kua>
> alias bob
> bind Z
Unknown: bob
Unknown: Z
</kua>
* Call 'bob'. No command, variable or alias named 'bob' exist.
<kua>
> bob
Unknown: bob
</kua>
</kua>
* Create an alias 'bob' and set to 'echo fred'.  
* Create a bind for the 'Z' key.
<kua>
<kua>
> alias bob "echo fred"
> bind Z "echo fred"
</kua>
</kua>
* Same as the second example, but now alias 'bob' exists. The 'echo' command in the 'bob' alias script runs, and prints 'fred'.
* Close console and press 'Z' key. Prints 'fred'.
<kua>
<kua>
> bob
fred
fred
</kua>
</kua>
* Same as the first example, but now alias 'bob' exists and shows the value of the alias 'bob'
* Same as the first example, but now bind 'Z' exists and shows the value.
<kua>
<kua>
> alias bob
> alias bob
Line 44: Line 38:
</kua>
</kua>


=== To a variable ===
=== Key states ===
* 'bob' called without a value. No command, variable or alias named 'bob' exist.
* '+zoom' called without a value. No command, variable or alias named '+zoom' exist.
<kua>
> bob
Unknown: bob
</kua>
* Create an alias 'bob' and set to 'fred'.
<kua>
> alias bob fred
</kua>
* Same as the first example, but now alias 'bob' exists. The 'fred' command in the 'bob' alias script runs, and 'fred' doesn't exist.
<kua>
<kua>
> bob
> +zoom
Unknown: fred
Unknown: +zoom
</kua>
</kua>
* Create variable 'fred'.
* Create an alias for '+zoom' and '-zoom'.  
<kua>
<kua>
> var fred james
> alias +zoom "set fov 45; print 'zoom is 45'"
> alias -zoom "set fov 90; print 'zoom is 90'"
</kua>
</kua>
* Run 'bob'
* Create a binding for the 'Z' key.
<kua>
<kua>
> bob
> bind Z +zoom
'fred' is 'james'
</kua>
</kua>
* Try to set 'fred' through 'bob'. Value remains the same because 'bob' is only the statement "fred".
* Close console and press and release the 'Z' key. Zooms in and out and prints zoom messages.
<kua>
<kua>
> bob alan
zoom is 45
> bob
zoom is 90
'fred' is 'james'
</kua>
</kua>


== Notes ==
== Notes ==
*
*

Latest revision as of 04:28, 15 October 2023

Console commands

Creates a new key binding, replacing existing key binding if any.

bind Z "echo fred"

Arguments[edit]

  • name - name of binding, which corresponds to a particular key, button, or other device.
  • value (optional) - script string or command to run. If not supplied, then prints the script or command value, if the binding exists.

Associations[edit]

  • Key bindings are global, and not a part of any context.

Details[edit]

A 'bind' acts like a custom command for a key. It runs the assigned text as a script, which can contain a single-word command, statement, or script.

By default, binds do not work while input focus is in console or in text mode.

Binds have a special relationship with commands and aliases, where specially named commands will get run during special key or device states. For example, if an alias is named '+bob' and is bound to a key, it will only get called when that key is pressed down, and if named '-bob' will get called when the key goes up.

Examples[edit]

Default values[edit]

  • Check bind 'Z' for script value. No bind exists for key 'Z'.
> bind Z
Unknown: Z
  • Create a bind for the 'Z' key.
> bind Z "echo fred"
  • Close console and press 'Z' key. Prints 'fred'.
fred
  • Same as the first example, but now bind 'Z' exists and shows the value.
> alias bob
'bob' is 'echo fred'

Key states[edit]

  • '+zoom' called without a value. No command, variable or alias named '+zoom' exist.
> +zoom
Unknown: +zoom
  • Create an alias for '+zoom' and '-zoom'.
> alias +zoom "set fov 45; print 'zoom is 45'"
> alias -zoom "set fov 90; print 'zoom is 90'"
  • Create a binding for the 'Z' key.
> bind Z +zoom
  • Close console and press and release the 'Z' key. Zooms in and out and prints zoom messages.
zoom is 45
zoom is 90

Notes[edit]