Commands

Inline Command Evaluation

Since commands can return values to Paisley after execution, you can also use those values in further calculations. For example:

#Get an integer value representing in-game time, and convert it to a human-readable format
let t = {floor(${time})}
let hour = {t // 3600}
let minute = {(t // 60) % 60}
let second = {t % 60}
print {hour ":" minute ":" second}

Of course, there is also a simpler version that does the same thing:

print {${time}.clocktime()[1:3].join(":")}

Built-in commands

For ease of use and consistency, there are 6 built-in commands that will always be the same regardless of what the target environment is.

In the PC build, the following commands are also available:

Shell command coersion

If the --shell or -l flag is passed, then Paisley will assume that any undefined commands are programs available on this system.

# Plain commands will not capture stdout or stderr, so the following are equivalent:
wget https://127.0.0.1/example
= wget https://127.0.0.1/example

# But inline command evaluation captures stdout, so the following are equivalent:
let x = ${wget https://127.0.0.1/example}
let x = ${? wget https://127.0.0.1/example}
# And NOT equivalent to the following which captures the RETURN value of wget:
let x = ${= wget https://127.0.0.1/example}

Command piping

Like Bash, the stdout of commands can be piped into other commands, or from and to files. This uses the same syntax as bash, for familiarity, and because the syntax is simple enough.

# Some sample bash commands.
echo "some text" > my_file.txt
cat my_file.txt | grep "some"
grep "something <<<"text input"
grep "something" <"file input"

There is one difference however, and it’s that the stdout and stderr files are not called 1 and 2 respectively, instead they are ? and ! to remain consistent with other syntax. For example, to pipe stderr into a file:

wget https://127.0.0.1/example !>my_file.txt

Also note that unlike in Bash, you must explicitly specify the input stream:

echo "text" >file.txt #This will not work!

echo "text" ?>file.text #Pipes stdout into the file.
echo "text" !>file.text #Pipes stderr into the file.
echo "text" ?!>file.text #Pipes BOTH stdout and stderr into the file.
echo "text" !>? #Pipes stderr to stdout.

< Prev | Home | Next >