Hi,
While looking at the commands related to
demo recording I came across something interesting, a new variable function that's not mentioned in this guide, perhaps it was added later, I'm not sure about it's timeline. I'm talking about these expansion variable functions:
Quote:${4 ?} means the fourth parameter, or nothing if it wasn't passed.
${2 asis} means the second parameter, without escaping quotes (because by default they are escaped)
${* q}, ${1- q} means all the parameters as they were provided, escaped (spaces and quotes work)
In Xonotic "
?", "
asis", "
q" and a new member to the family "
!" (
the exclamation mark, also know as
bang) are collectively referred to as "variable function" (at least that's what the error messages call them
![Tongue Tongue](https://forums.xonotic.org/images/smilies/tongue.png)
). They specify how to handle the expansion of arguments (passed to aliases) and cvars. While BlaXpirit has explained the behavior of first 3 of these variable functions, I'll try to explain the behavior of the 4th variable function.
The
bang variable function throws detailed error message and aborts the execution of procedure/actions associated with it, when there is an expansion error (undefined cvar or an argument not passed to an alias etc). It has no effect on the input like the other 3 variable functions have.
Code:
// NOTE: "->" means it's console output.
// Cvar expansion, the greeting cvar is not defined
echo ${greeting}; // -> Warning: Could not expand $greeting
// -> $greeting
// echo command was still executed regardless of an expansion error.
echo ${greeting !}; // -> Error: Could not expand $greeting
// no output for the echo command as it was likely aborted.
// Alias parameter expansion
alias print "echo ${1- !}; echo SUCCESS"
print Hello Xonotic!; // -> Hello Xonotic!
// -> SUCCESS
print; // -> Error: Could not expand $1- in alias print
// No SUCCESS was printed to the console.
This can be used to check if a cvar is defined in console namespace, like so:
Code:
// cvar_exists <identifier> <cvar-name>
alias cvar_exists "set ${1 !} \"0\"; set __cvar_exists_cvar_name__ \"${2 !}\"; __cvar_exists__ ${1}"
alias __cvar_exists__ "${1 !} 1; set __tmp_data__ \"${$__cvar_exists_cvar_name__ !}\""
// the procedures/actions in __cvar_exists__ alias only get executed when the expansion is successful, thus
// the <identifier> is set to 1 on expansion success, otherwise it remains 0. Effectively letting us know, if
// the cvar is defined or not, this can then be combined with rest of the console tricks to perform action based
// on the existence of certain cvars.
// Usage example:
cvar_exists result1 _cl_name // result1 contains 1; it exists and contains your player nick
cvar_exists result2 _uncle_roger // result2 contains 0; does not exists/ is not defined, it will also output an error message
// which can be ignored.
That's all, thanks to BlaXpirit for his awesome guide.
Keep fragging!