Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

multi language note giver

Igota Newcomb
Registered User
Join date: 5 Nov 2006
Posts: 3
05-29-2009 16:56
Hi

I been trying to combine 2 scripts one I found on the wiki the other is a visitor list maker.
I want to give a note card out but just once to each person in thier own language.
I'm lost can some smart guy show me how to set up the for loops so this works?
this seems to give the first person it finds a bunch of notes lol.

list visitor_list;
float range = 45.0; // in meters
float rate = 5.0; // in seconds


// Functions
integer isNameOnList( string name )
{
integer len = llGetListLength( visitor_list );
integer i;
for( i = 0; i < len; i++ )
{
if( llList2String(visitor_list, i) == name )
{
return TRUE;
}
}
return FALSE;
}




default
{
state_entry()
{
llSensorRepeat( "", "", AGENT, range, TWO_PI, rate );
llListen(0, llGetOwner(), "", "";);
}
on_rez(integer pop)
{
llResetScript();
}
listen( integer channel, string name, key id, string message )
{
if( id != llGetOwner() )
{
return;
}

if( message == "help" )
{
llSay( 0, "This object records the names of everyone who" );
llSay( 0, "comes within "+ (string)range + " meters." );
llSay( 0, "Commands the owner can say:" );
llSay( 0, "'help' - Shows these instructions." );
llSay( 0, "'say list' - Says the names of all visitors on the list.";);
llSay( 0, "'reset list' - Removes all the names from the list." );
}
else
if( message == "say list" )
{
llSay( 0, "Visitor List:" );
integer len = llGetListLength( visitor_list );
integer i;
for( i = 0; i < len; i++ )
{
llSay( 0, llList2String(visitor_list, i) );
}
llSay( 0, "Total = " + (string)len );
}
else
if( message == "reset list" )
{
visitor_list = llDeleteSubList(visitor_list, 0, llGetListLength(visitor_list));
llSay( 0, "Done resetting.";);
}
}
sensor( integer number_detected )
{
integer i;
for( i = 0; i < number_detected; i++ )
{
// if( llDetectedKey( i ) != llGetOwner() )
// {
string detected_name = llDetectedName( i );
if( isNameOnList( detected_name ) == FALSE )
{
integer j;
for(j=0;j<number_detected;j++) {
string name=llDetectedName(j);
string lang=llGetAgentLanguage(llDetectedKey(i));
if(lang=="";) lang="en"; // Default to English.
if(lang=="en";) {
llSay(0,"Hi there, "+name+"!";);
llGiveInventory(llDetectedKey(i),"Warning in English";);
}else if(lang=="es";) {
llSay(0,"¡Hola, "+name+"!";);
llGiveInventory(llDetectedKey(i),"Warning in Spanish";);
}else if(lang=="fr";) {
llSay(0,"Salut, "+name+" !";);
llGiveInventory(llDetectedKey(i),"Warning in French";);
}else if(lang=="ja";) {
llSay(0,"やあ、 "+name+"!";);
llGiveInventory(llDetectedKey(i),"Warning in Japanese";);
}else if(lang=="de";) {
llSay(0,"Hallo, "+name+"!";);
llGiveInventory(llDetectedKey(i),"Warning in German";);
}else if(lang=="pt";) {
llSay(0,"Olá!, "+name+"!";);
llGiveInventory(llDetectedKey(i),"Warning in Portuguese";);
}else if(lang=="ko";) {
llSay(0,"안녕하세요, "+name+"!";);
llGiveInventory(llDetectedKey(i),"Warning in Korean";);
}else if(lang=="zh";) {
llSay(0,"你好啊, "+name+"!";);
llGiveInventory(llDetectedKey(i),"Warning in Chinese";);
}
}
visitor_list += detected_name;
}
//}
}
}
}
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
05-29-2009 18:39
Hi Igota and welcome to the scripting forum. I saw a couple of problems but then I started playing with the script and got carried away! Just another way of doing it:

CODE


list langList = ["en-us", "Hi there", "Warning in English",
"es", "¡Hola", "Warning in Spanish",
"fr", "Salut", "Warning in French",
"ja", "???", "Warning in Japanese",
"de", "Hallo", "Warning in German",
"pt", "Olá!", "Warning in Portuguese",
"ko", "?????", "Warning in Korean",
"zh", "???", "Warning in Chinese"
];
list visitor_list;
float range = 5.0; // in meters
float rate = 5.0; // in seconds
integer on = 1;
integer listenID;
string name;
//integer nameTest;


// Functions
integer isNameOnList()//)
{
if (~llListFindList(visitor_list, (list) name)) {
//same as if (llListFindList(visitor_list, (list) name) != -1)
return TRUE;
}
else {
llOwnerSay("name added");
return FALSE;
}
}

default {
on_rez(integer pop) {
llResetScript();
}
touch_start(integer n) {
if(llGetOwner() == llDetectedKey(0)){
if(on){
llOwnerSay("on");
llListenRemove(listenID);
llSensorRepeat("", "", AGENT, range, PI, rate);
}
else{
llOwnerSay("off");
llSensorRemove();
listenID = llListen(99, "", llGetOwner(),"");
}
on = !on;
}
}
listen(integer channel, string name, key id, string message) {
if (message == "help") {
llOwnerSay("This object records the names of everyone who" +
"\ncomes within " + (string) range + " meters." +
"\nCommands the owner can say:" +
"\n'help' - Shows these instructions." +
"\n'say list' - Says the names of all visitors on the list." +
"\n'reset list' - Removes all the names from the list.");
}
else if (message == "say list") {
llOwnerSay("Visitor List:");
integer len = llGetListLength(visitor_list);
integer i;
for (i = 0; i < len; i++) {
llOwnerSay(llList2String(visitor_list, i));
}
llOwnerSay("Total = " + (string) len);
}
else if (message == "reset list") {
visitor_list =[];
llOwnerSay("Done resetting.");
}
}
sensor(integer number_detected) {
integer i;
for (i = 0; i < number_detected; i++) {
name = llDetectedName(i);
if (!isNameOnList()) {
//same as if(isNameOnList() == FALSE)
string lang = llGetAgentLanguage(llDetectedKey(i));
if (lang == "") {
lang = "en-us";
}
integer test = llListFindList(langList, (list)lang);
string greeting = llList2String(langList, ++test);
string card = llList2String(langList, ++test);
llSay(0, greeting + ", " + name + "!");
llGiveInventory(llDetectedKey(i), card);
visitor_list += name;
}
}
}
}


_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime.
From: someone
I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
Igota Newcomb
Registered User
Join date: 5 Nov 2006
Posts: 3
05-29-2009 18:56
Thank you very much that works great.
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
05-29-2009 20:07
I had to clean it up a little and added comments so you could more easily understand what I was doing:

CODE


//this is called a strided list
list langList = ["en-us", "Hi there", "Warning in English",
"es", "¡Hola", "Warning in Spanish",
"fr", "Salut", "Warning in French",
"ja", "???", "Warning in Japanese",
"de", "Hallo", "Warning in German",
"pt", "Olá!", "Warning in Portuguese",
"ko", "?????", "Warning in Korean",
"zh", "???", "Warning in Chinese"
];
list visitor_list;
float range = 45.0; // in meters
float rate = 5.0; // in seconds
integer on = 1;//integer 1 is the same as the value TRUE
integer listenID;
string name;
//integer nameTest;


// Functions
integer isNameOnList()//)
{
if (~llListFindList(visitor_list, (list) name)) {
//same as if (llListFindList(visitor_list, (list) name) != -1)
return TRUE;
}
else {
llOwnerSay("name added");
return FALSE;
}
}

default {
on_rez(integer pop) {
llResetScript();
}
touch_start(integer n) {
if(llGetOwner() == llDetectedKey(0)){
//This is a simple integer switch. Everytime you touch it,
//it changes the values between TRUE & FALSE
if(on){
//This reads as: if(on == TRUE)
llOwnerSay("on");
llListenRemove(listenID);
llSensorRepeat("", "", AGENT, range, PI, rate);
}
else{
llOwnerSay("off");
llSensorRemove();
listenID = llListen(99, "", llGetOwner(),"");
}
on = !on;//This is the actual switch
}
}
listen(integer channel, string name, key id, string message) {
if (message == "help") {
llOwnerSay("This object records the names of everyone who" +
//"/n" denotes a newline
"\ncomes within " + (string) range + " meters." +
"\nCommands the owner can say:" +
"\n'help' - Shows these instructions." +
"\n'say list' - Says the names of all visitors on the list." +
"\n'reset list' - Removes all the names from the list.");
}
else if (message == "say list") {
//now you do not have to do a loop test to output the names
llOwnerSay("Visitor List:\n" +
llDumpList2String(visitor_list, "\n") +
"\nTotal = " + (string)llGetListLength(visitor_list));
}
else if (message == "reset list") {
visitor_list =[];//The empties the list
llOwnerSay("Done resetting.");
}
}
sensor(integer number_detected) {
integer i;
for (i = 0; i < number_detected; i++) {
name = llDetectedName(i);
if (!isNameOnList()) {
//same as if(isNameOnList() == FALSE)
string lang = llGetAgentLanguage(llDetectedKey(i));
llOwnerSay((string)lang);
integer test = llListFindList(langList, (list)lang);
if(test == -1){
//can not find lang so default to en-us
test = 0;
}
llOwnerSay((string)test);
string greeting = llList2String(langList, ++test);
string card = llList2String(langList, ++test);
llOwnerSay(greeting + ", " + name + "!");
llSay(0, greeting + ", " + name + "!");
llGiveInventory(llDetectedKey(i), card);
visitor_list += name;//adds name to list
}
}
}
}


_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime.
From: someone
I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
Igota Newcomb
Registered User
Join date: 5 Nov 2006
Posts: 3
06-01-2009 17:38
Hi well tested it last weekend and it has a few problems.
I was using the cleaned up version and every once in a while it said script error unable to give object Hello "persons name".
I think that's what it said I should a wrote that down I guess but it seemed as though it was trying to give out what it should have been speaking. but not every time. just once in a while.
it is in mono too. If that helps. maybe its the if no language selected part?
because I "think" it was in english.