Planar Tile Generator

From Second Life Wiki
Jump to: navigation, search

Created by Kira Komarov.

Tile-Related Tree

+-------------------------+ | Planar Tile Generator | +------------+------------+ | +---------------------+---------------------------+-------------------------+ | | | | +------------+-------------+ +----------------+ +-------------+-------------+ +--------+-------+ | Spatial Tile Generator | | Holo Display | | Planar Fibbonacci Tiles | | Snake Game | +--------------------------+ +----------------+ +---------------------------+ +----------------+

Introduction

The following script generates tiles by traversing a planar space with the dimensions: <math> \verb+BOARD_WIDTH+ \times \verb+BOARD_HEIGHT+ </math> by rezzing an object, with the scale OBJECT_SCALE, from the primitive's inventory with the time-delay SPEED between each rez.

The expected result should be a two-dimensional board with tiles:


           +z|
             |
             +-------------+
             |_|_|_|_|_|_|_|
 BOARD_HEIGHT|_|_|_|_|_|_|_|
             |_|_|_|_|_|_|_|
             +-------------+-->
               BOARD_WIDTH   +x

Notes

This script should function properly in an OpenSim environment. Initially it had been designed to use a loop instead of a timer. However, due to some not well-founded choices, event handlers in OpenSim are killed by default after a certain time period. They should not. Handers should not go away. Just the event that triggers the handler does, after a time period.

Setup

In order to use this script:

  1. Create a primitive.
  2. Drop another primitive that you wish to rez at every stop inside the primitive from Step 1.
  3. Copy and configure the speed with attention to the configuration section.
  4. Touch the primitive from Step 1 to start rezzing the object inside it from Step 2.

You may abort the rezzing procedure by touching the object again.

Code

//////////////////////////////////////////////////////////
// [K] Komarov - 2011, License: GPLv3                   //
// Please see: http://www.gnu.org/licenses/gpl.html     //
// for legal details, rights of fair usage and          //
// the disclaimer and warranty conditions.              //
//////////////////////////////////////////////////////////
 
//////////////////////////////////////////////////////////
//                   CONFIGURATION                      //
//////////////////////////////////////////////////////////
// The height of the generated board.
integer BOARD_HEIGHT = 5;
// The width of the generated board.
integer BOARD_WIDTH = 5;
// The delay between rezzing the object in the primitive.
float SPEED = 0.5;
// Set this to the scale of the primitive inside the object.
vector OBJECT_SCALE = <0.5,0.5,0.5>;
 
//////////////////////////////////////////////////////////
//                      INTERNALS                       //
//////////////////////////////////////////////////////////
integer runner = 1;
integer gitra = 0;
integer gitrb = 0;
vector tilePos = ZERO_VECTOR;
 
default {
 
    state_entry() {
        llSay(0, "Click the glowing prim to deploy more tiles.");
    }
 
    touch_start(integer total_number) {
        // Sanity.
        if(BOARD_HEIGHT*BOARD_WIDTH < 1) {
            llSay(DEBUG_CHANNEL, "Sorry, the width and height have to be larger than zero. Aborting.");
            return;
        }
        if(llGetInventoryName(INVENTORY_OBJECT, 0) == "") {
            llSay(DEBUG_CHANNEL, "Sorry, I could not find an object in the inventory to rez. Aborting.");
            return;
        }
        tilePos = llGetPos();
        state deploy;
    }
}
 
state deploy {
 
    state_entry() {
        llSay(0, "Please wait, deploying prims. Touch To stop...");
        llSetTimerEvent(SPEED);
    }
    touch_start(integer num) {
        llSetTimerEvent(0);
        state default;
    }
    timer() {
        llSetTimerEvent(0);
        if(runner > BOARD_WIDTH*BOARD_HEIGHT) {
            state default;
            return;
        }
        if(gitrb < BOARD_HEIGHT) {
            if(gitra < BOARD_WIDTH-1) {
                llRezObject(llGetInventoryName(INVENTORY_OBJECT,0),tilePos,ZERO_VECTOR,ZERO_ROTATION,++runner);
                tilePos.x += OBJECT_SCALE.x;
                llSetPos(tilePos);
                ++gitra;
                llSetTimerEvent(SPEED);
                return;
            }
            llRezObject(llGetInventoryName(INVENTORY_OBJECT,0),tilePos,ZERO_VECTOR,ZERO_ROTATION,++runner);
            tilePos.z += OBJECT_SCALE.z;
            llSetPos(tilePos);
            OBJECT_SCALE.x *= -1;
            ++gitrb;
            gitra = 0;
            llSetTimerEvent(SPEED);
            return;
        }
    }
}