Assembling the Holodeck

In this series to date I have talked about the two main functions used to rez objects from another object’s inventory, setting the rotations of those rezzed objects and passing an integer from the rezzer to the rezzed objects. As well as those main topics I have also looked at how a user-defined function is created, walked through a simple timer script for deleting a rezzed object and given out a script and a utility for securing the quaternion rotation of an object.

Now it’s time to gather all of the above into a functioning holodeck by adding the final requirement; the ability to rez from a selection of objects. To enable this a dialog box of scene choices will be added to the touch_start event that has been employed in the scripts to date, that event by itself limited to performing the same function over and over. This addition is the real strength of a holodeck; being able to rez individual scenes (i.e. linked objects) from a selection.

The function used to create the dialog box, with choice buttons, is llDialog. It has the following parameters:

(key avatar, string message, list buttons, integer channel)

The dialog box is displayed to the avatar designated by key avatar. This key is selected using the llDetectedKey function which is called from within detection events such as touch_start. The dialog box presents text, string message, and a number of button choices defined by the labels list buttons. When a button is clicked on, the avatar says the text of the button label on integer channel.

As well as enabling the dialog box the script will cover the functionality for replacing one scene with another and for clearing the scenes completely.

For the demonstration example I will be using three scenes from the SLENZ Project. These scenes are part of the Foundation Studies build, in that build the scenes being used by the students to practice interview skills in different environments. They are as follows:


Each scene is comprised of a set of linked objects with the root prim offset and transparent. This will allow the rezzing of the scene at the XY position of the rezzer using llRezAtRoot, but will set the visual scene (what you see) slightly away from the rezzer itself.

Each scene has inserted into the root prim a script with two main functions. On rezzing it will set a timer running, the time interval being feed to it by the llRezAtRoot function’s final parameter. As each time interval passes the timer event will trigger and scan a distance of 20 metres around the scene using the function llSensor. If no avatars are present the no_sensor event will be triggered sending a message to the holodeck console to reset itself and deleting the current scene. The script will also listen for a message from the holodeck console to delete itself using the function llListen, if a user actions rezzing another scene or clearing the current scene.

The llSensor function has the following parameters:

(string name, key id, integer type, float range, float arc)

The sensor used will disregard name and id and scan instead for type, the designated type being avatars. It will scan a spherical area 20 metres around the scene root prim.

The llListen function has the following parameters:

(integer channel, string name, key id, string message)

This function will listen on a specific channel for a particular message from the holodeck console. If it receives the message it will trigger the listen event.

The script is as follows:

default
{
state_entry()
{
llListen(101, “Holodeck Console”, NULL_KEY, “Delete”); // Listens on channel 101 for the message string Delete from the object Holodeck Console
}

listen(integer channel, string name, key id, string message)
{
llDie(); // Self deletes
}

on_rez(integer start_param)
{
llSetTimerEvent(start_param + 0.0);
}

timer()
{
llSensor(“”, NULL_KEY, AGENT_BY_LEGACY_NAME, 20.0, PI); // Scans a spherical area with a range of 20m for avatars
}

no_sensor()
{
llSay(102, “Reset”); // Says the message string Reset on channel 102
llDie(); // Self deletes
}
}

The script for the holodeck console starts with the initiation of three global variables; string floatTxtStr, the basic floating text for the console; string menuStr, the main text for the dialog box and list menuButtons, the button labels for the dialog box.

string floatTxtStr = “Touch for Holodeck Menu”;
string menuStr = “Click on a button to choose a scene\n \nScene One: Motorworx Services Office\nScene Two: Nursing Centre Office\nScene Three: Community Policing Office\nClear Scene: Remove current scene”;
list menuButtons = [“Scene One”, “Scene Two”, “Scene Three”, “Clear Scene”];

Note: The text \n is used to create a line break.

Next comes a user-defined function, rezScene, used here because rezzing each scene requires repetitive code. First the llSay function delivers the Delete message on channel 101 to remove the current scene. The llRezAtRoot function then rezzes the scene selected from the menu (i.e. sceneName) at the position of the holodeck console minus 1.5m on the Z axis, with no velocity nor rotation but with a final parameter of 1800. This represents 30 minutes in seconds, the time interval for the timer discussed above. Finally the floating text is changed to indicate the current scene. The image below shows how this text is displayed for Scene One.

As no value is returned from this function, i.e. it just runs the internal code, there is no need to define a return type.

rezScene(string sceneName)
{
llSay(101, “Delete”);
llRezAtRoot(sceneName, llGetPos() – <0.0, 0.0, 1.5>, <0.0, 0.0, 0.0>, <0.0, 0.0, 0.0, 1.0>, 1800);
llSetText(“Current Scene:\n” + sceneName + “\n \n” + floatTxtStr, <1.0, 1.0, 0.8>, 1.0);
}

Then comes the default state of the script starting with the state_entry event which sets the initial floating text for the console.

Next is the touch_start event which sets up a listener (llListen) for the label names sent when a button is clicked on and for the Reset message from a timed-out scene. This event also triggers the display of the dialog box (the Holodeck Console Menu) displayed as shown below.

Finally the listen event, triggered by receiving the text of a button label when a button is clicked on or the Reset message is sent from a timed-out scene.

Each message is handled withIF statements that check if the message meets a certain condition, e.g. is equivalent to “Scene One”. If it meets the condition the code block is run ELSE it moves to the next IF statement. If it is a selected scene the user-defined rezScene function runs. If it is the Reset message the holodeck script uses the llResetScript function to reset itself, essentially running the state_entry event which will set the floating text back to the global variable floatTxtStr. If the message is Clear Scene the Delete message is sent on channel 101 to the current scene and the script then resets.

The llResetScript function also removes the listener, so that this isn’t running needlessly when not required.

default
{
state_entry()
{
llSetText(floatTxtStr, <1.0, 1.0, 0.8>, 1.0);
}

touch_start(integer total_number)
{
llListen(102, “”, NULL_KEY, “”);
llDialog(llDetectedKey(0), menuStr, menuButtons, 102);
}

listen(integer channel, string name, key id, string message)
{
if(message == “Scene One”)
{
rezScene(“Motorworx Services Office”);
}
else if(message == “Scene Two”)
{
rezScene(“Nursing Centre Office”);
}
else if(message == “Scene Three”)
{
rezScene(“Community Policing Office”);
}
else if(message == “Reset”)
{
llResetScript();
}
else if(message == “Clear Scene”)
{
llSay(101, “Delete”);
llResetScript();
}
}
}

Many variations of the scripts used could be worked into other holodeck versions; llRezObject could be used instead of llRezAtRoot, different methods of changing the scenes could be incorporated, if the positioning or rotation of each scene is different then extra parameters could be added to the rezScene user-defined function or the rezzing function could be written out in full inside each IF statement. I may go into some of the variations in a later post though I do think my next post will have a change of subject. Right now I’m all holodecked out.

I know what I have written to date is not the be all and end all of a holodeck system but I do hope it has shone some light on the subject and is sufficient to give those wishing to assemble their own a head start. The scripts provided are also suitable for an OpenSim environment.

Advertisements

2 thoughts on “Assembling the Holodeck

  1. Pingback: Setting a Rezzed Object Timer « F/Xual Education Services

  2. Pingback: Damn you LSL ! | Matthew Green Project 701

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s