Zezombye / overpy

High-level language for the Overwatch Workshop with support for compilation and decompilation.
GNU General Public License v3.0
179 stars 27 forks source link

A BUG of the compiler when compiling the function "_ _ setPlayerVariable*__" #170

Closed SweetInk closed 4 years ago

SweetInk commented 4 years ago

Opy code

rule "test":
    @Event eachPlayer
    @Hero all
    __setPlayerVariable__(eventPlayer,C,1)
    __setPlayerVariableAtIndex__(eventPlayer, U, 1, 8)

Compilation result

variables {
    global:
        2: C
        20: U
}
rule ("test") {
    event {
        Ongoing - Each Player;
        All;
        All;
    }
    actions {
        "It should not be a global variable here."
        Set Player Variable(Event Player, Global Variable(C), 1);
        Set Player Variable At Index(Event Player, Global Variable(U), 1, 8);
    }
}

This bug exists in version 5.4.0

Zezombye commented 4 years ago

Operator functions are not supported when writing their special forms (due to quirks like this). You should use eventPlayer.C = 1 and eventPlayer.U[1] = 8 .

SweetInk commented 4 years ago

When you compile this workshop code, you get the following result workshop code

variables {
    global:
        20: U
    player:
        2: C
}
rule ("test") {
    event {
        Ongoing - Each Player;
        All;
        All;
    }
    actions {
        Set Player Variable(Event Player, C, 1);
        Set Player Variable At Index(Event Player, U, 1, 8);
    }
}

Compilation result

/*
The decompiler is functional, but not finished.
It does not support gotos, this mean multi-line actions such as "Abort If" or "Loop If" are not properly decompiled as well.
Some special functions may also not be properly decompiled.

However, decompilation should yield a compilable gamemode. Decompiling then compiling a gamemode should result in the same functional gamemode.
*/

rule "test":
    @Event eachPlayer
    @Hero all

    eventPlayer.C = 1
    __setPlayerVariableAtIndex__(eventPlayer, U, 1, 8)

After compiling, you will get the following code

variables {
    global:
        20: U
    player:
        2: C
}
rule ("test") {
    event {
        Ongoing - Each Player;
        All;
        All;
    }
    actions {
        Set Player Variable(Event Player, C, 1);
       "It should not be a global variable here."
        Set Player Variable At Index(Event Player, Global Variable(U), 1, 8);
    }
}

The compiled workshop code is inconsistent with the original workshop code. As I mentioned above.

Zezombye commented 4 years ago

I see. The decompiler does not support the whole syntax of the Overwatch text language (as it is too difficult to parse - even Blizzard currently has a bug in their parser), but instead only supports the subset of it generated by Overwatch. Basically, the decompiler only supports output that is copy pasted from the workshop GUI.

I will leave this issue open as a reminder for myself to put a warning on the decompiler page specifying that. If you wish to decompile output generated from a third-party tool (including OverPy) then you should paste it into Overwatch and back.

Zezombye commented 4 years ago

Added warning in 5.5.0.