SpaceTown-Developers / Lemon-Gate

Expression Advanced a Lua sub language.
Other
15 stars 5 forks source link

Suggestion: changed() #206

Closed ghost closed 10 years ago

ghost commented 10 years ago

probably biggest issue i came across coding lemon gate that there's no changed().

shadowscion commented 10 years ago

The delta operator $ serves this purpose in lemongate.

h3xcat commented 10 years ago

if($Variable != 0){print("changed")} But this only works with number variables

shadowscion commented 10 years ago

Should work with any variable type

vector V = vec(1, 1, 1)

event think() {
    V = V + vec(1, 1, 1)
    if ( $V ) {
        print( "Changed" + (string) V )    
    }
}

Changed<Vector3: 2 2 2>
Changed<Vector3: 3 3 3>
Changed<Vector3: 4 4 4>
Changed<Vector3: 5 5 5>
Changed<Vector3: 6 6 6>
Changed<Vector3: 7 7 7>
Changed<Vector3: 8 8 8>
Changed<Vector3: 9 9 9>
Changed<Vector3: 10 10 10>
Changed<Vector3: 11 11 11>
Changed<Vector3: 12 12 12>
Changed<Vector3: 13 13 13>
Changed<Vector3: 14 14 14>
Changed<Vector3: 15 15 15>
Changed<Vector3: 16 16 16>
Changed<Vector3: 17 17 17>
Changed<Vector3: 18 18 18>
Changed<Vector3: 19 19 19>
Changed<Vector3: 20 20 20>
h3xcat commented 10 years ago

what about variable types such as string, table, arrays, entities and etc.?

shadowscion commented 10 years ago

Doesn't look like those types are supported (string and entity probably should have support though, they do in e2). It works with numbers, vectors and angles for sure though.

h3xcat commented 10 years ago

Delta shouldn't work with types that doesn't have numbers, and it's original purpose isn't meant to be used as a way to detect variable changes. All delta does is return difference value of current and previous variable state.

ghost commented 10 years ago

sorry i didn't maybe describe it clearly enough, i know delta but i need it in strings etc. and you can make it pretty easily with one static number, but still it's slower than typing changed() :)

guillaume-dorczynski commented 10 years ago

Just store the string in another variable, that you will use to compare later...

Orzlar commented 10 years ago

its ~

if(~Variable){ do stuff }

works with : Strings, Entities, vectors, angles, booleans

Edit: seems it doesn't work with strings, maybe convert to char IDs then count? or do above.

Rusketh commented 10 years ago

As orzlar stated above, use ~Var to detect change of variable.