'Open Source Scripting' group (Second Life) wiki

The AutoBlock - Building Block of GIANT buildings

Modified: 22/01/2007 19:30 by sparti.
The AutoBlock is a refactored (i.e. rewritten to be (fairly) nice code) script which sits in a prim.

This script expects to be told where to go and what shape, texture, colour, pathcut and many other parameters it should assume.

It only actually applies the set of parameters once it is told to 'go'.

There is an AutoBlock API which defines the commands to which the AutoBlock will respond.

Here is the script
// Project: autobuilder
// Script: autobuilder_block.lsl
// This is the combined 'block' which forms the building brick of all autobuilder objects
// It is based on the similar block scripts taken from the Sphere, Block Pyramid and Room builder tools

// History: // 15jan07 version 0.1 of combined block

//Simple OpenSource Licence (I am trusting you to be nice) //1. PLEASE SEND ME UPDATES TO THE CODE //2. You can do what you want with this code and object including selling it in other objects and so on. //You can sell it in closed source objects if you must, but please try to send any updates or //improvements back to me for possible inclusion in the main trunk of development. //3. You must always leave these instructions in any object created; notecard written; posting to //any electronic medium such as Forum, Email &c. of the source code & generally be nice (as //already requested!) //4. You must not claim that anyone apart from sparti Carroll wrote the original version of this software. //5. You can add and edit things below =THE LINE= but please try to keep it all making sense. //Thank you for your co-operation //sparti Carroll

integer FLAGdebug = FALSE; // If true then every block will produce debug trace - USE WITH CARE integer FLAGlabel = FALSE; // If true then every block will use llSetText to identify itself - USE WHEN PROBLEMS UNDERSTANDING WHAT'S GOING ON integer c_listen = 1766724; // first listen on this, until channel command integer c_talkto_master = 3141251; // say position e.g. back on this channel integer c_block_ALL = 44444; // this is id used when all children must obey integer n_endpoint = 99998; integer n_nomove = 6254812; // will only respond to delete after this

integer my_id; integer my_listener;

integer FLAGchanged; // set to FALSE when rezzed, then TRUE when parameters are changed, or if the 'changed' command is received helps with efficiency

// Parameters for finishing off the rez... I.e where to fly to and prim parameters when we get there vector prim_size; vector prim_pos; list prim_params; integer prim_transparency; string prim_texture; float prim_texture_scale; vector prim_colour; integer prim_physical; integer prim_repeat; // flag whether to repeat commands (used if > 80m from source block) rotation prim_rot;

// *** FUNCTIONS ***

set_position(vector targetpos) { while (llVecDist(llGetPos(),targetpos) > 0.001) llSetPos(targetpos); }

// The set_shape and set_shape2 routines record parameters for later use, when the 'go' command is issued // ... they also dump the parameters out for the owner to read if FLAGdebug is TRUE

set_shape(vector size,vector pos, vector cut,vector topsize,vector topshear,integer transparency) { // See http://secondlife.com/badgeo/wakka.php?wakka=llSetPrimitiveParams // Set shape of this primitive: width;height;pos;rot refer to this specific wall, NOT the overall collection making the room prim_size = size; prim_pos = pos; prim_params = [PRIM_TYPE, PRIM_TYPE_BOX, 0, cut, 0.0, <0.0, 0.0, 0.0>,topsize, topshear, PRIM_SIZE,size]; prim_transparency = transparency; if (FLAGdebug) { // I used llOwnerSay here because the danger of spamming everyone with loads of trace is large llOwnerSay("shape: size=" + (string)size + ",pos=" + (string)pos + ",cut=" + (string)cut + ",topsize=" + (string)topsize + ",topshear=" + (string)topshear); } FLAGchanged = TRUE; }

set_shape2(string texture,float texture_scale,vector colour,integer physical,integer repeat, rotation rot) { prim_texture = texture; prim_texture_scale = texture_scale; prim_rot = rot; prim_colour = colour; prim_physical = physical; prim_repeat = repeat; if (FLAGdebug) { llOwnerSay("shape2: txt=" + texture + ",texture_scale=" + (string)texture_scale + ",colour=" + (string)colour + ",physical=" + (string)physical + ",repeat=" + (string)repeat + ",rot=" + (string)rot); } set_position(prim_pos); FLAGchanged = TRUE; }

// do_go applies all the parameters which were stored by the set_shape and set_shape2 calls

do_go() { // call this again, for reset calls... but won't do anything normally llSetPrimitiveParams(PRIM_PHYSICS,FALSE); if (my_id == n_endpoint) llSetPrimitiveParams(PRIM_PHANTOM,TRUE); set_position(prim_pos); llSetPrimitiveParams(prim_params); llSetRot(prim_rot); // set our texture on all sides llSetTexture(prim_texture,ALL_SIDES); if (prim_texture_scale == 0.0) prim_texture_scale = 1; float x_scale = prim_size.x / prim_texture_scale; float y_scale; if (my_id != n_endpoint) { y_scale = prim_size.z / prim_texture_scale; } else { y_scale = prim_size.y / prim_texture_scale; } llScaleTexture(x_scale,y_scale,ALL_SIDES); // scale texture appropriately llSetColor(prim_colour,ALL_SIDES); // At the moment only the domino usage of WaveMaker makes use of physical blocks, but we are generalising, so leave it in. if (prim_physical == 1) { llSetPrimitiveParams(PRIM_PHYSICS,TRUE); } }

// helper function, pass messages on say2all(string command_to_pass_on) { llSay(c_listen,(string)c_block_ALL + "^" + command_to_pass_on); }

// STATES

default { on_rez(integer start_id) { // the object number i am my_id = start_id; my_listener = llListen(c_listen, "", "", ""); // we will be told what to do by parent object if (FLAGlabel) { llSetText("block " + (string)start_id,<1.0,1.0,1.0>,1.0); // remove any label from parent } else { llSetText("",<0,0,0>,0); } FLAGchanged = FALSE; llSetStatus(STATUS_DIE_AT_EDGE,TRUE); // Otherwise blocks will fly into adjacent sims - which is antisocial } // Note. The FLAGall and prim_repeat stuff allows commands to be sent further than 100m for really big structures, by relaying them listen( integer channel, string name, key id, string message ) { list cmdline = llParseString2List(message,"^",[]); integer block_id = llList2Integer(cmdline,0); integer FLAGall = block_id == c_block_ALL; if (!FLAGall && (block_id != my_id)) { return; } string cmd = llList2String(cmdline,1); if (cmd == "delete" || cmd == "deleteall") { if (FLAGall && prim_repeat) say2all(cmd); if (cmd == "deleteall" || (my_id != n_endpoint && my_id != n_nomove)) llDie(); } else if (cmd == "freeze") { if (FLAGall && prim_repeat) say2all(cmd); if (my_id != n_endpoint) llRemoveInventory(llGetScriptName()); // removing the script stops the listen as well } else if (cmd == "nomove") { if (FLAGall && prim_repeat) say2all(cmd); if (my_id != n_endpoint) my_id = n_nomove; } else if (cmd == "report") { // say position and rotation back to master; only used by endpoint block of the wavemaker vector pos = llGetPos(); rotation rot = llGetRot(); llShout(c_talkto_master,(string)pos + "^" + (string)rot); } else if (cmd == "go") { if (FLAGchanged) { if (FLAGdebug) llSay(0, "Doing GO for block " + (string)my_id); FLAGchanged = FALSE; if (FLAGall && prim_repeat) llSay(c_listen,(string)c_block_ALL + "^go"); do_go(); } } else if (cmd == "posgo") { // move immediately to position vector goto = (vector)llList2String(cmdline,2); set_position(goto); } else if (cmd == "changed") { if (FLAGall && prim_repeat) llSay(c_listen,(string)c_block_ALL + "^changed"); if (my_id != n_endpoint) FLAGchanged = 1; } else if (cmd == "shape") { // size, position, pathcut, topsize, topshear, transparency vector size = (vector)llList2String(cmdline,2); vector pos = (vector)llList2String(cmdline,3); vector cut = (vector)llList2String(cmdline,4); vector topsize = (vector)llList2String(cmdline,5); vector topshear = (vector)llList2String(cmdline,6); integer transparency = (integer)llList2String(cmdline,7); set_shape(size,pos,cut,topsize,topshear,transparency); } else if (cmd == "shape2") { // texture, texturescale, colour, physical, repeat, rotation string texture = llList2String(cmdline,2); float texture_scale = (float)llList2String(cmdline,3); vector colour = (vector)llList2String(cmdline,4); integer physical = (integer)llList2String(cmdline,5); integer repeat = (integer)llList2String(cmdline,6); rotation rot = (rotation)llList2String(cmdline,7); set_shape2(texture,texture_scale,colour,physical,repeat,rot); } } // end listen()

} // end state run_object

ScrewTurn Wiki version 1.0.11. Some of the icons created by FamFamFam.