Jump to content

memory game using textures


testgenord1
 Share

You are about to reply to a thread that has been inactive for 1796 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

Hi!
I've made a memory game using textures.
The memory cards start off with their textures in the colour black.
When you click on a card, the colour of the texture changes from black to white and it thus becomes visible.
When you click on another card the same thing happens.

When you happen to click on two matching cards (having the same texture),
you get the feedback "Well done!" /"matching card found" or something similar.
(matching cards:
texture 1 and texture 1)

What I would like to change, however is the following:

I would like to use this memory game as a vocabulary exercise.
One card is supposed to display an English word
A second card is supposed to display the same word in a different language.
There is a texture for the English word and another texture for the same word in, e.g., French.

This means the script would have to be adjusted in the following way:
The cards that match each other would not be cards having the same texture,
but they would have different textures.
(matching cards:
texture English and texture French)

I guess this is hard to achieve.
Do you maybe have an idea of how to do this?
Thank you very much in advance.

//written by Rebecca Davis and dj phil 05/25/2019; 
//https://www.youtube.com/watch?v=lCHt7dCEqJA
//https://forums.osgrid.org/viewtopic.php?f=5&t=6353

list pics = [];
list used = [];
list done = [];

integer debug = FALSE;
integer tries;
list select = [];
string pic1;
key user;
list success = [];
list chosen = [];

list players = [];
string playerlist;
key current;


fillPics()
{
	integer i;
	integer all = llGetInventoryNumber(INVENTORY_TEXTURE);
	if(debug)llOwnerSay((string)all+" textures found");
	for(i=0; i<all; i=i+1)
	{
		string add = llGetInventoryName(INVENTORY_TEXTURE,i);
		pics = pics + add;
		if(debug)llOwnerSay("Adding Texture "+add+" to Pics List");
	}
}

populate()
{
	integer all = llGetNumberOfPrims( );
	integer this = llGetLinkNumber();
	integer picCount = llGetListLength(pics); picCount=picCount-1;
	list used = [];
	list done = [];
	if(debug) llOwnerSay((string)all+" Number of parts. The Root is "+(string)this);
	integer i;
	llSetLinkColor(this, <1,1,1>, ALL_SIDES);
	for(i=this; i<all; i=i+1)
	{
		string thisPic = picSelect(picCount);
		llSetLinkTexture(i+1,thisPic,ALL_SIDES);
		llSetLinkColor(i+1, <0,0,0>, ALL_SIDES);
		//llSetLinkColor(i+1, <0,0,0>, ALL_SIDES);
	}
}

string picSelect(integer picCount)
{
	user = llGetOwner();
	integer nope = 1;
	string picName;
	while(nope != -1)
	{
		integer choose = llRound(llFrand(picCount));
				picName= llList2String(pics,choose);
				nope = llListFindList(done,[picName]);
		integer last = llListFindList(used,[picName]);
		if(last != -1) done = done + picName;
		else		   used = used + picName;
	}
	return picName;
}

chooser(integer box)
{
	string name = llKey2Name(user);
	llSetLinkColor(box,<1,1,1>, ALL_SIDES);
	select = select+box;
	if(llGetListLength(select)>1)
	{
		string pic2 = texture(box);
		if(pic1 == pic2)
		{
			llSay(0,"Well done, "+name+"!"+"\n\n");
			chosen = chosen + box;
			box = llList2Integer(select,0);
			chosen = chosen + box;
		}
		else
		{
			//llSay(0,"Sorry that is not a match");
			llSleep(3);
			if(llListFindList(chosen,[box]) == -1)llSetLinkColor(box,<0,0,0>, ALL_SIDES);
			box = llList2Integer(select,0);
			if(llListFindList(chosen,[box]) == -1)llSetLinkColor(box,<0,0,0>, ALL_SIDES);
			integer place = llListFindList(players, [current]);
			place = place +1;
			if(place < llGetListLength(players) ) current = llList2Key(players,place);
			else current = llList2Key(players,0);	
			llSetText(playerlist+"\n\n It is "+llKey2Name(current)+"'s turn.\n\n", <1,1,1>, 1);
		}
		//llSay(0,name+" is done");
		llSay(0,"Next player, please.\n\n");
		select = [];
		pic1 = "";
		return;
	}
	else
	{
		pic1 = texture(box);
	}
}

string texture(integer box)
{
	list params = llGetLinkPrimitiveParams(box,[ PRIM_TEXTURE, 0]);
	string get = llList2String(params,0);
	return get;
	}

add(key who)
{
	players = players + who;
	string PlayersShow = "";
	integer i;
	for(i=0; i<llGetListLength(players); i=i+1)
	{
		PlayersShow = PlayersShow + llKey2Name(llList2Key(players,i));
	}
	playerlist = "players:\n"+PlayersShow;
	llSetText("players "+PlayersShow+"\nClick to join the game.\n\n", <1,1,1>, 1);
}
default
{
	state_entry()
	{
		fillPics();
		populate();
		//llSay(0,"Click the board to sign up for this round");
		llListen(0,"",NULL_KEY,"start");
		llListen(0,"",NULL_KEY,"reset");
		//llSetText("Current Players \n None \n \nclick to join game", <1,1,1>, 1);
	}
	listen(integer chan, string what, key who, string msg)
	{
		if(msg == "start")state play;
		else if(msg == "reset")llResetScript();
	}
	touch_start(integer clicked)
	{
		add(llDetectedKey(0));
		state play;
	}
}

state play
{		
	state_entry()
	{
		llSay(0,"Starting the game"+"\n\n");
		llListen(0,"",NULL_KEY,"reset");
		current = llList2Key(players,0);
		llSetText(playerlist+"\n\n It is "+llKey2Name(current)+"'s turn.\n\n", <1,1,1>, 1);
	}
	listen(integer chan, string what, key who, string msg)
	{
		if(msg == "reset")llResetScript();
	
	}
	touch_start(integer total_number)
	{
		key clicked = llDetectedKey(0);
		if(clicked != current)
		{
			llInstantMessage(clicked,"Sorry, it is not your turn.\n\n");
			return;
		}
		
		if(clicked != user)
		{
			llInstantMessage(clicked,"It is not your turn.\n\n");
			return;
		}
		integer box = llDetectedLinkNumber(0);
		if(llListFindList(chosen,[box]) == -1) chooser(box);
		llSetTimerEvent(120);
		}
			timer()
			{
				llResetScript();
			}
		
	}


 

Link to comment
Share on other sites

29 minutes ago, Wandering Soulstar said:

What not have the word, in English for example, as part of the name of the texture: ENG_Texture_Boat & FRA_Texture_Boat. then you could use llGetSubString to identify the word and see if it is a match.

Interesting.
So the llGetSubString  would "cut off" the differing prefixes of the names of the two matching cards
and thus turn the 'English card' into: "[ENG_]Texture_Boat" (="Texture_Boat")
and the 'French' matching card into: "[FRA_]Texture_Boat" (="Texture_Boat")
and then they would actually match.

Did I get this right?

I'll have a look at this.
Just have to find out how to do this yet.
Thanks!

Link to comment
Share on other sites

Put both words on one texture. English - top half and french - bottom half.

I'd integrate picselect into populate and can then easily decide if top or low half of the texture is to display on a specific link. Only small code changes required.

 

If you prefer renaming the textures, it's is not that easy as it seems.

If I see that right you have more textures than links. So renaming the textures is not enough. You always need to make sure that the counterpart of a specific texture is placed on another link. So you can no longer randomly take from textures. A solution would be to only take randomly half as many textures as you need and only take the version1 textures. Then you need to fill up the list with the matching version2 textures.

  • Like 1
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 1796 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...