Create an account


Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Console Tips & Tricks

#31
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 ). 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! erebus
Reply



Messages In This Thread
Console Tips & Tricks - by BlaXpirit - 05-05-2012, 05:21 AM
RE: Console Tips & Tricks - by Mr. Bougo - 05-05-2012, 07:41 AM
RE: Console Tips & Tricks - by Mr. Bougo - 05-12-2012, 02:16 AM
RE: Console Tips & Tricks - by rocknroll237 - 05-12-2012, 06:32 AM
RE: Console Tips & Tricks - by BlaXpirit - 05-12-2012, 06:41 AM
RE: Console Tips & Tricks - by Mr. Bougo - 05-12-2012, 06:40 AM
RE: Console Tips & Tricks - by rocknroll237 - 05-12-2012, 07:28 AM
RE: Console Tips & Tricks - by Mr. Bougo - 05-12-2012, 08:19 AM
RE: Console Tips & Tricks - by rocknroll237 - 05-12-2012, 12:40 PM
RE: Console Tips & Tricks - by Mr. Bougo - 05-12-2012, 12:42 PM
RE: Console Tips & Tricks - by zykure - 08-10-2012, 10:09 AM
RE: Console Tips & Tricks - by BlaXpirit - 08-10-2012, 10:41 AM
RE: Console Tips & Tricks - by PillowPants - 06-15-2013, 10:49 AM
RE: Console Tips & Tricks - by Mr. Bougo - 06-15-2013, 01:16 PM
RE: Console Tips & Tricks - by PillowPants - 09-14-2013, 08:13 AM
RE: Console Tips & Tricks - by Mr. Bougo - 09-14-2013, 08:43 AM
RE: Console Tips & Tricks - by PillowPants - 09-14-2013, 12:53 PM
RE: Console Tips & Tricks - by Mr. Bougo - 09-14-2013, 01:03 PM
RE: Console Tips & Tricks - by PillowPants - 09-14-2013, 01:15 PM
RE: Console Tips & Tricks - by Mr. Bougo - 09-14-2013, 01:35 PM
RE: Console Tips & Tricks - by PillowPants - 09-14-2013, 02:22 PM
RE: Console Tips & Tricks - by Mr. Bougo - 09-14-2013, 02:28 PM
RE: Console Tips & Tricks - by PillowPants - 09-14-2013, 03:16 PM
RE: Console Tips & Tricks - by FinBiteLeaf - 03-02-2020, 07:54 AM
RE: Console Tips & Tricks - by martin-t - 03-05-2020, 01:45 PM
RE: Console Tips & Tricks - by FinBiteLeaf - 03-07-2020, 04:01 AM
RE: Console Tips & Tricks - by martin-t - 03-07-2020, 07:57 AM
RE: Console Tips & Tricks - by Aguaumreal - 02-13-2021, 09:15 AM
RE: Console Tips & Tricks - by lakrass - 02-13-2021, 09:31 AM
RE: Console Tips & Tricks - by Aguaumreal - 02-13-2021, 05:50 PM
RE: Console Tips & Tricks - by Jiān - 07-30-2024, 02:50 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Console Commands Tutorial Beagle 4 17,145 03-10-2016, 05:53 PM
Last Post: -z-
  kojns video tips and creation thread kojn^ 10 18,618 03-03-2014, 03:11 PM
Last Post: deoxys
  Disabling console print in upper-left corner Zxen 4 9,728 12-11-2012, 06:43 PM
Last Post: s1lence
  Video Creation Tips & Tricks Antibody 10 33,471 11-07-2012, 12:33 PM
Last Post: rocknroll237

Forum Jump:


Users browsing this thread:
1 Guest(s)

Forum software by © MyBB original theme © iAndrew 2016, remixed by -z-