Much Ado About Nothing
The null object
Section titled “The null object”In Quest code, null has two slightly different meanings. It can be an empty object; that is, an object with no attributes and of the special type “null”.
obj = playermsg(TypeOf(obj))-> "object"obj = nullmsg(TypeOf(obj))-> "null"The variable obj is set to point to the built-in object, null, which is of the type “null”.
Some functions will check if a parameter is null, some do not. Look at the HasString function. It takes an object and a string (the attribute name). It checks if the object is null, and gives a helpful error message if that is not the case.
obj = playermsg(HasString(obj, "name"))-> Trueobj = nullmsg(HasString(obj, "name"))-> Error running script: Error evaluating expression 'HasString(obj, "name")': Value cannot be null. (Parameter 'obj')msg(HasString(player, obj))-> Error running script: Error evaluating expression 'HasString(player, obj)': Value cannot be null. (Parameter 'property')Attributes set to null
Section titled “Attributes set to null”However, null also means nothing. If you set an attribute to null, then the attribute no longer exists.
player.equipped = nullmsg(HasAttribute(player, "equipped"))-> FalseSetting an attribute to null is a useful way to remove a script. Perhaps an object does something weird when picked up. You could give it a script that fires. However, later in the game, the curse is removed, perhaps, and the script is set to null; now the default script runs.
This illustrates an important point: if the object is of a certain type, and the type has a value for the attribute, then setting the attribute to null will reset it to the value in the type. Suppose bob is of the type “male”…
msg(bob.gender)-> "he"bob.gender = "she"msg(bob.gender)-> "she"bob.gender = nullmsg(bob.gender)-> "he"In fact, behind the scenes, what happens is that when we try to access bob.gender, Quest first checks if Bob has that attribute, and if not, it then looks for it in the types associated with Bob.
Compared to null
Section titled “Compared to null”You can test if anything is null, including integers.
obj.att = "somestring"msg (obj.att = null)-> Falseobj.att = playermsg (obj.att = null)-> Falseobj.att = 42msg (obj.att = null)-> FalseIf you are not sure what type a value is, and want to avoid a direct comparison, you can instead use the Equal function:
obj.att = 42msg (Equal(obj.att, null))-> FalseOr compare the type first:
obj.att = 42msg (TypeOf(obj.att) = "null")-> False