Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Discussion: Simon 1.1 Game Script

BelGarath Stern
CEO Bel-G Corp.
Join date: 19 Dec 2004
Posts: 9
08-05-2005 06:30
I put some prims together and trying to learn how lists work i came up with this. So i thought ide share what i made.
This is not a tutorial sombody else can do that if they wish. If you know the game simon then you will know where the scripts go. i dident comment much of the code i needed the room for code ;-].

As i was learning i wrote the scripts the way i knew how at the time, i'm sure there are better ways to do things but hey it works.

For those that can't be bothered building it, you can pick up a copy of mine for L$250
at:

TP To Simon Vendor
Simon Picture

Main Control Script.
Goes in main prim.

CODE


//BelGarath Stern Was Here.
string name = "No Player";
integer waiting;
integer round = 0;
integer this_round = 0;
integer counter;
integer ran_num;
list ran_numstring;

integer last_clicked = 0;
integer top_round = 0;
string top_player = "";
integer waitingforcommand = FALSE;
integer owner_listen;
float randBetween(float min, float max)
{
return llFrand(max - min) + min;
}

play_round()
{

round +=1;
llSetText("Top Player: " + top_player + " \n Highest Round: " + (string)top_round + " \n Current Player: \n" + name + "\n Round: \n" + (string)round + " \n \n \n \n \n \n \n \n \n \n \n \n \n",<0,1,0>,1.0);



ran_num = (integer)randBetween(1,5);
ran_numstring += [(string)ran_num];
integer iLen = llGetListLength(ran_numstring);
//llWhisper(0, llList2String(ran_numstring, 0) + llList2String(ran_numstring, 1));


integer i = 0;
for(i = 0; i < iLen; ++i) {
llSleep(0.5);

llMessageLinked(LINK_ALL_CHILDREN, 0, "light_up_" + llList2String(ran_numstring,i), NULL_KEY);
//llWhisper(0, llList2String(ran_numstring, i));
}
waiting = TRUE;
this_round = round;
this_round -=1;
counter = 0;
//llWhisper(0, (string)counter + " this round" + (string)this_round);
llMessageLinked(LINK_ALL_CHILDREN, 0, "allow_click", NULL_KEY);
llSetTimerEvent(10.0);
return;
}



check_clicked()
{

//counter +=1;
if (last_clicked == (integer)llList2String(ran_numstring, counter)) {
llSetTimerEvent(0.0);
llSetTimerEvent(10.0);
last_clicked = 0;
//llWhisper(0, (string)counter + " this round" + (string)this_round);
//counter +=1;
//return;
if (counter == this_round) {
//llWhisper(0, (string)counter + " this round" + (string)this_round);
waiting = FALSE;
llMessageLinked(LINK_ALL_CHILDREN, 0, "no_click", NULL_KEY);
llSetTimerEvent(0.0);
llSleep(2);
play_round();
//counter +=1;
//return;
}
else {
counter += 1;
return;
}

}
else {
llSetTimerEvent(0.0);
end_game();
return;
}
}


end_game()
{
integer round_tmp = round;
round_tmp -=1;
if (top_round < round_tmp) {
top_round = round_tmp;
top_player = name;
llWhisper(0, "Well done. " + name + ". New High Score");
}
ran_numstring = [];
name = "No Player";
round = 0;
waiting = FALSE;
llSetText("Top Player: " + top_player + " \n Highest Round: " + (string)top_round + " \n Current Player: \n" + name + "\n Round: \n" + (string)round + " \n \n \n \n \n \n \n \n \n \n \n \n \n",<0,1,0>,1.0);
llMessageLinked(LINK_ALL_CHILDREN, 0, "end", NULL_KEY);
llTriggerSound("e3cb771c-8f93-1df4-c3a9-338c08713b82",0.9);
llSetTimerEvent(0.0);


}



default
{
state_entry()
{
//ownername = llKey2Name(llGetOwner());
//owner_listen = llListen(0,"",llGetOwner(),"");
llWhisper(0, "Starting Simon. Scripted for you enjoyment by BelGarath Stern.");
//top_round = 0;
//top_player = "";
waiting = FALSE;
ran_numstring = [];
round = 0;
ran_num;
llSetText("Top Player: " + top_player + " \n Highest Round: " + (string)top_round + " \n Current Player: \n" + name + "\n Round: \n" + (string)round + " \n \n \n \n \n \n \n \n \n \n \n \n \n",<0,1,0>,1.0);
llPreloadSound("e3cb771c-8f93-1df4-c3a9-338c08713b82"); // lose
}
touch_start(integer total_number)
{
if (llGetOwner() == llDetectedKey(0))
{
waitingforcommand = TRUE;
llWhisper(0, "Waiting For Command...");
state wfc;
}

}
timer()
{
llSetTimerEvent(0.0);
end_game();
//llSetTimerEvent(0.0);



}
link_message(integer sender_num, integer num, string str, key id)
{
if (str=="clicked_1" && waiting == TRUE) {
last_clicked = 1;
check_clicked();
//llSetTimerEvent(0.0);
//llSetTimerEvent(10.0);
return;
}
if (str=="clicked_2" && waiting == TRUE) {
last_clicked = 2;
check_clicked();
//llSetTimerEvent(0.0);
//llSetTimerEvent(10.0);
return;
}
if (str=="clicked_3" && waiting == TRUE) {
last_clicked = 3;
check_clicked();
//llSetTimerEvent(0.0);
//llSetTimerEvent(10.0);
return;
}
if (str=="clicked_4" && waiting == TRUE) {
last_clicked = 4;
check_clicked();
//llSetTimerEvent(0.0);
//llSetTimerEvent(10.0);
return;
}
if (str=="start") {
llSetObjectDesc("Creator: BelGarath Stern.");
string str2 = (string)id;
name = str2;
llSetText("Top Player: " + top_player + " \n Highest Round: " + (string)top_round + " \n Current Player: \n" + name + "\n Round: \n" + (string)round + " \n \n \n \n \n \n \n \n \n \n \n \n \n",<0,1,0>,1.0);

play_round();
}
}
// on_rez(integer sparam)
// {
// llResetScript();
// }
}


state wfc
{
state_entry()
{
owner_listen = llListen(0,"",llGetOwner(),"");
llSetTimerEvent(20);
}
listen(integer channel, string name, key id, string message)
{
//llWhisper(0, "channel:" + (string)channel + " name:" + name + " id:" + (string)id + " message:" + message);
if (waitingforcommand == TRUE) {
list said = llParseString2List(message, [" "], []);
if (llToLower(llList2String(said, 0)) == "/simon") {
if (llToLower(llList2String(said, 1)) == "reset") {
//llResetScript();
llSetTimerEvent(0.0);
waitingforcommand == FALSE;
state default;
top_round = 0;
top_player = "";
}
}
}
}


timer()
{
llSetTimerEvent(0.0);
waitingforcommand == FALSE;
state default;
}
}



Start Button.

CODE


//BelGarath Stern Was Here.
integer in_game;
string name;
default
{
state_entry()
{
in_game = FALSE;
llSetColor(<1,0,0>,ALL_SIDES);
llSetPrimitiveParams([PRIM_MATERIAL,PRIM_MATERIAL_LIGHT]);
}

touch_start(integer total_number)
{

if (in_game == FALSE) {
name = llKey2Name(llDetectedKey(0));
llMessageLinked(LINK_ALL_OTHERS, 0, "start", name);
//llMessageLinked(1, 0, "start", NULL_KEY);
llSetColor(<0.9,0.1,0.5>,ALL_SIDES);
//llSetPrimitiveParams([PRIM_MATERIAL,PRIM_MATERIAL_GLASS]);
in_game = TRUE;
}


}
link_message(integer sender_num, integer num, string str, key id)
{

if (str == "end") {
in_game = FALSE;
llSetColor(<1,0,0>,ALL_SIDES);
//llSetPrimitiveParams([PRIM_MATERIAL,PRIM_MATERIAL_LIGHT]);
name ="";

}
}
on_rez(integer sparam)
{
llResetScript();
}
}



Button 1 {Green}.

CODE


//BelGarath Stern Was Here.
integer in_game = FALSE;
integer can_click = FALSE;
string name = "";

default
{
state_entry()
{
in_game = FALSE;
can_click = FALSE;
llSetColor(<0,0.74,0>,ALL_SIDES);
llPreloadSound("03a0e991-ac4c-771d-26c1-8796b0b0b9e5"); // yellow
llSetPrimitiveParams([PRIM_MATERIAL,PRIM_MATERIAL_GLASS]);
//llSetPrimitiveParams([PRIM_MATERIAL,PRIM_MATERIAL_LIGHT]);
}

touch_start(integer total_number)
{

if (in_game && can_click) {
if (llKey2Name(llDetectedKey(0)) == name) {
//llWhisper(0, "player clicked 1");
llMessageLinked(1, 0, "clicked_1", NULL_KEY);
llSetColor(<0,1,0>,ALL_SIDES);
//llSetPrimitiveParams([PRIM_MATERIAL,PRIM_MATERIAL_LIGHT]);
llTriggerSound("03a0e991-ac4c-771d-26c1-8796b0b0b9e5",0.9);
llSleep(0.3);
llSetColor(<0,0.74,0>,ALL_SIDES);
//llSetPrimitiveParams([PRIM_MATERIAL,PRIM_MATERIAL_GLASS]);
//llMessageLinked(1, 0, "start", NULL_KEY);
//llSetColor(<0.9,0.1,0.5>,ALL_SIDES);
//in_game = TRUE;

}
}


}
link_message(integer sender_num, integer num, string str, key id)
{
if (str == "light_up_1") {
llSetColor(<0,1,0>,ALL_SIDES);
//llSetPrimitiveParams([PRIM_MATERIAL,PRIM_MATERIAL_LIGHT]);
llTriggerSound("03a0e991-ac4c-771d-26c1-8796b0b0b9e5",0.9);
llSleep(0.3);
llSetColor(<0,0.74,0>,ALL_SIDES);
//llSetPrimitiveParams([PRIM_MATERIAL,PRIM_MATERIAL_GLASS]);
}

if(str=="start") {
llSetPrimitiveParams([PRIM_MATERIAL,PRIM_MATERIAL_LIGHT]);
string str2 = (string)id;
name = str2;
in_game = TRUE;
}

if (str == "end") {
in_game = FALSE;
llSetColor(<0,0.74,0>,ALL_SIDES);
llSetPrimitiveParams([PRIM_MATERIAL,PRIM_MATERIAL_GLASS]);
name ="";

}
if(str=="allow_click") {
can_click = TRUE;
}

if (str == "no_click") {
can_click = FALSE;

}
}
}


Button 2 {Yellow}

CODE


//BelGarath Stern Was Here.
integer in_game = FALSE;
integer can_click = FALSE;
string name = "";

default
{
state_entry()
{
in_game = FALSE;
can_click = FALSE;
llSetColor(<0.74,0.74,0>,ALL_SIDES);
llSetPrimitiveParams([PRIM_MATERIAL,PRIM_MATERIAL_GLASS]);
llPreloadSound("1d51f673-15b4-fa9c-aecd-1a162fe3763e"); // blue

}

touch_start(integer total_number)
{

if (in_game && can_click) {
if (llKey2Name(llDetectedKey(0)) == name) {
//llWhisper(0, "player clicked 2");
llMessageLinked(1, 0, "clicked_2", NULL_KEY);
llSetColor(<1,1,0>,ALL_SIDES);
//llSetPrimitiveParams([PRIM_MATERIAL,PRIM_MATERIAL_LIGHT]);
llTriggerSound("1d51f673-15b4-fa9c-aecd-1a162fe3763e",0.9);
llSleep(0.3);
llSetColor(<0.74,0.74,0>,ALL_SIDES);
//llSetPrimitiveParams([PRIM_MATERIAL,PRIM_MATERIAL_GLASS]);
//llMessageLinked(1, 0, "start", NULL_KEY);
//llSetColor(<0.9,0.1,0.5>,ALL_SIDES);
//in_game = TRUE;
}
}


}
link_message(integer sender_num, integer num, string str, key id)
{
if (str == "light_up_2") {
llSetColor(<1,1,0>,ALL_SIDES);
//llSetPrimitiveParams([PRIM_MATERIAL,PRIM_MATERIAL_LIGHT]);
llTriggerSound("1d51f673-15b4-fa9c-aecd-1a162fe3763e",0.9);
llSleep(0.3);
llSetColor(<0.74,0.74,0>,ALL_SIDES);
//llSetPrimitiveParams([PRIM_MATERIAL,PRIM_MATERIAL_GLASS]);

}

if(str=="start") {
llSetPrimitiveParams([PRIM_MATERIAL,PRIM_MATERIAL_LIGHT]);
string str2 = (string)id;
name = str2;
in_game = TRUE;
}

if (str == "end") {
llSetPrimitiveParams([PRIM_MATERIAL,PRIM_MATERIAL_GLASS]);
in_game = FALSE;
llSetColor(<0.74,0.74,0>,ALL_SIDES);
//llSetPrimitiveParams([PRIM_MATERIAL,PRIM_MATERIAL_GLASS]);
name ="";

}
if(str=="allow_click") {
can_click = TRUE;
}

if (str == "no_click") {
can_click = FALSE;

}
}
}


Button 3 {Blue}

CODE


integer in_game = FALSE;
integer can_click = FALSE;
string name = "";

default
{
state_entry()
{
in_game = FALSE;
can_click = FALSE;
llSetColor(<0,0.71,0.71>,ALL_SIDES);
llSetPrimitiveParams([PRIM_MATERIAL,PRIM_MATERIAL_GLASS]);
llPreloadSound("7c043aa3-64df-a0f1-c825-fad216153272"); // green
}

touch_start(integer total_number)
{

if (in_game && can_click) {
if (llKey2Name(llDetectedKey(0)) == name) {
//llWhisper(0, "player clicked 3");
llMessageLinked(1, 0, "clicked_3", NULL_KEY);
llSetColor(<0,1,1>,ALL_SIDES);
//llSetPrimitiveParams([PRIM_MATERIAL,PRIM_MATERIAL_LIGHT]);
llTriggerSound("7c043aa3-64df-a0f1-c825-fad216153272",0.9);
llSleep(0.3);
llSetColor(<0,0.71,0.71>,ALL_SIDES);
//llSetPrimitiveParams([PRIM_MATERIAL,PRIM_MATERIAL_GLASS]);
//llMessageLinked(1, 0, "start", NULL_KEY);
//llSetColor(<0.9,0.1,0.5>,ALL_SIDES);
//in_game = TRUE;
}
}


}
link_message(integer sender_num, integer num, string str, key id)
{
if (str == "light_up_3") {
llSetColor(<0,1,1>,ALL_SIDES);
//llSetPrimitiveParams([PRIM_MATERIAL,PRIM_MATERIAL_LIGHT]);
llTriggerSound("7c043aa3-64df-a0f1-c825-fad216153272",0.9);
llSleep(0.3);
llSetColor(<0,0.71,0.71>,ALL_SIDES);
//llSetPrimitiveParams([PRIM_MATERIAL,PRIM_MATERIAL_GLASS]);

}

if(str=="start") {
llSetPrimitiveParams([PRIM_MATERIAL,PRIM_MATERIAL_LIGHT]);
string str2 = (string)id;
name = str2;
in_game = TRUE;
}

if (str == "end") {
llSetPrimitiveParams([PRIM_MATERIAL,PRIM_MATERIAL_GLASS]);
in_game = FALSE;
llSetColor(<0,0.71,0.71>,ALL_SIDES);
//llSetPrimitiveParams([PRIM_MATERIAL,PRIM_MATERIAL_GLASS]);
name ="";

}
if(str=="allow_click") {
can_click = TRUE;
}

if (str == "no_click") {
can_click = FALSE;

}
}
}


Button 4 {Red}

CODE


//BelGarath Stern Was Here.

integer in_game = FALSE;
integer can_click = FALSE;
string name = "";

default
{
state_entry()
{
in_game = FALSE;
can_click = FALSE;
llSetColor(<0.74,0,0>,ALL_SIDES);
llSetPrimitiveParams([PRIM_MATERIAL,PRIM_MATERIAL_GLASS]);
llPreloadSound("6295075d-674e-13c1-3128-237009b38e41"); // red
}

touch_start(integer total_number)
{

if (in_game && can_click) {
if (llKey2Name(llDetectedKey(0)) == name) {
//llWhisper(0, "player clicked 4");
llMessageLinked(1, 0, "clicked_4", NULL_KEY);
llSetColor(<1,0,0>,ALL_SIDES);
//llSetPrimitiveParams([PRIM_MATERIAL,PRIM_MATERIAL_LIGHT]);
llTriggerSound("6295075d-674e-13c1-3128-237009b38e41",0.9);
llSleep(0.3);
llSetColor(<0.74,0,0>,ALL_SIDES);
//llSetPrimitiveParams([PRIM_MATERIAL,PRIM_MATERIAL_GLASS]);
//llMessageLinked(1, 0, "start", NULL_KEY);
//llSetColor(<0.9,0.1,0.5>,ALL_SIDES);
//in_game = TRUE;
}
}


}
link_message(integer sender_num, integer num, string str, key id)
{
if (str == "light_up_4") {
llSetColor(<1,0,0>,ALL_SIDES);
//llSetPrimitiveParams([PRIM_MATERIAL,PRIM_MATERIAL_LIGHT]);
llTriggerSound("6295075d-674e-13c1-3128-237009b38e41",0.9);
llSleep(0.3);
llSetColor(<0.74,0,0>,ALL_SIDES);
//llSetPrimitiveParams([PRIM_MATERIAL,PRIM_MATERIAL_GLASS]);

}

if(str=="start") {
llSetPrimitiveParams([PRIM_MATERIAL,PRIM_MATERIAL_LIGHT]);
string str2 = (string)id;
name = str2;
in_game = TRUE;
}

if (str == "end") {
llSetPrimitiveParams([PRIM_MATERIAL,PRIM_MATERIAL_GLASS]);
in_game = FALSE;
llSetColor(<0.74,0,0>,ALL_SIDES);
//llSetPrimitiveParams([PRIM_MATERIAL,PRIM_MATERIAL_GLASS]);
name ="";

}
if(str=="allow_click") {
can_click = TRUE;
}

if (str == "no_click") {
can_click = FALSE;

}
}
}

_____________________
Nada Epoch
The Librarian
Join date: 4 Nov 2002
Posts: 1,423
Original Thread
08-06-2005 12:07
/15/00/56557/1.html
_____________________
i've got nothing. ;)
Kurt Zidane
Just Human
Join date: 1 Apr 2004
Posts: 636
08-06-2005 16:33
Your button script slightly tweeked. Global Variables under Button Parramiters can be used to change witch color the script will work for.

CODE
// Script Name: Simon Button
// Vertion: 0.00.01 B
// Created By: BelGarath Stern - 0.00.01 A - 8/6/05
// Modified By: Kurt Zidane - 0.00.01 B - 8/6/05
// Modified By:

// Script Desc: Interactive button, The goal is to emulate an illuminated button for the game Simon. When scripted primitive is touched, object will change color for a set amount of time. And play a specified sound.

//Global Variables
// Dynamic
integer in_game = FALSE;
integer can_click = FALSE;
key user = NULL_KEY;
// Button Settings
float volume = 0.9;
float blinkTime = 0.3;
//Settings
// Button Parameters
string name = "light_up_1";
key touchSound = "03a0e991-ac4c-771d-26c1-8796b0b0b9e5";
vector activeColor = <0,1,0>;
vector unActiveColor = <0,0.74,0>;

//Functions
// Configure Object
setup ()
{
in_game = FALSE;
can_click = FALSE;
user = NULL_KEY;
llSetColor( unActiveColor, ALL_SIDES );
llPreloadSound( touchSound );
llSetPrimitiveParams( [PRIM_MATERIAL,PRIM_MATERIAL_GLASS] );
}

//States & Events
default
{
state_entry()
{
setup ();
}

touch_start(integer total_number)
{
if ( in_game && can_click )
{
if ( user == NUL_KEY or user == llDetectedKey(0) )
{
llMessageLinked( 1, 0, "clicked_1", NULL_KEY);
llSetColor( activeColor ,ALL_SIDES);
llTriggerSound( touchSound, volume);
llSleep( blinkTime );
llSetColor( unActiveColor, ALL_SIDES );
}
}
}

link_message(integer sender_num, integer num, string str, key id)
{
if ( str == name )
{
llSetColor( activeColor, ALL_SIDES );
llTriggerSound( touchSound, volume );
llSleep( blinkTime );
llSetColor( unActiveColor, ALL_SIDES );
}
else if ( str =="start" )
{
llSetPrimitiveParams( [PRIM_MATERIAL,PRIM_MATERIAL_LIGHT] );
user = id;
in_game = TRUE;
}
else if ( str == "end" )
{
in_game = FALSE;
llSetColor( unActiveColor, ALL_SIDES );
llSetPrimitiveParams( [PRIM_MATERIAL,PRIM_MATERIAL_GLASS] );
user = NULL_KEY;
}
else if ( str == "allow_click")
{
can_click = TRUE;
}
else if ( str == "no_click" )
{
can_click = FALSE;
}
}
}
Christopher Omega
Oxymoron
Join date: 28 Mar 2003
Posts: 1,828
08-06-2005 21:15
Be *very* careful with branding this as "Simon", you may be violating Hasbro's trademark/copyright :eek:
==Chris
_____________________
October 3rd is the Day Against DRM (Digital Restrictions Management), learn more at http://www.defectivebydesign.org/what_is_drm
Corisons Nino
Singular Entity.
Join date: 11 Jul 2005
Posts: 49
08-22-2005 19:55
how do you play it?
_____________________
Lightwave Valkyrie
Registered User
Join date: 30 Jan 2004
Posts: 666
08-23-2005 10:39
This game will test your memory, and, ultimately, your sanity. The object of the game is to memorize Simon's sequence of lights.
Simon lights one of the coloured pads and sounds a tone, then two, then three, etc. Players attempt to match Simon by pressing the pads in the proper sequence. If someone fails, they get a 'raspberry' and are out of the game.

Use your mouse to click start and click the color bars int the same order they play in.
-LW
Corisons Nino
Singular Entity.
Join date: 11 Jul 2005
Posts: 49
09-15-2005 11:36
Nice, Got it... highest score was 17 :)
_____________________
Keknehv Psaltery
Hacker
Join date: 11 Apr 2005
Posts: 1,185
09-15-2005 16:02
Ah, sweet. I saw this thing in the Island Sandbox once, but then it was gone.

I might post up some changes once I've played with it :D
2fast4u Nabob
SL-ice.net
Join date: 28 Dec 2005
Posts: 542
Cannot get this working
01-25-2006 08:35
I built a rough version of the game and cannot get these scripts to work. I think it may be realted to how I'm linking the prims - what's the root prim? I also only saw the script trying to run only once despite resetting and recompiling it - perhaps this is related to the first issue.

BTW...I plan to modify this to give away a prize based on the player's score - kind of an incentive to play and add a little friendly competition :)

-2fast
Rhotis Paine
Registered User
Join date: 24 Dec 2007
Posts: 1
03-22-2008 21:56
Hrmm, cool idea, out of curiosity, if you set something like this up and charged for it, with a jackpot if you beat X score..... would this be considered a skill game and thus legal in SL?
Stora Zhora
Registered User
Join date: 27 Apr 2008
Posts: 10
08-13-2008 16:11
From: Rhotis Paine
Hrmm, cool idea, out of curiosity, if you set something like this up and charged for it, with a jackpot if you beat X score..... would this be considered a skill game and thus legal in SL?


interesting thought.
Dekka Raymaker
thinking very hard
Join date: 4 Feb 2007
Posts: 3,898
08-13-2008 16:54
seeing as your told the sequence in advance the skill is to follow that sequence, so yes it would be acceptable to charge for a go and offer a prize for beating a high score, but if you had to choose a random sequence first and then the game told you whether it was correct or not, that would be gambling and pretty much impossible :)
_____________________