//4-in-a-Row Build Game v002-008 integer didit = FALSE; string objPlaySpot = "Play Piece"; vector where2rez = < 3.0, 3.0, 3.0 >; integer planes = 4; integer rows = 4; integer columns = 4; integer countPlanes = 0; integer countRows = 0; integer countColumns = 0; integer primsRezd = 0; integer primsLinked; integer QPrims; default { state_entry(){ llOwnerSay( "Touch me to Build 4-in-a-Row game board."); QPrims = ( planes * columns * rows ) + 1; where2rez = llGetPos() + where2rez; } touch_start(integer total_number){ if( llGetOwner() == llDetectedKey( 0 ) ) llRequestPermissions( llGetOwner(), PERMISSION_CHANGE_LINKS ); } run_time_permissions( integer permissions_granted ){ if( permissions_granted == PERMISSION_CHANGE_LINKS ){ state Building; } else { llOwnerSay( "Didn't get permission to change links." ); return; } } } state Built { touch_start(integer total_number){ if( llGetOwner() == llDetectedKey( 0 ) ){ llOwnerSay( "#" + (string) llDetectedLinkNumber( 0 ) + " of " + (string) llGetNumberOfPrims( ) ); } } } state Building { state_entry(){ vector next_spot; primsLinked = llGetNumberOfPrims() - 1; next_spot = where2rez + < countColumns - 1.5, countRows - 1.5, countPlanes - 1.5 >; llRezObject( objPlaySpot, next_spot, ZERO_VECTOR, ZERO_ROTATION, 0); } object_rez( key child_id ) { // link as parent to the just created child. llCreateLink( child_id, TRUE ); // wait until the link is confirmed integer testLinks; integer countOut = 0; do{ llSleep( 1.0 ); testLinks = llGetNumberOfPrims() - 1; ++countOut; if( countOut > 1 ) llOwnerSay("countOut " + (string) countOut); if( countOut == 10 ){ llOwnerSay( "Failed to link object #" + (string) primsLinked ); state Built; } } while( testLinks < primsLinked ); // llOwnerSay( (string) countPlanes // + (string) countRows // + (string) countColumns ); countColumns = ( countColumns + 1 ) % 4; if ( countColumns == 0 ){ countRows = ( countRows + 1 ) % 4; if ( countRows == 0 ){ countPlanes = countPlanes + 1; if ( countPlanes == 4 ) state Built; } } state IncrPrims; } } state IncrPrims{ state_entry() { ++primsLinked; state Building; } }