ItsDeltin / Overwatch-Script-To-Workshop

Converts scripts to Overwatch workshops.
207 stars 24 forks source link

Unable to set player variable on a filtered array of players #496

Open SlenderFox opened 2 weeks ago

SlenderFox commented 2 weeks ago

Attempting to set the player variable on a filtered array of players yields the error "No variable by the name of 'variable name' exists in the current scope."

e.g.

playervar Number A;
playervar Number B;

rule: "Example"
{
    FilteredArray(AllPlayers(), ArrayElement().A > 5).B = 5;
}

Error: "No variable by the name of 'B' exists in the current scope."

Of course in this example you could set the rule to be OnGoingPlayer, however in a different situation this wouldn't be possible/reasonable.

SlenderFox commented 2 weeks ago

Similar to #490 I found that casting to Players before accessing fixes the error, however unlike #490 this doesn't feel like an unneeded workaround since the return type of FilteredArray is Any. (<Player>FilteredArray(AllPlayers(), ArrayElement().A > 5)).B = 5; I would like to see the error message improved to be more clear that this could be solved with type conversion.

CactusPuppy commented 2 weeks ago

The "semantic" way of doing a Filtered Array in OSTW is All Players().Filter(player => player.A > 5), though understandably this isn't well-known since the decompiler does not output this translation.