adapap / OWScript

Python-like scripting language which transpiles into Overwatch Workshop script rulesets.
MIT License
37 stars 2 forks source link

Chasing Variables is impossible #1

Closed DecibillyJoel closed 5 years ago

DecibillyJoel commented 5 years ago

Attempting to use Chase [Global / Player] Variable [At Rate / Over Time] (and, I suspect, other actions that have to do with variables not managed by OWScript) will cause OWScript to generate invalid Workshop code. The problem is that all variables in OWScript are just values in an array, but you cannot Chase a value in an array. You can only Chase an actual variable.

Consider the following simple example:

Rule "ez test"
    Event
        Event_Type: On Global
    Actions
        a = 5
        Chase Global Variable At Rate
            Variable: a
            Destination: 0
            Rate: 1
            Reevaluation: Destination And Rate

That results in this:

rule("Generated by https://github.com/adapap/OWScript") { Event { Ongoing - Global; }}
rule("ez test") {
   Event {
      Ongoing - Global;
   }
   Actions {
      Set Global Variable At Index(A, 0, 5);
      Chase Global Variable At Rate(Value In Array(Global Variable(A), 0), 0, 1, Destination And Rate);
   }
}

Attempting to paste this into the Workshop will give you this error: Error: Expected ',' after 'Rate(' on line 8

And yet it will happily accept this small (and illogical) change:

rule("Generated by https://github.com/adapap/OWScript") { Event { Ongoing - Global; }}
rule("ez test") {
   Event {
      Ongoing - Global;
   }
   Actions {
      Set Global Variable At Index(A, 0, 5);
      Chase Global Variable At Rate(A, 0, 1, Destination And Rate);
   }
}

Additionally, I don't think there is any simple workaround for this within OWScript, since any attempt to indicate an actual Workshop variable gets replaced by the OWScript variable system. For me to work around this, I would need to basically comb through OWScript's output every time I need to do something that involves chasing variables.

I'm not sure how this can be fixed since using an array for the variables is such a core feature of OWScript, but in any case, it would help if there was a way to include raw Workshop code in the OWScript code (kind of like a comment, but instead of being completely ignored, it's simply left in the output as it is). That would allow the user to create temporary workarounds for situations like this without having to comb through the output themselves.

adapap commented 5 years ago

Adding support for chase variables in the next release. You will be able to use variables as they are normally used in OWScript - internally, your variable will be reassigned to the next available letter. Here is a simple example:

Rule "Chase Test"
    Actions
        gvar chase_var = 100
        Chase Global Variable At Rate
            Variable: chase_var
            Destination: 0
            Rate: -1
            Reevaluation: Destination And Rate

This gets compiled to the following rule:

rule("Chase Test") {
   Actions {
      Set Global Variable At Index(A, 1, 100);
      Set Global Variable(B, Value In Array(Global Variable(A), 1));
      Chase Global Variable At Rate(B, 0, -1, Destination And Rate);
   }
}