what do you guys think about a implicit conversion between bools a numbers being added?
it shouldn't hurt existing cartridges but would allow for something like this..
local axisy = btn(3)-btn(2) |
normally you would need to write a num function that converts bools to numbers for something like this.



You want to convert true to 1 and false to zero? That would be kinda wonky considering that zero is truthy in lua.



No need for a function. Just use a lookup table. Use it inline, costs 1 extra cycle iirc.
b2n={[false]=0,[true]=1} ... local axisy = b2n[btn(3)]-b2n[btn(2)] |
Oh, and no, please no implicit conversions. That tends to cause hard-to-find bugs.



Another way is to use the and and or operators:
local axisy = btn(1) and 1 or btn(2) and -1 or 0 |



Minor point, but your code would return 1 even if both directions were pressed, which is different from the original, which returns 0 in that case.
Here's the truth table for the original expression:
Y (3) (2) --- --- --- 0 F F -1 F T 1 T F 0 T T |






That's because I was addressing dredds, not you. Your code is different from dredds' code, and yes, it will work.



Ah good then. For a moment I thought my function was in error. But yes it would be nice to have (var <>= var) calculate out to -1 or 1 and zero.
Gold star for your excellent question and observation, @Shadowblitz16.
[Please log in to post a comment]