How to check for a "weapon" attribute in a combat scenario?

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


OK… player.weapon just means the weapon attribute of the object named player.

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 null back.

And the = 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:

  • true if the player's weapon attribute is not set
  • false if the player's weapon attribute is an object
  • an error if the player has a weapon attribute which is a number, string, list, or anything else that isn't an object (because null is 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.


Log in to post a reply.

Support

Forums