For those who missed the Twitter post by Zep, he's published the official 0.1.6 changelog! He said the new version is coming this week.
I'm so excited for the cartridge explorer! Also I got in the habit of typing a bit slower because of the duplicate keypress thing, that'll be nice to have fixed.
The coroutine and metatable stuff is nice too. For me, the absence of these was the only thing keeping it from feeling like full Lua.
Thanks @zep!
Those sound fixes will help greatly with mixing sfx with music that needs 4 channels.
And setmetatable is a very welcome thing! In anticipation, I wrote a vector math helper type that I might never use. (and it works fine in regular Lua, just need to provide atan2/sqrt as upvalues to the script)
v2mt={ __add=function(a,b)return v2(a[1]+b[1],a[2]+b[2])end, __mul=function(a,b)return type(a)=='number'and v2(a*b[1],a*b[2])or v2(a[1]*b,a[2]*b)end, __div=function(a,b)return a*(1/b)end, __unm=function(v)return v*-1 end, __sub=function(a,b)return a+-b end, __tostring=function(v)return v[1]..' '..v[2]end, } function v2(x,y)return setmetatable({x,y},v2mt)end function v2dot(a,b)return a[1]*b[1]+a[2]*b[2]end function v2dir(v)return atan2(v[2],v[1])end function v2mag(v)return sqrt(v[1]^2+v[2]^2)end function v2norm(v)return v/v2mag(v)end |
Just call v2 with an x and y component, and it'll generate a table value with a vector metamethods. Alternatively, call with no arguments and you get the zero vector.
This vector type supports addition (a + b), subtraction (a - b), unary negation (-v), multiplication by scalar (k v, v k), division by scalar (v / k), tostring(v), dot product (vdot), direction (vdir) + magnitude (vmag) (for polar coordinates), and normalization (vnorm). And you can also treat as a table with two elements by indexing, but be careful if you modify the components, as this will modify all references to that value.
If PICO-8 could one day support _G or _ENV (maybe as _g / _env), I'd be very happy. It's easy enough to work around, but with token and character limits, being able to index the globals table like a regular table is occasionally handy. And it means that functions/variables that are accessed by name in this fashion can just be top-level declarations, which cost less tokens than a table literal containing a bunch of junk. (no {}, no comma/semicolon delimiters needed, functions don't need to be written name = function() end)
[Please log in to post a comment]