brandonlilly / lantern

A high level staredit trigger compiler

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Bound Types for Counters

michael-butler opened this issue · comments

We should make bound types for counters so the user can specify how the variable should be used. For example, coordinates should never go outside the map, so its bounds should not be changed. Angles could be simplified by having the value wrap around automatically so it stays in the range. By default, the bounds would be changeable as we currently have implemented.

DEFAULT:
dc1 = DC.new( min: 0, max: 100 )
dc1 << 5
dc1's bounds changed to min: 5, max: 5

RIGID:
coordinates = DC.new( min: 0, max: 100, boundType: rigid )
coordinates << 200
implicitly appends
_if ( coordinates > 100 ) [ coordinates << 100 ]
_if ( coordinates < 0 ) [ coordinates << 0 ]
and its bounds remain the same

WRAP:
angle = DC.new( min: 0, max: 100, boundType: wrap)
angle << 200
implicitly appends
_if ( angle > 100 ) [ angle << angle - 100 ]
_if ( angle < 0 ) [ angle << angle + 100 ]
and its bounds remain the same