Hello, I'm very new to Quest and have been setting up a very simple combat scenario to play around with that's mostly based off of the "How to use commands" page (only using the GUI editor, not entirely ready to dive into the coding part yet). I don't understand the expression
player.weapon=null (forgive my post formatting if that's incorrect), mainly because I don't understand what allows an object to apply to it as a weapon. Is it attribute related?
Thanks in advance
player.weapon just means the
weapon attribute of the object named
This is actually a bad habit to get into (
game.pov.weapon would be better), but it probably won't make a difference on your first game. Basically,
game.pov means "the character the player is currently controlling", even if that character's name isn't "player"
null is a special value which technically counts as an object. If you look at an attribute which hasn't been set, you'll get the value
= operator in an expression comparest the things on either side of it to see if they're the same.
So, the expression
player.weapon = null will return:
trueif the player's
weaponattribute is not set
falseif the player's
weaponattribute is an object
weaponattribute which is a number, string, list, or anything else that isn't an object (because
nullis technically an object, and
=tends to have problems comparing things that are different types).
That's assuming that the expression you gave is actually an expression (something that appears in the GUI in a box that says it's an expression). If you had
player.weapon = null on a line of code on its own, then that is an assignment not an expression, so the
= works differently. In this case, it sets the player's
weapon attribute to the result of the expression
null; which basically deletes that attribute.