-
Notifications
You must be signed in to change notification settings - Fork 0
Command Syntax
Commands in GalaxiEngine work mostly how you would expect them to, but you have more power than you may know. This page goes over the syntax for creating advanced commands.
The first thing you probably are wanting to know is how to escape special characters. As is standard in many places, the escape character here is the humble backslash (\).
\\ is the escape for a backslash (\)
\" is the escape for a double quote (")
\' is the escape for a single quote (')
\ is the escape for a space
When the PARSE_CONSOLE_VARIABLES option is enabled:
\$ is the escape for the dollar sign ($)
\% is the escape for the percent sign (%)
\ followed by 3 numbers is an escape for an ASCII character (More info)
\b is the escape for the backspace character
\n is the escape for the newline character
\t is the escape for a tab
\r is the escape for the carriage return character
\f is the escape for the form feed character
\u followed by a 4-character hex code is the legacy escape for a Unicode character (More info)
\u{...} populated with a hex code is the new escape for a Unicode character (More info)
Examples:
\176 translates to ~
\u00A7 translates to §
\u{A7} also translates to §
If you don't fancy typing escapes all the time just to submit some text, then quoting is your friend, as two different quote types have been reserved to solve that problem.
Single quotes (') signify that the content within should be taken at face value, or treated literally. This means that a literal string cannot use any of the formatting described on this page because no parsing for that is happening. The only valid escape sequence is a custom one for the single quote itself, which is ''.
Double quotes ("), by contrast, only signify that the white-space within should be preserved. In other words, this means that all spaces inside will be treated literally instead of as argument separators, without the need to escape them. All formatting on this page is still fair game inside double quotes; even using single quotes. In addition, a similar custom escape sequence for the double quote itself is also present here: "".
Standard quote usage:
Most of the time when using quotes, you will end up with something like this because an argument with special characters came along.
/example add 'that one time' 54 results in the following argument(s):
args[0]: add
args[1]: that one time
args[2]: 54
Quotes inside other quotes:
As mentioned before, single quotes may be used inside double quotes.
/example "double outside '\u{A7}ingle' inside\u{A7}" results in the following argument(s):
args[0]: double outside \u{A7}ingle inside§
However, double quotes may not be used inside single quotes.
/example 'single outside "\u{A7}double" inside\u{A7}' results in the following argument(s):
args[0]: single outside "\u{A7}double" inside\u{A7}
Quotes beside other quotes:
Quotes may sit immediately beside other content if needed. This, of course, includes differing quote types.
/example '"single" quotes '"beside double quote\u{A7}" results in the following argument(s):
args[0]: "single" quotes beside double quote§
This can be useful if you are in need of the abilities of both quote types in the same argument. You should be careful to not place two quotes of the same type next to each other, though. If you make that mistake, they will instead be interpreted as an escape sequence. For example:
/example "double quote\u{A7} ""beside double quote\u{A7}" results in the following argument(s):
args[0]: double quote§ "beside double quote§
Open-ended quotes:
Quotes that are not closed result in the rest of the command being parsed with those rules.
/example "the '"example" command i\u{A7} pretty cool results in the following argument(s):
args[0]: the "example" command i\u{A7} pretty cool
Here \u{A7} was not parsed because the single quotes were never closed.
Perhaps this is what they were trying to do:
/example "the '"example"' command i\u{A7} pretty cool results in the following argument(s):
args[0]: the "example" command i§ pretty cool
Notice that this still resulted in a single argument. That's because the double quotes at the beginning were also never closed. For the most part, we recommend that you close all of your quotes so that you don't end up confusing yourself. It's just a best practice sort of thing.
Lastly, when the PARSE_CONSOLE_VARIABLES option is enabled, you can make use of system variables in your commands. Two additional characters are reserved for batch-style variable parsing while in this mode.
%example% for environment variables
$example$ for java system properties
To make use of a variable, surround its name with the appropriate symbol as in the above examples. Variable names are taken literally, so there is never a need to escape the characters within them.
/example "Hello, my name is $os.name$." could result in the following argument(s):
args[0]: Hello, my name is Windows 10.