Welcome Sign Script: Foundation Studies Build
This post is the first in a series that will look at the scripting of objects in both the SLENZ Foundation and Midwifery Studies builds and hopefully help those who wish to adapt, enhance or change the builds to other purposes. It looks at the Welcome sign for the Foundations Studies build (a similar one is found on the complete Midwifery Studies build) which welcomes new users to the build and presents them with a number of options for further information in the form of a notecard and links out to WikiEducator. The script is called welcome and can be found in the actual sign itself (see image). A pdf showing the complete script is available throught the following link: Welcome Script
I will attempt to colour the code syntax as it is seen in Second Life to facilitate identification and identify line numbers where appropriate. It would be greatly appreciated that if any errors are discovered in this and/or subsequent posts or any questions are raised, readers comment here so that I can address them promptly and other readers can benefit from the discussion.
The Variables: Lines 0 to 6
integer sensorRange = 30; float sensorFrequency = 10.0; integer listenChannel = 1000; // Delay for clearing out latestVisitors list (2 hours in seconds) float welcomeBackDelay = 7200.0; list visitors; list latestVisitors;
The integer sensorRange is the distance in metres from the sign that avatars are detected for automatic delivery of the welcome through a dialog box. The float sensorFrequency is the time in seconds that the area is scanned for avatars. The integer listenChannel is the communications channel used. The float welcomeBackDelay is used in conjunction with the list latestVisitors to ensure that visitors to the build are not pestered by the welcome each time the area is scanned. The list visitors holds the names of up to 80 visitors so that on revisiting the site newer visitors will not automatically be delivered the welcome notice but instead told how to access the information (by clicking on the sign).
state_entry(): Lines 10 to 15
llSensorRepeat("","",AGENT,sensorRange,2*PI,sensorFrequency); llSetTimerEvent(welcomeBackDelay); llListen(listenChannel, "", NULL_KEY, "");
Set up in the state_entry event are the sensor which scans for avatars, the timer event for managing the visitor lists and the listener which handles button selections from the dialog box delivered to visitors.
sensor(integer total_number): Lines 17 to 42
The sensor event handles delivery of information to visitors picked up by the llSensorRepeat function. Each detected visitor is first checked against the visitors list as follows:
string userName = llDetectedName(i); list nameCheck = [userName]; integer test1 = llListFindList(visitors, nameCheck);
If the visitor is not on the list they are delivered a dialog box with button choices for selecting information on the build and added to both the visitors list and the latestVisitors list.
if(test1 == -1)
{
llDialog(llDetectedKey(i), "Welcome " + userName + " to the Skill Mastery Hyperdome. Note: Click on the Welcome sign to re-open this dialog/n** Options for Information **/n1. Notecard: Read and save to your SL Inventory/n2. Resources: View teacher resources on WikiEducator/n3. Notes: View student notes on WikiEducator", ["Notecard", "Resources", "Notes"], listenChannel);
visitors = visitors + userName;
latestVisitors = latestVisitors + userName;
}
If they are on the visitors list (i.e they were one of the last 80 visitors) they are then checked against the latestVisitors list. If they are not on the latestVisitors list they are delivered an instant message in chat informing them how to access the initial dialog box.
else { integer test2 = llListFindList(latestVisitors, nameCheck); if(test2 == -1) { llInstantMessage(llDetectedKey(i), "Welcome back to the Skill Mastery Hyperdome " + userName + ". To review general information on this build please click on the Welcome sign."); latestVisitors = latestVisitors + userName; } }
touch_start(integer num_detected): Lines 44 to 47
The touch_start event allows visitors to touch the Welcome sign and receive the initial dialog box for information review purposes. They are informed of this ability in the original dialog box and when they revisit the build and are still on the visitors list.
listen(integer channel, string name, key id, string message): Lines 49 to 71
The listen event receives the button name from the dialog box on the selected communications channel and delivers the appropriate response depending on which button is selected. Lines 63 to 70 were inserted as a list testing solution to see that the list visitors was accurately receiving data.
else if(message == "say list" && id == llGetOwner()) { integer i; for (i=0; i<llGetListLength(visitors); i++) { llOwnerSay(llList2String(visitors, i)); } }
These lines enable the owner of the build to type /1000 say list into the main chat window and the current items in the list visitors will be displayed (to the owner only).
timer(): Lines 73 t0 84
// Remove oldest half of latest visitors list integer halfLen = llGetListLength(latestVisitors)/2; latestVisitors = llDeleteSubList(latestVisitors, 0, halfLen); // If visitors list over 80 remove oldest visitors from list if(llGetListLength(visitors) > 80) { integer over80 = llGetListLength(visitors) - 60; visitors = llDeleteSubList(visitors, 0, over80); }
The timer event runs every 2 hours and is used to keep the lists to a manageable size while enabling those who have recently visited the build to not be bothered by repeated notices from the welcome sign. First the event removes the oldest half of the latestVisitors list, then it checks the visitors list and if the list count is greater than 80 it will remove the oldest visitors from the list leaving the latest 60 or thereabouts. This method ensures that the character count for a list does not stretch the script memory and that the latest visitors are always retained in the list.
I hope that this explains the welcome script adequately and is of use in adapting the script for other purposes. As mentioned above any questions should be addressed to this blog as comments so that all users can benefit from the discussion.
Isa Goodman/Aaron Griffiths

