Cam,
I played around with the scripts night before last, and came across many of the same issues.
As for keeping track of what piece is where, this could easily be done with a list. In the zero based setup you have, (xPos + 1) * (yPos + 1) would give you squares 1 thru 64. I created a list using two for loops hooked into your x and y values to generate the 64 item list, giving a value to each square along with the named piece that existed in that square. I was playing with chess in mind. As I did this, the only issue I encountered, and why I stopped for the night, was because I hadn't coded specific link numbers. I've found inconsistancy when obtaining and sending the link number on each llMessageLinked call, so I sent the number from each piece on state_entry, and saved them to a variable. Then I can refer to the piece in question simply by the variable. Lots of 'if' statements.
As for moving multiple prims, wouldn't it just be easier to grow the 'King', making the piece taller, and doubling the texture along the prim side face to indicate two. This cuts down on programming at least.
I had thought about adding the extra spaces for moving pieces off the board, but hadn't pursued anything yet.
Would like to see about having the pieces taken into the boards inventory, and being placed on rez.
Here's the code as it stands right now. How you can find something useful.
Game Board
Code:
//Simple chess board script V0.3
//by Cam Chevalier
//09-June-2012
integer width = 8;
integer height = 8;
string strChildName;
integer intChildNum;
list listBoard;
default
{
state_entry()
{
integer idxBoard_XPos;
integer idxBoard_YPos;
for (idxBoard_XPos = 1; idxBoard_XPos <= 8; idxBoard_XPos = idxBoard_XPos + 1)
{
for (idxBoard_YPos = 1; idxBoard_YPos <= 8; idxBoard_YPos = idxBoard_YPos + 1)
{
if (idxBoard_XPos == 1)
{
if (idxBoard_YPos == 1)
{
listBoard = llListInsertList(listBoard, [(string)idxBoard_XPos + "|" + (string)idxBoard_YPos + "|" + "White_RRook"], idxBoard_XPos * idxBoard_YPos);
}
if (idxBoard_YPos == 2)
{
listBoard = llListInsertList(listBoard, [(string)idxBoard_XPos + "|" + (string)idxBoard_YPos + "|" + "White_RKnight"], idxBoard_XPos * idxBoard_YPos);
}
if (idxBoard_YPos == 3)
{
listBoard = llListInsertList(listBoard, [(string)idxBoard_XPos + "|" + (string)idxBoard_YPos + "|" + "White_RBishop"], idxBoard_XPos * idxBoard_YPos);
}
if (idxBoard_YPos == 4)
{
listBoard = llListInsertList(listBoard, [(string)idxBoard_XPos + "|" + (string)idxBoard_YPos + "|" + "White_King"], idxBoard_XPos * idxBoard_YPos);
}
if (idxBoard_YPos == 5)
{
listBoard = llListInsertList(listBoard, [(string)idxBoard_XPos + "|" + (string)idxBoard_YPos + "|" + "White_Queen"], idxBoard_XPos * idxBoard_YPos);
}
if (idxBoard_YPos == 6)
{
listBoard = llListInsertList(listBoard, [(string)idxBoard_XPos + "|" + (string)idxBoard_YPos + "|" + "White_LBishop"], idxBoard_XPos * idxBoard_YPos);
}
if (idxBoard_YPos == 7)
{
listBoard = llListInsertList(listBoard, [(string)idxBoard_XPos + "|" + (string)idxBoard_YPos + "|" + "White_LKnight"], idxBoard_XPos * idxBoard_YPos);
}
if (idxBoard_YPos == 8)
{
listBoard = llListInsertList(listBoard, [(string)idxBoard_XPos + "|" + (string)idxBoard_YPos + "|" + "White_LRook"], idxBoard_XPos * idxBoard_YPos);
}
}
else if (idxBoard_XPos == 2)
{
if (idxBoard_YPos == 1)
{
listBoard = llListInsertList(listBoard, [(string)idxBoard_XPos + "|" + (string)idxBoard_YPos + "|" + "White_RPawn4"], idxBoard_XPos * idxBoard_YPos);
}
if (idxBoard_YPos == 2)
{
listBoard = llListInsertList(listBoard, [(string)idxBoard_XPos + "|" + (string)idxBoard_YPos + "|" + "White_RPawn3"], idxBoard_XPos * idxBoard_YPos);
}
if (idxBoard_YPos == 3)
{
listBoard = llListInsertList(listBoard, [(string)idxBoard_XPos + "|" + (string)idxBoard_YPos + "|" + "White_RPawn2"], idxBoard_XPos * idxBoard_YPos);
}
if (idxBoard_YPos == 4)
{
listBoard = llListInsertList(listBoard, [(string)idxBoard_XPos + "|" + (string)idxBoard_YPos + "|" + "White_RPawn1"], idxBoard_XPos * idxBoard_YPos);
}
if (idxBoard_YPos == 5)
{
listBoard = llListInsertList(listBoard, [(string)idxBoard_XPos + "|" + (string)idxBoard_YPos + "|" + "White_LPawn1"], idxBoard_XPos * idxBoard_YPos);
}
if (idxBoard_YPos == 6)
{
listBoard = llListInsertList(listBoard, [(string)idxBoard_XPos + "|" + (string)idxBoard_YPos + "|" + "White_LPawn2"], idxBoard_XPos * idxBoard_YPos);
}
if (idxBoard_YPos == 7)
{
listBoard = llListInsertList(listBoard, [(string)idxBoard_XPos + "|" + (string)idxBoard_YPos + "|" + "White_LPawn3"], idxBoard_XPos * idxBoard_YPos);
}
if (idxBoard_YPos == 8)
{
listBoard = llListInsertList(listBoard, [(string)idxBoard_XPos + "|" + (string)idxBoard_YPos + "|" + "White_LPawn4"], idxBoard_XPos * idxBoard_YPos);
}
}
else if (idxBoard_XPos == 7)
{
if (idxBoard_YPos == 1)
{
listBoard = llListInsertList(listBoard, [(string)idxBoard_XPos + "|" + (string)idxBoard_YPos + "|" + "Black_RRook"], idxBoard_XPos * idxBoard_YPos);
}
if (idxBoard_YPos == 2)
{
listBoard = llListInsertList(listBoard, [(string)idxBoard_XPos + "|" + (string)idxBoard_YPos + "|" + "Black_RKnight"], idxBoard_XPos * idxBoard_YPos);
}
if (idxBoard_YPos == 3)
{
listBoard = llListInsertList(listBoard, [(string)idxBoard_XPos + "|" + (string)idxBoard_YPos + "|" + "Black_RBishop"], idxBoard_XPos * idxBoard_YPos);
}
if (idxBoard_YPos == 4)
{
listBoard = llListInsertList(listBoard, [(string)idxBoard_XPos + "|" + (string)idxBoard_YPos + "|" + "Black_King"], idxBoard_XPos * idxBoard_YPos);
}
if (idxBoard_YPos == 5)
{
listBoard = llListInsertList(listBoard, [(string)idxBoard_XPos + "|" + (string)idxBoard_YPos + "|" + "Black_Queen"], idxBoard_XPos * idxBoard_YPos);
}
if (idxBoard_YPos == 6)
{
listBoard = llListInsertList(listBoard, [(string)idxBoard_XPos + "|" + (string)idxBoard_YPos + "|" + "Black_LBishop"], idxBoard_XPos * idxBoard_YPos);
}
if (idxBoard_YPos == 7)
{
listBoard = llListInsertList(listBoard, [(string)idxBoard_XPos + "|" + (string)idxBoard_YPos + "|" + "Black_LKnight"], idxBoard_XPos * idxBoard_YPos);
}
if (idxBoard_YPos == 8)
{
listBoard = llListInsertList(listBoard, [(string)idxBoard_XPos + "|" + (string)idxBoard_YPos + "|" + "Black_LRook"], idxBoard_XPos * idxBoard_YPos);
}
}
else if (idxBoard_XPos == 8)
{
if (idxBoard_YPos == 1)
{
listBoard = llListInsertList(listBoard, [(string)idxBoard_XPos + "|" + (string)idxBoard_YPos + "|" + "Black_RPawn4"], idxBoard_XPos * idxBoard_YPos);
}
if (idxBoard_YPos == 2)
{
listBoard = llListInsertList(listBoard, [(string)idxBoard_XPos + "|" + (string)idxBoard_YPos + "|" + "Black_RPawn3"], idxBoard_XPos * idxBoard_YPos);
}
if (idxBoard_YPos == 3)
{
listBoard = llListInsertList(listBoard, [(string)idxBoard_XPos + "|" + (string)idxBoard_YPos + "|" + "Black_RPawn2"], idxBoard_XPos * idxBoard_YPos);
}
if (idxBoard_YPos == 4)
{
listBoard = llListInsertList(listBoard, [(string)idxBoard_XPos + "|" + (string)idxBoard_YPos + "|" + "Black_RPawn1"], idxBoard_XPos * idxBoard_YPos);
}
if (idxBoard_YPos == 5)
{
listBoard = llListInsertList(listBoard, [(string)idxBoard_XPos + "|" + (string)idxBoard_YPos + "|" + "Black_LPawn1"], idxBoard_XPos * idxBoard_YPos);
}
if (idxBoard_YPos == 6)
{
listBoard = llListInsertList(listBoard, [(string)idxBoard_XPos + "|" + (string)idxBoard_YPos + "|" + "Black_LPawn2"], idxBoard_XPos * idxBoard_YPos);
}
if (idxBoard_YPos == 7)
{
listBoard = llListInsertList(listBoard, [(string)idxBoard_XPos + "|" + (string)idxBoard_YPos + "|" + "Black_LPawn3"], idxBoard_XPos * idxBoard_YPos);
}
if (idxBoard_YPos == 8)
{
listBoard = llListInsertList(listBoard, [(string)idxBoard_XPos + "|" + (string)idxBoard_YPos + "|" + "Black_LPawn4"], idxBoard_XPos * idxBoard_YPos);
}
}
else
{
listBoard = llListInsertList(listBoard, [(string)idxBoard_XPos + "|" + (string)idxBoard_YPos + "|" + "EMPTY"], idxBoard_XPos * idxBoard_YPos);
}
}
}
}
link_message(integer sender_num, integer num, string str, key id)
{
strChildName = str;
intChildNum = num;
}
touch_start(integer b)
{
integer idxBoard_XPos;
integer idxBoard_YPos;
vector st = llDetectedTouchST(0);
integer x = llFloor(st.x * width);
integer y = llFloor(st.y * height);
integer xPos = x + 1;
integer yPos = y + 1;
integer idxBoardPos = xPos * yPos;
vector size = llGetScale();
float wFactor = size.x/8;
float wstep = wFactor/2;
float hFactor = size.y/8;
float hstep = hFactor/2;
float tFactor; //=size.z;
vector finalpos;
vector placex;
vector placexy;
if (x == 0)
{
placex = ( - <wstep + wFactor * 3, 0, 0>);
}
if (x == 1)
{
placex = ( - <wstep + wFactor * 2, 0, 0>);
}
if (x == 2)
{
placex = ( - <wstep + wFactor, 0, 0>);
}
if (x == 3)
{
placex = ( - <wstep, 0, 0>);
}
if (x == 4)
{
placex = ( <wstep, 0, 0>);
}
if (x == 5)
{
placex = ( <wstep + wFactor,0,0>);
}
if (x == 6)
{
placex = ( <wstep + wFactor*2,0,0>);
}
if (x == 7)
{
placex = ( <wstep + wFactor*3,0,0>);
}
if (y == 0)
{
placexy = (placex - <0, hstep + hFactor * 3, 0>);
}
if (y == 1)
{
placexy = (placex - <0, hstep + hFactor * 2, 0>);
}
if (y == 2)
{
placexy = (placex - <0, hstep + hFactor, 0>);
}
if (y == 3)
{
placexy = (placex - <0, hstep, 0>);
}
if (y == 4)
{
placexy = (placex + <0, hstep, 0>);
}
if (y == 5)
{
placexy = (placex + <0, hstep + hFactor, 0>);
}
if (y == 6)
{
placexy = (placex + <0, hstep + hFactor * 2, 0>);
}
if (y == 7)
{
placexy = (placex + <0, hstep + hFactor * 3, 0>);
}
if (strChildName == "White_King")
{
tFactor = size.z + 0.65;
}
if (strChildName == "White_Queen")
{
tFactor = size.z + 0.5;
}
if (strChildName == "White_LBishop")
{
tFactor = size.z + 0.5;
}
if (strChildName == "White_RBishop")
{
tFactor = size.z + 0.5;
}
if (strChildName == "White_LKnight")
{
tFactor = size.z + 0.05;
}
if (strChildName == "White_RKnight")
{
tFactor = size.z + 0.05;
}
if (strChildName == "White_LRook")
{
tFactor = size.z + 0.4;
}
if (strChildName == "White_RRook")
{
tFactor = size.z + 0.4;
}
if (strChildName == "White_LPawn1")
{
tFactor = size.z + 0.05;
}
if (strChildName == "White_RPawn1")
{
tFactor = size.z + 0.05;
}
if (strChildName == "White_LPawn2")
{
tFactor = size.z + 0.05;
}
if (strChildName == "White_RPawn2")
{
tFactor = size.z + 0.05;
}
if (strChildName == "White_LPawn3")
{
tFactor = size.z + 0.05;
}
if (strChildName == "White_RPawn3")
{
tFactor = size.z + 0.05;
}
if (strChildName == "White_LPawn4")
{
tFactor = size.z + 0.05;
}
if (strChildName == "White_RPawn4")
{
tFactor = size.z + 0.05;
}
if (strChildName == "Black_King")
{
tFactor = size.z + 0.65;
}
if (strChildName == "Black_Queen")
{
tFactor = size.z + 0.5;
}
if (strChildName == "Black_LBishop")
{
tFactor = size.z + 0.5;
}
if (strChildName == "Black_RBishop")
{
tFactor = size.z + 0.5;
}
if (strChildName == "Black_LKnight")
{
tFactor = size.z + 0.05;
}
if (strChildName == "Black_RKnight")
{
tFactor = size.z + 0.05;
}
if (strChildName == "Black_LRook")
{
tFactor = size.z + 0.4;
}
if (strChildName == "Black_RRook")
{
tFactor = size.z + 0.4;
}
if (strChildName == "Black_LPawn1")
{
tFactor = size.z + 0.05;
}
if (strChildName == "Black_RPawn1")
{
tFactor = size.z + 0.05;
}
if (strChildName == "Black_LPawn2")
{
tFactor = size.z + 0.05;
}
if (strChildName == "Black_RPawn2")
{
tFactor = size.z + 0.05;
}
if (strChildName == "Black_LPawn3")
{
tFactor = size.z + 0.05;
}
if (strChildName == "Black_RPawn3")
{
tFactor = size.z + 0.05;
}
if (strChildName == "Black_LPawn4")
{
tFactor = size.z + 0.05;
}
if (strChildName == "Black_RPawn4")
{
tFactor = size.z + 0.05;
}
//for (idxBoard_XPos = 1; idxBoard_XPos <= 8; idxBoard_XPos = idxBoard_XPos + 1)
//{
//for (idxBoard_YPos = 1; idxBoard_YPos <= 8; idxBoard_YPos = idxBoard_YPos + 1)
//{
//if (strChildName == llList2String(llParseString2List(llList2String(listBoard, idxBoard_XPos * idxBoard_YPos), ["|"], []), 2))
//{
// listBoard = llListReplaceList(listBoard, [(string)x + "|" + (string)y + "|" + "EMPTY"], idxBoard_XPos * idxBoard_YPos, idxBoard_XPos * idxBoard_YPos);
//}
//if (x == llList2Integer(llParseString2List(llList2String(listBoard, idxBoard_XPos * idxBoard_YPos), ["|"], []), 0))
//{
//if (y == llList2Integer(llParseString2List(llList2String(listBoard, idxBoard_XPos * idxBoard_YPos), ["|"], []), 1))
//{
//if (llGetSubString(llList2String(llParseString2List(llList2String(listBoard, idxBoard_XPos * idxBoard_YPos), ["|"], []), 2), 0, 3) != llGetSubString(strChildName, 0, 3))
//{
//listBoard = llListReplaceList(listBoard, [(string)x + "|" + (string)y + "|" + strChildName], idxBoard_XPos * idxBoard_YPos, idxBoard_XPos * idxBoard_YPos);
finalpos = placexy + <0, 0, tFactor>;
llMessageLinked(intChildNum, 0, (string)finalpos + "|" + (string)x + "|" + (string)y, NULL_KEY);
//}
//else
//{
//}
//}
//}
//}
//}
llSetText(strChildName + " to " + (string)x + ", " + (string)y, <0.0, 1.0, 0.0>, 1.0);
}
}
Game Piece
Code:
//piece script V-0.3
//by Cam Chevalier
//09-June-2012
vector vecPieceCoords;
string strPieceName;
default
{
state_entry()
{
strPieceName = llGetObjectName();
}
touch_start(integer b)
{
llMessageLinked(LINK_ROOT, llGetLinkNumber(), strPieceName, NULL_KEY);
}
link_message(integer sender_num, integer num, string str, key id)
{
integer xPos;
integer yPos;
vecPieceCoords = llList2Vector(llParseString2List(str, ["|"], []), 0);
xPos = llList2Integer(llParseString2List(str, ["|"], []), 1);
yPos = llList2Integer(llParseString2List(str, ["|"], []), 2);
llSetPos(vecPieceCoords);
llSetText(strPieceName + "\n" + (string)xPos + ", " + (string)yPos, <1.0, 1.0, 1.0>, 1.0);
}
}
The Game Piece code depends on the prim being named something unique. In this case White_LeftPawn1 or Black_Queen.
Shad MOrdre