Generalising Tile Count

Using planar tile generator and altering it for our needs, we can now generate as many tiles needed in order to simulate the electrical activity of a beating heart. We have to change planar tile generator so that it passes an integer containing the matrix coordinates from above. In order to do that, we use a simple bit-shift trick:

`++runner_x << 16 | runner_y`

which will push runner_x to the left of the mantissa and then add the second variable. This can be used to pass two variables, in this case, the coordinates of the rezzer to the tile that it will rez at its current location.

```///////////////////////////////////////////////////////////////////////////
//  Copyright (C) Wizardry and Steamworks 2011 - License: GNU GPLv3      //
//  rights of fair usage, 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;
// Set this to the scale of the primitive inside the object.
vector OBJECT_SCALE = <0.1,0.1,0.1>;

//////////////////////////////////////////////////////////
//                      INTERNALS                       //
//////////////////////////////////////////////////////////
integer runner_x = 0;
integer runner_y = 1;
integer gitra = 0;
integer gitrb = 0;
vector tilePos = ZERO_VECTOR;
integer comChannel = 0;

default {

touch_start(integer num) {
comChannel = (((integer)("0x"+(llGetSubString((string)llGetOwner(),-8,-1))) + (integer)("0x"+(llGetSubString((string)llGetKey(),-8,-1)))) & 0x3FFFFFFF) ^ 0xBFFFFFFF;
llListen(comChannel, "", "", "");
llListen(comChannel+1, "", "", "");
llListen(comChannel+2, "", "", "");
llDialog(llDetectedKey(0), "\nThe current settings are:\n\nHeight: " + (string)BOARD_HEIGHT + "\nWidth: " + (string)BOARD_WIDTH + "\n\nPlease select from the following options below.", [ "Height", "Width", "Deploy" ], comChannel);
}

listen(integer channel, string name, key id, string message) {
if(message == "Deploy") {
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;
}
if(message == "Height") {
llTextBox(id, "\nPlease specify the height of the board:\n", channel+1);
return;
}
if(message == "Width") {
llTextBox(id, "\nPlease specify the width of the board:\n", channel+2);
return;
}
if(channel == comChannel+1 && (integer)message > 1) {
BOARD_HEIGHT = (integer)message;
return;
}
if(channel == comChannel+2 && (integer)message > 1) {
BOARD_WIDTH = (integer)message;
}
llDialog(id, "\nThe current settings are:\n\nHeight: " + (string)BOARD_HEIGHT + "\nWidth: " + (string)BOARD_WIDTH + "\n\nPlease select from the following options below.", [ "Height", "Width", "Deploy" ], comChannel);
}
}

state deploy {

state_entry() {
llSay(0, "Please wait, deploying prims. Touch To stop...");
llSetTimerEvent(0.5);
}
touch_start(integer num) {
llSetTimerEvent(0);
llResetScript();
}
timer() {
llSetTimerEvent(0);
if(runner_x > BOARD_WIDTH*BOARD_HEIGHT) {
llResetScript();
return;
}
if(gitrb < BOARD_HEIGHT) {
if(gitra < BOARD_WIDTH-1) {
llRezObject(llGetInventoryName(INVENTORY_OBJECT,0),tilePos,ZERO_VECTOR,ZERO_ROTATION,++runner_x << 16 | runner_y);
tilePos.x += OBJECT_SCALE.x;
llSetPos(tilePos);
++gitra;
llSetTimerEvent(0.5);
return;
}
llRezObject(llGetInventoryName(INVENTORY_OBJECT,0),tilePos,ZERO_VECTOR,ZERO_ROTATION,++runner_x << 16 | runner_y);
tilePos.z += OBJECT_SCALE.z;
llSetPos(<tilePos.x - OBJECT_SCALE.x*BOARD_WIDTH+OBJECT_SCALE.x,tilePos.y,tilePos.z>);
tilePos = <tilePos.x - OBJECT_SCALE.x*BOARD_WIDTH+OBJECT_SCALE.x,tilePos.y,tilePos.z>;
++runner_y;
runner_x=0;
++gitrb;
gitra = 0;
llSetTimerEvent(0.5);
return;
}
}
}```