Engine:CCMD bind: Difference between revisions

From AddOn Studio
Jump to navigation Jump to search
No edit summary
Line 17: Line 17:
== 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>
> bind Z
> bind Z
Unknown: bob
Unknown: Z
</kua>
</kua>
* Call 'bob'. No command, variable or alias named 'bob' exist.
* Create a bind for Z key to echo 'fred'.
<kua>
<kua>
> bob
> bind Z "echo fred"
Unknown: bob
</kua>
</kua>
* Create an alias 'bob' and set to 'echo fred'.  
* Close console and press 'Z' key. Prints 'fred'.
<kua>
<kua>
> alias bob "echo fred"
</kua>
* Same as the second example, but now alias 'bob' exists. The 'echo' command in the 'bob' alias script runs, and prints 'fred'.
<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 of the bind 'Z'
<kua>
<kua>
> alias bob
> alias bob

Revision as of 01:19, 15 October 2023

Console commands

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

bind Z "echo fred"

Arguments

  • 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

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

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.

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

Examples

Default values

  • Check bind 'Z' for script value. No bind exists for key 'Z'.
> bind Z
Unknown: Z
  • Create a bind for Z key to echo 'fred'.
> 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 of the bind 'Z'
> alias bob
'bob' is 'echo fred'

To a variable

  • 'bob' called without a value. No command, variable or alias named 'bob' exist.
> bob
Unknown: bob
  • Create an alias 'bob' and set to 'fred'.
> alias bob fred
  • Same as the first example, but now alias 'bob' exists. The 'fred' command in the 'bob' alias script runs, and 'fred' doesn't exist.
> bob
Unknown: fred
  • Create variable 'fred'.
> var fred james
  • Run 'bob'
> bob
'fred' is 'james'
  • Try to set 'fred' through 'bob'. Value remains the same because 'bob' is only the statement "fred".
> bob alan
> bob
'fred' is 'james'

Notes