ItsDeltin / Overwatch-Script-To-Workshop

Converts scripts to Overwatch workshops.
208 stars 26 forks source link

What should the syntax be for unparalleled structs? #343

Closed ItsDeltin closed 3 months ago

ItsDeltin commented 3 years ago

The problem

This struct will be used as an example.

struct Point
{
    public Number X;
    public Number Y;
}

Variables assigned with this data-type will have their workshop variables generated as so:

// ostw:
Point myPoint = {X: 5, Y: 6};

// workshop generated code:
global.myPoint_X = 5;
global.myPoint_Y = 6;

This has the advantage of avoiding arrays, which is known to be pretty good at hogging server load. There are 2 downsides to this approach, however:

The solution

The solution to this is unparalleled structs, which store the struct data in an array. This is identical to how it structs worked pre-v1.0.

There needs to be a way to mark a struct type as unparalleled, for example, succeeding the type name with the % symbol:

// ostw:
Point% myPoint = {X: 5, Y: 6};

// workshop generated code:
global.myPoint = [5, 6];
ItsDeltin commented 3 years ago

Anonymous types cannot be assigned to the Any type for this reason, because it does not know if it may be a struct type. To solve this, type args can be marked as single, which will not accept parallel structs. Example:

void DoThing<single T>(in T value)
{
    Any assignToAny = value;
}

// Not okie dokie, adds a syntax error.
DoThing<Point>({X: 5, Y: 6});

// okie dokie
DoThing<Point%>({X: 5, Y: 6});
CactusPuppy commented 3 months ago

This has been resolved with the introduction of single structs