<HTML> <HEAD> <!-- This HTML file has been created by texi2html 1.51 from ProgrammersManual.texinfo on 4 March 1997 --> <TITLE>LambdaMOO Programmer's Manual - Property Values</TITLE> </HEAD> <BODY> Go to the <A HREF="ProgrammersManual_1.html">first</A>, <A HREF="ProgrammersManual_23.html">previous</A>, <A HREF="ProgrammersManual_25.html">next</A>, <A HREF="ProgrammersManual_77.html">last</A> section, <A HREF="ProgrammersManual_toc.html">table of contents</A>. <P><HR><P> <H3><A NAME="SEC24" HREF="ProgrammersManual_toc.html#TOC24">Getting and Setting the Values of Properties</A></H3> <P> Usually, one can read the value of a property on an object with a simple expression: </P> <PRE> <VAR>expression</VAR>.<VAR>name</VAR> </PRE> <P> <VAR>Expression</VAR> must return an object number; if not, <CODE>E_TYPE</CODE> is raised. If the object with that number does not exist, <CODE>E_INVIND</CODE> is raised. Otherwise, if the object does not have a property with that name, then <CODE>E_PROPNF</CODE> is raised. Otherwise, if the named property is not readable by the owner of the current verb, then <CODE>E_PERM</CODE> is raised. Finally, assuming that none of these terrible things happens, the value of the named property on the given object is returned. </P> <P> I said "usually" in the paragraph above because that simple expression only works if the name of the property obeys the same rules as for the names of variables (i.e., consists entirely of letters, digits, and underscores, and doesn't begin with a digit). Property names are not restricted to this set, though. Also, it is sometimes useful to be able to figure out what property to read by some computation. For these more general uses, the following syntax is also allowed: </P> <PRE> <VAR>expression-1</VAR>.(<VAR>expression-2</VAR>) </PRE> <P> As before, <VAR>expression-1</VAR> must return an object number. <VAR>Expression-2</VAR> must return a string, the name of the property to be read; <CODE>E_TYPE</CODE> is raised otherwise. Using this syntax, any property can be read, regardless of its name. </P> <P> Note that, as with almost everything in MOO, case is not significant in the names of properties. Thus, the following expressions are all equivalent: </P> <PRE> foo.bar foo.Bar foo.("bAr") </PRE> <P> The LambdaCore database uses several properties on <CODE>#0</CODE>, the <STRONG>system object</STRONG>, for various special purposes. For example, the value of <CODE>#0.room</CODE> is the "generic room" object, <CODE>#0.exit</CODE> is the "generic exit" object, etc. This allows MOO programs to refer to these useful objects more easily (and more readably) than using their object numbers directly. To make this usage even easier and more readable, the expression </P> <PRE> $<VAR>name</VAR> </PRE> <P> (where <VAR>name</VAR> obeys the rules for variable names) is an abbreviation for </P> <PRE> #0.<VAR>name</VAR> </PRE> <P> Thus, for example, the value <CODE>$nothing</CODE> mentioned earlier is really <CODE>#-1</CODE>, the value of <CODE>#0.nothing</CODE>. </P> <P> As with variables, one uses the assignment operator (<SAMP>`='</SAMP>) to change the value of a property. For example, the expression </P> <PRE> 14 + (#27.foo = 17) </PRE> <P> changes the value of the <SAMP>`foo'</SAMP> property of the object numbered 27 to be 17 and then returns 31. Assignments to properties check that the owner of the current verb has write permission on the given property, raising <CODE>E_PERM</CODE> otherwise. Read permission is not required. </P> <P><HR><P> Go to the <A HREF="ProgrammersManual_1.html">first</A>, <A HREF="ProgrammersManual_23.html">previous</A>, <A HREF="ProgrammersManual_25.html">next</A>, <A HREF="ProgrammersManual_77.html">last</A> section, <A HREF="ProgrammersManual_toc.html">table of contents</A>. </BODY> </HTML>