Skip to content

v2.0-beta.0

Pre-release
Pre-release

Choose a tag to compare

@ItsDeltin ItsDeltin released this 23 Oct 23:30
· 884 commits to master since this release

Important

This is a preview. Some syntax may change before the final release.

Breaking changes

  • Lambdas whose parameters contain types must be wrapped around parentheses. Lambdas can now determine the parameter types from the context, so all you need to do is remove the type,
    Example:
array.FilteredArray(define a => a == 6)

to

array.FilteredArray(a => a == 6)

or

array.FilteredArray(a => (define a) == 6)
  • In future previews, the new string functions will probably be moved into the string type.

Removed ButtonValue, any occurrences of something like ButtonValue(Button.PrimaryFire) can be replaced with just Button.PrimaryFire.

VSCode extension

Because this is a preview, the vscode extension will not automatically update. Everything except decompiling will still work with the current version, so if you want to decompile, be sure to install the .vsix extension included in the assets.

2.0 features not included in this preview (@Protowalker 👀 )

  • Linux support
  • Explicit typing
  • Type aliasing*
  • Generics*

*May come out after 2.0 is released, we will see!

Changelog

Added support for the Workshop's October 2020 patch

Patch notes here.

Code text parser completely reworked

  • The new parser is extremely fast.
    • The Workshop Code channel in the output updates too slow, use the Create a panel for workshop code output to see the live changes in real time.
  • Files are now parsed incrementally.
  • Missing tokens are now handled elegantly.
    • This includes missing parentheses, brackets, etc.
    • File an issue if you get an exception from a missing character in your script.

Portable functions and subroutine variables

You can now store functions in variables, for example:

Example 1

// Specify the function name without parameters.

// 'DeclareMatchDraw()' is a function with no parameters that returns nothing.
(() => void) myFunction = DeclareMatchDraw;
myFunction();

Example 2

// 'Teleport(players, location)' is a function with 2 parameters that returns nothing.
((define, define) => void) tp = Teleport;
tp(eventPlayer, location);

Example 3

// An array of functions:
(() => void)[] functionArray = [
    DestroyAllDummyBots,
    DestroyAllEffects,
    DestroyAllHudText,
    DestroyAllIcons,
    // Lambdas work as well!
    () => {
        SmallMessage(AllPlayers(), "This was called from inside a lambda!");
    }
];

// Functions are internally stored as an array,
// because AppendToArray flattens arrays, you need to wrap the function inside [ ].
// This will probably be handled automatically before the full 2.0 release.
ModifyVariable(functionArray, Operation.AppendToArray, [DestroyAllInworldText])

// Execute the functions
foreach ((() => void) func in functionArray)
    func();

Example 4

rule: "My rule"
{
    // Choose a random subroutine.
    (() => void) myFunction =
        // Choose either 0 or 1.
        RandomInteger(0, 1) == 0 ?
        // If 0 is chosen, use Subroutine1.
        Subroutine1 :
        // Otherwise, use Subroutine2.
        Subroutine2

    // Call the subroutine.
    myFunction();
}

void Subroutine1() "Subroutine #1"
{
    SmallMessage(AllPlayers(), "This is subroutine #1");
}

void Subroutine2() "Subroutine #2"
{
    SmallMessage(AllPlayers(), "This is subroutine #2");
}

WaitAsync

WaitAsync functions like the Wait action but it does not block the current rule. A rule with a wait cannot be executed again until the wait is over, however, with WaitAsync it can be activated multiple times.

// If the host player presses interact, a number will be printed and 3 seconds later the same number will be printed again.
// Pressing interact multiple times in 3 seconds will execute the rule each time, unlike the default Wait.
// Local variables are captured, so 'value' is not replaced when executing the rule again.
rule: "Test"
if (IsButtonHeld(HostPlayer(), Button.Interact))
{
    define value = RandomInteger(0, 5);
    SmallMessage(AllPlayers(), <"Start: <0>", value>);

    WaitAsync(3, () => {
        SmallMessage(AllPlayers(), <"End: <0>", value>);
    });
}

Constructor subroutines

class Test
{
    public Test() "This is the subroutine name."
    {
    }
}

Decompiling

  • Improved error reporting.
  • Custom workshop settings are now supported.
  • The ^ operator is now recognized as right-associative.
  • Fixed decompiling Start Damage Modification and Start Healing Modification.
  • Fixed decompiling certain maps.
  • Fixed decompiling disabled modes.
  • Fixed decompiling several specific hero settings. (@Polymathical)

Bug fixes (and other stuff)

  • Any files with the .lobby extension can be used instead of customGameSettings.json.
  • Fixed ternary precedence.
  • Fixed exception when using enums in ternaries. (@Protowalker)

VSCode extension

  • Updated syntax to support function types like (() => void).

Known issues:

  • Some diagnostic's error range is one character longer than it should be.