Room Scripting

From ManorManual

Jump to: navigation, search

Room scripting can be placed in any spot that is created in a room. For the more complex script the spot order can be a concern when it comes to script linking and timing issues during script execution. This will be noted if needed. It should not be a concern for these basic examples.


To add a script to a room first open the room editor then create a new spot by selecting the "New" button on the left side of the room editor in the spot section. Then click the "Script" button on the right side to open the script editor for that spot.


Type script example 1 into the script editor, select the "Save" button in the script editor then close the script editor window. Add the text "Click Me" to the Title Box for the spot then flip the "No Move" switch to the up position. Now select the save button at the bottom right of the room editor. This will reload the room. If all went correctly the text "Hello World" will appear in your log window when you click on the spot labeled "Click Me". If not, continue reading to find out where you may have made an error.


Script Example 1

import manor

def mnr_spothit(spotID):
    print ("Hello World")


Example 1 above contains the basic anatomy of a script. The first part of the first line, import loads a python extension. In this case we need to use the manor module. Hence the first line, import manor. While there are only a certain number of modules, You can import as many of them as you need. Custom modules can also be written and imported. We will explore them later.


The second line is just a blank line. The only purpose it serves is to help make the script easier for a person to read. Some scripts can get very long and involved. A blank line can prove very useful in keeping a script organized.


The third line, def mnr_spothit(spotID): is the begin of a definition. To translate this line it would look something like this. def = Definition. mnr = Manor. spothit = If this spot is triggered execute the following script. (spotID) = The spot number.


For the forth line, print ("Hello World"), take note of the 4 blank spaces before the command print. The 4 spaces are called an indent. Indents are very important in python scripting. They help to keep the code organized so python can understand what is going on with a script. It is best to use 4 spaces for an indent. Pressing the tab key in the script editor will give you a 4 space indent. Anything that comes after a def line must have an indent before it.


The print command will print text to the log. In example 1 it will print Hello World. Notice that in the script it is incased in set of ( ), which lets python know what needs to be printed. It is also incased in " " to define it as a text string. Neither would be used for a defined variable. More about them in the next example.


The last line is a blank line. In this instance it tells python that the script has ended.



Script Example 2 - a Dress script for Avatars

import manor

def mnr_inchat(userID, chatText):
    userName = manor.getUserName(userID)
    if chatText == "newbie"
        if userName != manor.getUserName(manor.myID()):
            manor.chatText = ""
            manor.clearProps()
            manor.setProp(["89204063674A2EDF41AE6DA8BC98BFF0C487D976"])
    return chatText

When the command newbie is whispered to a target user, they will wear the prop as defined in setProp.


PHP scripting in a room.

PHP scripting must be placed in a room with the <?php and ?> tags. PHP scripting offers tremendous possibilities for Manor server side features. The MySql database and GD libs can provide dynamic room content, limited only by your creative skills.

PHP resources are easy to find and do verify which version your Manor server supports.

A basic example of creating Hello World in a spot title is shown.

NOTES:

  • The roomfile extension must be name-or-id.php in the media folder and match the conf file entry.
  • Never save a php in the room editor, all editing must be outside.

PHP Script Example 1 - Hello World

<roomdesc background=black.jpg>
  <?php
     echo "<spot id=1 poly=235,95:265,95:265,125:235,125 title=\"Hello World\"></spot>\n";
  ?>
</roomdesc>


This simple counter uses a server file to keep the count. The file must have rw permissions.

PHP Script Example 2 - Basic Hit Counter

<roomdesc background=black.jpg>
  <?php
        $file = "hitcount.txt";
	$open = fopen($file, "r");
	$size = filesize($file);
	$count = fread($open, $size);
	fclose($open);
	$count  ;
	$open = fopen($file, "w");
	fwrite($open, $count);
	fclose($open);
	echo "<spot id=1 poly=15,25:45,25:45,55:15,55 title=\"$count\"></spot>\n";
  ?>
</roomdesc>
Personal tools