adapap / OWScript

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

Accessing an array element uses the value assigned to the array instead of actually accessing the array #31

Closed netux closed 4 years ago

netux commented 4 years ago

Title is a little weird. Basically, if you create an array like so

gvar arr = [ 0, Null, False ]

and later try to access elements of that array

Big Message(Everyone, arr[1])

it transpiles to a Big Message with the string input Null (value assigned to the array element) instead of Value In Array(Value In Array(Global Variable(A), 0), 1) (reading value from array)

Example code

pvar array = [ 0, Null, False ]
Big Message(Everyone, `{} {} {}`(array[0], array[1], array[2]))

outputs

Set Global Variable At Index(A, 0, Append To Array(Append To Array(Append To Array(Empty Array, 0), Null), Null));
Big Message(All Players(Team(All)), String("{0} {1}", 0, String("{0} {1}", Null, False, Null), Null));

instead of

Set Global Variable At Index(A, 0, Append To Array(Append To Array(Append To Array(Empty Array, 0), Null), Null));
Big Message(All Players(Team(All)), String("{0} {1}", Value In Array(Value In Array(Global Variable(A), 0), 0), String("{0} {1}", Value In Array(Value In Array(Global Variable(A), 0), 1), Value In Array(Value In Array(Global Variable(A), 0), 2), Null), Null));
netux commented 4 years ago

This is a problem with arrays holding other variables, as modifying that variable essentially modifies the array:

gvar var = 0
gvar arr = [var]
var = 1
arr[0] // => var => 1, not 0
MatthewSH commented 4 years ago

so, funny thing. This is actually how it used to act with gvar all together for the most part. This was fixed a month ago, can't remember the commit exactly. This behavior was, eventually, put back in with the const keyword addition in 6334860a12bea39457842c8de0aa5dfe3db8d04a.

I wonder if arrays slipped through the cracks.