I think the documentation on `physics.body.categories` is wrong

In my experiments, the range of numbers allowed in a physics body’s categories is 1 to 16.

The documentation says the range is 0 to 15.

0 seems to be ignored completely when you try to add it to a body’s categories, and any number over 16 seems to be automatically converted to 16… which is really odd behavior if you ask me, but I’m assuming it’s an artifact of Box2d’s code and not @John’s or @Simeon’s.

@John, @Simeon maybe it would be good to change the code in PhysicsLab, because the categories and masks assigned to bodies in the code are not the ones that actually get used. That could seriously mislead people trying to use PhysicsLab as a guide. See console printout in attached image, which reports on Test5.

yeah i ran into this problem,
https://codea.io/talk/discussion/12186/physics-categories-and-mask#latest

it’s probably because Lua starts at index 1 and box2d uses C++ originally which starts at 0 and there wasn’t any index messaging put in place

the reason anything above 16 is converted is because masks and categories use bit addresses and there’s only room for 16

Good catch @UberGoober, documentation updated!

Is this correct now?

https://github.com/TwoLivesLeft/Codea-Documentation/commit/2fb79d01e43c5c618d9bab891223390cb8106e0f

Note that if you ever have a fix and the time, you can submit a pull request to the documentation here https://github.com/TwoLivesLeft/Codea-Documentation

@Simeon, that looks right to me, it’s great you were free to jump on that so quickly.

Personally I think it’s just as important, if not more important, to have the example code in PhysicsLab updated, but I get that it might take more work.

@UberGoober I have updated that as well. Thanks for finding the issue

box.categories = {1}
box.mask = {1,3}

circle.categories = {2}
circle.mask = {1,3}

box2.categories = {3}
box2.mask = {1,2}

@Simeon thats awesome! Thanks again for fixing that up toot sweet!