Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Discussion: Mazes Built using Walls

Moose Pegler
Registered User
Join date: 22 Apr 2006
Posts: 33
11-08-2006 16:59
Here's a little pair of scripts that let you bring into SL mazes built with programs outside SL such as Daedalus (http://www.astrolog.org/labyrnth/daedalus.htm).

A maze is thought of as being a collection of horizontal and vertical walls. Each wall in the maze is represented as a positive integer, hhhvvvlll, where <hhh, vvv> is the coordinate of an end of the wall and lll is the length of the wall measured from this point.

Put the Wall script into a 1x1xk cuboid ("rectangular box";). The height of this cuboid, k, determines the height of the walls in the maze. Put this cuboid into the Inventory of a second prim that contains the MazeBuilder script. Make sure that the name of the cuboid containing the Wall script is Wall. MazeBuilder will rez this cuboid once for each wall in the maze.

The MazeBuilder script contains two lists of integers, xwalls and ywalls, that define the walls of the maze. The walls in xwalls are the horizontal walls in the maze and the walls in ywalls are the vertical walls in the maze.

Enjoy!

Cheers, Moose

Here's the Wall script. It builds one wall when it is rezzed. The parameter it is passed is the hhhvvvlll integer described above. It says where the wall should be and how long it should be. If this integer is positive then it is a horizontal wall and if it is negative it is a vertical wall. Adjust scale and thickness to suit your tastes and situation.
CODE

default
{
state_entry()
{
}

on_rez(integer wall)
{
float scale = 0.1;
float thickness = 0.05;
integer ypos;
integer xpos;
integer leng;
float yposition;
float xposition;
float length;
vector location;
vector size;

size = llGetScale();

ypos = llAbs(wall) / 1000000;
xpos = (llAbs(wall) - (ypos * 1000000)) / 1000;
leng = llAbs(wall) - (ypos * 1000000) - (xpos * 1000);

yposition = scale * ypos;
xposition = scale * xpos;
length = scale * leng;

if (wall > 0) // wall > 0 ==> xwall
{
llSetPrimitiveParams([PRIM_SIZE, <thickness, length, size.z>]);

location = llGetPos() + <xposition + thickness / 2, yposition + length / 2 + thickness / 2, 0>;

while(llVecDist(llGetPos(), location) > 0.001) llSetPos(location);
}
else if(wall < 0) // wall < 0 ==> ywall
{
llSetPrimitiveParams([PRIM_SIZE, <length, thickness, size.z>]);

location = llGetPos() + <xposition + length / 2 + thickness / 2, yposition + thickness / 2, 0>;

while (llVecDist(llGetPos(), location) > 0.001) llSetPos(location);
}

}
}


Here's the MazeBuilder script. It just walks down the xwalls and ywalls lists and rezzes the cuboid containing the Wall script with each list entry taking care to negate the entries on the ywalls list so they will be orthogonal to the entries on the xwalls list.

CODE
// A Small Maze
list xwalls = [83, 83000081, 164083, 83164081, 41082041, 82041041, 123123041];
list ywalls = [82, 123041, 41000041, 41082041, 82041062, 82103061, 123041041, 164000041, 164082082];


default
{
state_entry()
{
llSetText("", <1,1,1>, 1.0);
llListen(0, "", llGetOwner(), "");
}

on_rez(integer start_param)
{
llResetScript();
}

listen(integer channel, string name, key id, string message)
{
string command = llToLower(message);

if (command == "maze reset")
{
llResetScript();
}
else if (command == "maze build")
{
integer i;
integer wall;
integer numberofwalls;

// Do the X walls
numberofwalls = llGetListLength(xwalls);
for(i = 0; i < numberofwalls; i++)
{
wall = llList2Integer(xwalls, i);
llRezObject("Wall", llGetPos(), ZERO_VECTOR, ZERO_ROTATION, wall);
}

// Do the Y walls
numberofwalls = llGetListLength(ywalls);
for(i = 0; i < numberofwalls; i++)
{
wall = -llList2Integer(ywalls, i);
llRezObject("Wall", llGetPos(), ZERO_VECTOR, ZERO_ROTATION, wall);
}
}
}

on_rez(integer start_param)
{
llResetScript();
}
}
Nada Epoch
The Librarian
Join date: 4 Nov 2002
Posts: 1,423
Original Thread
11-09-2006 22:03
/15/8c/147943/1.html
_____________________
i've got nothing. ;)