Wiki

Clone wiki

PowerChat / Home

PowerChat

This was originally intended to be an addition to PAYDAY 2 ingame chat, but eventually was completely rewritten into sort of a command line language that can work on anything that uses Lua and has a command line. PowerChat has incredibly simple syntax and is easy to use, since it does not have such things as data types, strict syntax rules, and mandatory script parts. It is designed to extend command line inputs and give tools to operate such inputs more effectively.

'PowerChat' was the name of the very first mod for PAYDAY 2 that allowed to use commands in the ingame chat, like:

#!Haskell
!count enemies
or
#!Haskell
!fps 60

Commands could be provided with options and arguments:

#!Haskell
!command arg1 arg2 -opt1 -opt2 arg3

And that was the whole syntax. In the new PowerChat, I kept the same basic approach with options and arguments and extended it with a way to set variables and get their values back and also with the {} brackets that group things into blocks. That instantly gave the opportunity of assigning a line of commands to a variable to execute that line later by getting that variable. That allowed the user to create their own PowerChat commands and, of course, that required a way for such user-made commands to support arguments and options as well. And I made that a thing too. As PowerChat provided support for creating fully functional commands like that, I figured I could write a great deal of standard convenience commands using PowerChat itself. For that I needed to add support for loading up files with commands, or, what I call them, PowerChat script files. That's the story of PowerChat.

Basics

I explain everything using the standard control character (!), but I want to underline that the control character can be any character, as long as it's not the same as any other important PowerChat character. When a PowerChat instance is created, the custom character can be specified.

There is no such thing as a 'typical' PowerChat command, but if there was, it would look like this:

#!Haskell
!add={ {!add.result:{{!1}+{!2}}} {!print !add.result} }

This creates 'add' command that sums up the two arguments given to it. It'll be easier to understand if I clear it up with new lines and spaces:

#!Haskell
!add={ 
        { !add.result:{ {!1}+{!2} } } 
        { !print !add.result } 
    }
The arguments will be placed in the positions of !1 and !2. The first line sums up the args and saves the result in 'add.result'. The second line calls 'print' command giving it the value of 'add.result' as an argument.

Now this command can be called like this:

#!Haskell
!add 2 3

And that will print 5.

Keypoints from this example:

  • Use !variable={script} in the beginning of the line to save that script into that variable.

  • Use !variable:value or !variable:{text to evaluate} to set the variable to a value. In this case the {} block contents will be evaluated/calculated into a value.

  • Math is natively supported in blocks, {5+5} block will be replaced with 10. Do not use parenthesis (), use blocks instead: {2*{5+5}}.

  • !X and !.X will be replaced with the respective argument or option. Use of blocks is recommended with these to have the parser take another look at what you got.

  • Use !variable to get the value of a variable.

  • To use a command with arguments and options passed to it, the command must be called in the beginning of the line or a block.

  • If unsure if you should put something into a block or not, PUT IT INTO A BLOCK. This works too: {{5}{+}{5}}.

If we don't need to save the result, we can rewrite the example above like this:

#!Haskell
!add={!print {{!1}+{!2}}}

Now say we want to use this command in the middle of some text, like:

#!
Two years is {!add 365 365} days

(of course, we don't need the command at all, since math is supported, but this is an example)

It is even simplier to make the command return the value. For that we need to make the value stay as the last thing in the block after every other command is done. We do that in this example by not using !print at all:

#!Haskell
!add={{!1}+{!2}}

So {!add 2 3} gives {2+3} then {5} and finally simply 5. The whole block with 'add' will be replaced with the result:

#!
Two years is 730 days

The [...]

Options and arguments are separated by spaces, but sometimes you may need to include spaces into an option or an argument. That can be done with [] blocks:

#!Haskell
!command [arg1 with spaces] -[opt1 with spaces]

!raw

The special argument !raw is replaced with everything passed to the command, options and arguments together as they were when the command was called:

#!Haskell
!r={!raw}
!r a b -c -d e f
Gives: a b -c -d e f

!disable and !enable

These commands can be used to switch to normal input and back (because PowerChat is designed to work as an addition to an existing input and it cannot always know whether you want it to process your input or not).

This is all of the basics. To get extensive help from inside PowerChat, use !help

Advanced guide >>>

Updated