Take the quiz! CollisionGroups in TAML
by Mike Lilligreen · in Torque 2D Beginner · 07/12/2013 (3:02 am) · 11 replies
Question 1) You receive a TAML file for a scene object with the following field:
What SceneGroup(s) will this object collide with?
A. Groups 0, 1, 2, and 3
B. Group 15
C. No SceneGroups
D. Groups 1 and 5
Question 2) You are manually writing a TAML file and want an object to collide with SceneGroups 28, 29 and 30. What do you put in the CollisionGroups field?
A. CollisionGroups="87"
B. CollisionGroups="28 29 30"
C. CollisionGroups="1879048192"
D. CollisionGroups="24360"
Question 3) You have the following in TorqueScript:
What would the output be if exported to TAML?
A. CollisionGroups="none"
B. CollisionGroups="0"
C. There would be no CollisionGroups field in the exported file.
D. CollisionGroups="15"
Don't run to your T2D setup to solve these, if you are unsure just post your guesses here. It's all in good fun - especially if you don't come from a computer science background like me. Answers coming soon!
CollisionGroups="15"
What SceneGroup(s) will this object collide with?
A. Groups 0, 1, 2, and 3
B. Group 15
C. No SceneGroups
D. Groups 1 and 5
Question 2) You are manually writing a TAML file and want an object to collide with SceneGroups 28, 29 and 30. What do you put in the CollisionGroups field?
A. CollisionGroups="87"
B. CollisionGroups="28 29 30"
C. CollisionGroups="1879048192"
D. CollisionGroups="24360"
Question 3) You have the following in TorqueScript:
%quiz = new SceneObject(); %quiz.setCollisionGroups(none);
What would the output be if exported to TAML?
A. CollisionGroups="none"
B. CollisionGroups="0"
C. There would be no CollisionGroups field in the exported file.
D. CollisionGroups="15"
Don't run to your T2D setup to solve these, if you are unsure just post your guesses here. It's all in good fun - especially if you don't come from a computer science background like me. Answers coming soon!
About the author
#2
07/12/2013 (4:11 am)
Sorry, I just made an edit to question 3 since depending how you interpret what I wrote there could be two answers. It is fixed now, do you want to keep your answers the same practicing?
#4
Q2) C (2^28)+(2^29)+(2^30) = 1879048192
Q3) B
The collision-groups field is actually a single U32 mask where each bit represents the respective field so TAML will read/write it as just that, a U32.
The equivalent method call is "setCollisionMask()" that takes the mask directly. The method "setCollisionGroups()" is a helper which can take "none", "all" or a space/tab/newline separated group-number list. This helper is just like "setCollisionAgainst()" which is just another helper.
Granted, it would probably be more user-friendly to get TAML to write the groups out as a (say) space-separated list and that change is pretty trivial but it would break existing persisted TAML files.
What do we win?
07/12/2013 (4:43 am)
Q1) AQ2) C (2^28)+(2^29)+(2^30) = 1879048192
Q3) B
The collision-groups field is actually a single U32 mask where each bit represents the respective field so TAML will read/write it as just that, a U32.
The equivalent method call is "setCollisionMask()" that takes the mask directly. The method "setCollisionGroups()" is a helper which can take "none", "all" or a space/tab/newline separated group-number list. This helper is just like "setCollisionAgainst()" which is just another helper.
Granted, it would probably be more user-friendly to get TAML to write the groups out as a (say) space-separated list and that change is pretty trivial but it would break existing persisted TAML files.
What do we win?
#5
07/12/2013 (4:48 am)
@Alien Cabbage : That's off the top of your head without checking the source code?
#6
Thanks for saving me a write up though!
P.S. I knew collision groups used a bitmask but I blindly went ahead last night with integers in TAML and was pulling my hair out wondering why objects were not colliding with SceneGroup zero. :)
07/12/2013 (4:57 am)
I probably should have put in a disclaimer that GarageGames employees and vegetables not native to our planet were disqualified from winning. :PThanks for saving me a write up though!
P.S. I knew collision groups used a bitmask but I blindly went ahead last night with integers in TAML and was pulling my hair out wondering why objects were not colliding with SceneGroup zero. :)
#7
@Simon: Yup. It's a pretty well used field so if folk don't know this (and there's obviously not an editor) then I guess it means they never have stuff colliding with each other or just use the helper I described. :)
Do think that the field should be changed to be more friendly at the expense of performance by outputting the groups separately as integers.
Next time I'll try not to spoil the quiz!
07/12/2013 (5:06 am)
Sorry, should've thought that was a spoiler! *hangs head in shame*@Simon: Yup. It's a pretty well used field so if folk don't know this (and there's obviously not an editor) then I guess it means they never have stuff colliding with each other or just use the helper I described. :)
Do think that the field should be changed to be more friendly at the expense of performance by outputting the groups separately as integers.
Next time I'll try not to spoil the quiz!
#8
On a more serious note, I always use bit(0)|bit(1)|bit(2) etc. Worked for me so far.
07/12/2013 (5:13 am)
hehehehe no hard feelings, I was just thinking 'I wish I were half as cool as this leafy vegetable.On a more serious note, I always use bit(0)|bit(1)|bit(2) etc. Worked for me so far.
#9
@Alien Cabbage - I bet there's not a lot of people out there building objects in TAML from scratch so they probably haven't noticed the funny numbers this field generates if they ever did a TamlWrite. All tutorials build objects completely in TorqueScript I believe and all the sandbox examples are done that way too.
07/12/2013 (5:22 am)
@practicing - ok, since the correct answers are out there, Q3 is B because defaults aren't written out when exported and the default bitmask for CollisionGroups is (all).@Alien Cabbage - I bet there's not a lot of people out there building objects in TAML from scratch so they probably haven't noticed the funny numbers this field generates if they ever did a TamlWrite. All tutorials build objects completely in TorqueScript I believe and all the sandbox examples are done that way too.
#10
07/12/2013 (5:48 am)
@Simon - bit(0), etc doesn't work in TAML, just tried it out. So if you are making an object from scratch in TAML and not exporting it from TorqueScript you need to know the math behind converting a bitmask to an integer, as AlienCabbage showed in his post.
#11
Additionally would have to throw an exception if they're both defined I guess which begins to make it complicated.
07/14/2013 (3:46 am)
Wouldn't it be possible to add a possible TAMLField that can take the more friendly spaced format? That way existing persisted objects won't break and we'll be able to make more readable TAML in the future?Additionally would have to throw an exception if they're both defined I guess which begins to make it complicated.
Torque Owner practicing01
MourningDoveSoft
Q2) C
Q3) C
Correct me if I'm wrong :0