Code

Code is a type of property that stores a block of TworldPy code, which is mainly the same as Python code. Code properties may not be focused by players.

Any properties in the code that are given "standalone" are executed - text will be focused, code executed, move will move the player.

When the code property is not called but interpolated, any action properties being called or properties being assigned will cause an error. All text properties and variables will be concatenated and appear as the interpolation result. Note that string values are not treated as markup text - for that to happen they have to be passed through the  function first.

Fields
Code properties are actually Python dictionaries with the following fields:
 *    - Determines that this is a code property. Can be set in the build interface by selecting Code from the type drop-down menu.
 *   string - The code. Can be set in the build interface using the Code text field.

Special names
If a code property is named after one of these names, it will automatically be used for a specific purpose. It can still be called or interpolated manually.


 * (realm property)
 * Called once when a new instance of the realm is created.


 * (realm property)
 * Called when the instance is awoken, i. e. if a player accesses it while it was asleep. Also called immediately after  at instance creation. The temporary variable   is available and contains a timestamp of when the instance went asleep, or   if it was never asleep before.


 * (realm property)
 * Called when the instance properly goes asleep. This hook is somewhat unreliable, as it is not called after a server crash, where all instances are put to sleep. Thus it may be possible that two consecutive  calls occur.


 * (realm or instance property)
 * Called when a player leaves the location the property is in, or any location in the instance if it is a realm property. The two temporary variables  and   are available, which contain the player's old and new location, respectively.   will be   if the player moved in using a portal or opened the browser page.


 * (realm or instance property)
 * Similar to, but called when a player leaves the location the property is in, or any location in the instance if it is a realm property. The two temporary variables   and   are available, which contain the player's old and new location, respectively.   will be   if the player moved out using a portal or closed the browser page.