Jump to content

Add a command to a script


Tania Ivanovic
 Share

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

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

Recommended Posts

I have a script that gives me the option to choose a floating text to an object and a color for this text, is activated by touch, but if I put more of an object near the same script all respond to the chat command. I need to add to the script that I have to just respond to the command of the chat when I touch it and I have no idea how. Someone could help me?

 

string command = "";
string person = "";
key owner;

default
{
    on_rez(integer n) { llResetScript(); }

    state_entry()
    {
        owner = llGetOwner();
        llListen(0,"",owner,"");
    }
    
    touch_start(integer total_number)
    {
    if (llDetectedKey(0) == owner)
     {
            llInstantMessage(owner,"To set a title: title <color name> <title text>");
            llInstantMessage(owner,"To remove title: title off");
            llInstantMessage(owner,"<color name> can be: white, black, red, green, blue, pink, cyan, purple, yellow, orange");
            llResetScript();
        }
    }

    listen(integer channel, string name, key id, string message)
    {
        list strings = llParseString2List(message,[" "],[]);
        string command=llList2String(strings,0);
        string string1=llList2String(strings,1);
        if(command=="title")
        {
            vector color=<0,0,0>;
            if(string1=="blue")
            {
                color=<0,0,1>;
            }
            else if(string1=="orange")
            {
                color=<1,0.5,0>;
            }
            else if(string1=="cyan")
            {
                color=<0,1,1>;
            }
            else if(string1=="pink")
            {
                color=<1,0,1>;
            }
            else if(string1=="green")
            {
                color=<0,1,0>;
            }
            else if(string1=="red")
            {
                color=<1,0,0>;
            }
            else if(string1=="white")
            {
                color=<1,1,1>;
            }
            else if(string1=="yellow")
            {
                color=<1,1,0.1>;
            }
            else if(string1=="purple")
            {
                color=<0.7,0,0.7>;
            }
            else
            {
                color=<0,0,0>;
            }
            string title = "";
            integer i;
            for(i=2; i<=12; i++)
            {
                if(llStringLength(llList2String(strings,i)))
                {
                    title = title + llList2String(strings,i) + " ";
                }
            }
            if(title == "off")
            {
                llSetText("",<0,0,0>,1.0);
            } else {
                llSetText(title, color, 1.0);   
                llResetScript();
            }
        }   
    }
}

Link to comment
Share on other sites

I'm not quite clear about what you are trying to do, but this will work a lot better than what you have now (which, frankly, is not a very well-written script):

key owner;integer gLsn;default{	changed (integer change)	{		if(change & CHANGED_OWNER)		{			owner = llGetOwner();		}	}	state_entry()	{		owner = llGetOwner();	}	touch_start(integer total_number)	{		if (llDetectedKey(0) == owner)		{			gLsn = llListen(31,"",owner,"");			llInstantMessage(owner,"To set a title: /31 title <color name> <title text>");			llInstantMessage(owner,"To remove title: /31 title off");			llInstantMessage(owner,"<color name> can be: white, black, red, green, blue, pink, cyan, purple, yellow, orange");		}	}	listen(integer channel, string name, key id, string message)	{		llListenRemove(gLsn);		list strings = llParseString2List(message,[" "],[]);		string command=llList2String(strings,0);		string string1=llList2String(strings,1);		if(command=="title")		{			vector color=<0,0,0>;			if(string1=="blue")			{				color=<0,0,1>;			}			else if(string1=="orange")			{				color=<1,0.5,0>;			}			else if(string1=="cyan")			{				color=<0,1,1>;			}			else if(string1=="pink")			{				color=<1,0,1>;			}			else if(string1=="green")			{				color=<0,1,0>;			}			else if(string1=="red")			{				color=<1,0,0>;			}			else if(string1=="white")			{				color=<1,1,1>;			}			else if(string1=="yellow")			{				color=<1,1,0.1>;			}			else if(string1=="purple")			{				color=<0.7,0,0.7>;			}			else			{				color=<0,0,0>;			}			string title = "";			integer i;			for(i=2; i<=12; i++)			{				if(llStringLength(llList2String(strings,i)))				{					title = title + llList2String(strings,i) + " ";				}			}			if(title == "off")			{				llSetText("",<0,0,0>,1.0);			}			else			{				llSetText(title, color, 1.0);			}		}	}}

 I have removed some unnecessary stuff (including the llResetScript statements), made it communicate on channel 31 instead of the public chat channel, turned on channel 31 only when you touch it and turned it off again as soon as you say the chat message.  It shouldn't hear a neighboring copy unless you touch that one too at the same time.

  • Like 1
Link to comment
Share on other sites

To my mind, this is an occasion when chat commands aren't a particularly good idea.   This sort of task is easier for the end user if you present her with some dialogs and text boxes, rather like this.

 

integer handle;integer dialogChan;integer textboxChan;integer i;integer Key2Number(key objKey) {    return ((integer)("0x"+llGetSubString((string)objKey,-8,-1)) & 0x3FFFFFFF) ^ 0x3FFFFFFF;}key owner;string command = "";string title;list main = ["Color","Title","Both","Clear Title","Finished"];list colours=[    "Blue",<0,0,1>,    "Orange",<1,0.5,0>,    "Cyan",<0,1,1>,    "Pink",<1,0,1>,    "Green",<0,1,0>,    "Red",<1,0,0>,    "White",<1,1,1>,    "Yellow",<1,1,0.1>,    "Purple",<0.7,0,0.7>,    "Black",<0.0,0.0,0.0>        ];vector color=<0.0,0.0,0.0>;default{    on_rez(integer n) { llResetScript(); }    state_entry()    {        owner = llGetOwner();        dialogChan = Key2Number(llGetKey());        textboxChan = dialogChan+1;    }    touch_start(integer total_number)    {        if (llDetectedKey(0) == owner)        {            llListenRemove(handle);            llDialog(owner,"What would you like to change?",main,dialogChan);            llSetTimerEvent(30.0);            handle = llListen(dialogChan,"",owner,"");//start listening        }    }    timer()    {        llSetTimerEvent(0.0);        llOwnerSay("Sorry, timed out.  Please touch me and try again");        llListenRemove(handle);//stop listening    }    listen(integer channel, string name, key id, string message)    {        if(dialogChan == channel){            command = message;            if(~llListFindList(main,[command])){//if the message is from the first, main, menu                if(~llListFindList(["Clear Title","Finished"],[command])){                    if ("Clear Title"==message){                        title="";//clear the title                        llSetText("",color,0.0);                    }                    llListenRemove(handle);                    llSetTimerEvent(0.0);                    return;                }                llSetTimerEvent(30.0);                if(~llListFindList(["Color","Both"],[command])){                    if("Both"==command){                        title="";                    }                    llDialog(owner,"Please choose a color",llList2ListStrided(colours,0,-1,2),dialogChan);                    return;                }                if("Title"==command){                    llListenRemove(handle);                    handle = llListen(textboxChan,"",owner,"");                    llTextBox(owner,"Please enter a title and click \"Submit\"",textboxChan);                    return;                }            }            else {                i = llListFindList(colours,[message]);//find the index of the message in the colours list                if(~i){// if it's not -1, then we've found the message                    color = llList2Vector(colours,(i+1));//and the appropriate vector is the next value                    if(title){//if we have a title                        llSetText(title,color,1.0);//set it                        llListenRemove(handle);//close the listener                        llSetTimerEvent(0.0);//turn off the timer                        return;//that's it                    }                    else{//no title, so ask for one                        llListenRemove(handle);                        handle = llListen(textboxChan,"",owner,"");                        llTextBox(owner,"Please enter a title and click \"Submit\"",textboxChan);                        return;                    }                }            }        }        if(textboxChan==channel){            title = message;            llSetText(title,color,1.0);//set it            llListenRemove(handle);//close the listener            llSetTimerEvent(0.0);//turn off the timer            return;//that's it        }    }}

This way, you don't have to worry about the channel, and the user doesn't need to type it.

 

  • Like 1
Link to comment
Share on other sites

hello Innula , thanks for the post. Have the option to change everything in a menu is fine, my problem is that I use two scripts in the same object, one to change the color of the object and the other to change the text, that is why I have it with chat command . I try to modify this script you posted but my knowledge of scripts will not let me: S. Trying to get the script changed the color of both the text and the object where it is, but every modification I do I always get error message I dont know what to write in the "vector", well, I dont have idea what I am doing lol, maybe for sure its all wrong. integer handle; integer dialogChan; integer textboxChan; integer i; integer Key2Number(key objKey) { return ((integer)("0x"+llGetSubString((string)objKey,-8,-1)) & 0x3FFFFFFF) ^ 0x3FFFFFFF; } key owner; string command = ""; string title; list main = ["Color","Title","Both","Ball Color","Clear Title","Finished"]; list colours=[ "Blue",<0,0,1>, "Orange",<1,0.5,0>, "Cyan",<0,1,1>, "Pink",<1,0,1>, "Green",<0,1,0>, "Red",<1,0,0>, "White",<1,1,1>, "Yellow",<1,1,0.1>, "Purple",<0.7,0,0.7>, "Black",<0.0,0.0,0.0> ]; list color_vectors=[ "Blue",<0,0,1>, "Orange",<1,0.5,0>, "Cyan",<0,1,1>, "Pink",<1,0,1>, "Green",<0,1,0>, "Red",<1,0,0>, "White",<1,1,1>, "Yellow",<1,1,0.1>, "Purple",<0.7,0,0.7>, "Black",<0.0,0.0,0.0> ]; vector color= default { on_rez(integer n) { llResetScript(); } state_entry() { owner = llGetOwner(); dialogChan = Key2Number(llGetKey()); textboxChan = dialogChan+1; } touch_start(integer total_number) { if (llDetectedKey(0) == owner) { llListenRemove(handle); llDialog(owner,"What would you like to change?",main,dialogChan); llSetTimerEvent(30.0); handle = llListen(dialogChan,"",owner,"");//start listening } } timer() { llSetTimerEvent(0.0); llOwnerSay("Sorry, timed out. Please touch me and try again"); llListenRemove(handle);//stop listening } listen(integer channel, string name, key id, string message) { if(dialogChan == channel){ command = message; if(~llListFindList(main,[command])){//if the message is from the first, main, menu if(~llListFindList(["Clear Title","Finished"],[command])){ if ("Clear Title"==message){ title="";//clear the title llSetText("",color,0.0); } llListenRemove(handle); llSetTimerEvent(0.0); return; } llSetTimerEvent(30.0); if(~llListFindList(["Color","Both"],[command])){ if("Both"==command){ title=""; } llDialog(owner,"Please choose a color",llList2ListStrided(colours,0,-1,2),dialogChan); return; } if("Title"==command){ llListenRemove(handle); handle = llListen(textboxChan,"",owner,""); llTextBox(owner,"Please enter a title and click \"Submit\"",textboxChan); return; } if("Ball Color"==command){ title=""; } llDialog(owner,"Please choose a color",llList2ListStride (color_vectors,0,-1,2),dialogChan); return; } } else { i = llListFindList(colours,[message]);//find the index of the message in the colours list if(~i){// if it's not -1, then we've found the message color = llList2Vector(colours,(i+1));//and the appropriate vector is the next value if(title){//if we have a title llSetText(title,color,1.0);//set it llListenRemove(handle);//close the listener llSetTimerEvent(0.0);//turn off the timer return;//that's it } else{//no title, so ask for one llListenRemove(handle); handle = llListen(textboxChan,"",owner,""); llTextBox(owner,"Please enter a title and click \"Submit\"",textboxChan); return; } } } } if(textboxChan==channel){ title = message; llSetText(title,color,1.0);//set it llListenRemove(handle);//close the listener llSetTimerEvent(0.0);//turn off the timer return;//that's it } } }

Link to comment
Share on other sites

they way I post for sure you can't understand , send again:

 

integer handle;
integer dialogChan;
integer textboxChan;

integer i;

integer Key2Number(key objKey) {
    return ((integer)("0x"+llGetSubString((string)objKey,-8,-1)) & 0x3FFFFFFF) ^ 0x3FFFFFFF;
}
key owner;

string command = "";

string title;

list main = ["Color","Title","Both","Ball Color","Clear Title","Finished"];

list colours=[
    "Blue",<0,0,1>,
    "Orange",<1,0.5,0>,
    "Cyan",<0,1,1>,
    "Pink",<1,0,1>,
    "Green",<0,1,0>,
    "Red",<1,0,0>,
    "White",<1,1,1>,
    "Yellow",<1,1,0.1>,
    "Purple",<0.7,0,0.7>,
    "Black",<0.0,0.0,0.0>
        ];

list color_vectors=[
    "Blue",<0,0,1>,
    "Orange",<1,0.5,0>,
    "Cyan",<0,1,1>,
    "Pink",<1,0,1>,
    "Green",<0,1,0>,
    "Red",<1,0,0>,
    "White",<1,1,1>,
    "Yellow",<1,1,0.1>,
    "Purple",<0.7,0,0.7>,
    "Black",<0.0,0.0,0.0>
        ];

vector color=
default
{
    on_rez(integer n) { llResetScript(); }

    state_entry()
    {
        owner = llGetOwner();
        dialogChan = Key2Number(llGetKey());
        textboxChan = dialogChan+1;


    }

    touch_start(integer total_number)
    {
        if (llDetectedKey(0) == owner)
        {
            llListenRemove(handle);
            llDialog(owner,"What would you like to change?",main,dialogChan);
            llSetTimerEvent(30.0);
            handle = llListen(dialogChan,"",owner,"");//start listening
        }
    }

    timer()
    {
        llSetTimerEvent(0.0);
        llOwnerSay("Sorry, timed out.  Please touch me and try again");
        llListenRemove(handle);//stop listening
    }

    listen(integer channel, string name, key id, string message)
    {
        if(dialogChan == channel){
            command = message;
            if(~llListFindList(main,[command])){//if the message is from the first, main, menu
                if(~llListFindList(["Clear Title","Finished"],[command])){
                    if ("Clear Title"==message){
                        title="";//clear the title
                        llSetText("",color,0.0);
                    }
                    llListenRemove(handle);
                    llSetTimerEvent(0.0);
                    return;
                }
                llSetTimerEvent(30.0);
                if(~llListFindList(["Color","Both"],[command])){
                    if("Both"==command){
                        title="";
                    }
                    llDialog(owner,"Please choose a color",llList2ListStrided(colours,0,-1,2),dialogChan);
                    return;
                }
                if("Title"==command){
                    llListenRemove(handle);
                    handle = llListen(textboxChan,"",owner,"");
                    llTextBox(owner,"Please enter a title and click \"Submit\"",textboxChan);
                    return;
                }
                if("Ball Color"==command){
                       title="";
                    }
                    llDialog(owner,"Please choose a color",llList2ListStride (color_vectors,0,-1,2),dialogChan);  
                    return;
                }
            }
            else {
                i = llListFindList(colours,[message]);//find the index of the message in the colours list
                if(~i){// if it's not -1, then we've found the message

                    color = llList2Vector(colours,(i+1));//and the appropriate vector is the next value
                    if(title){//if we have a title
                        llSetText(title,color,1.0);//set it
                        llListenRemove(handle);//close the listener
                        llSetTimerEvent(0.0);//turn off the timer
                        return;//that's it
                    }
                    else{//no title, so ask for one
                        llListenRemove(handle);
                        handle = llListen(textboxChan,"",owner,"");
                        llTextBox(owner,"Please enter a title and click \"Submit\"",textboxChan);
                        return;
                    }

                }
            }

        }
        if(textboxChan==channel){
            title = message;
            llSetText(title,color,1.0);//set it
            llListenRemove(handle);//close the listener
            llSetTimerEvent(0.0);//turn off the timer
            return;//that's it

        }
    }
}

Link to comment
Share on other sites

I think Tania wanted to combine two scripts; we know about the one that changes the text and its color, but there's another one that changes the color of the object. So, we might start with something like this:

integer handle;integer dialogChan;key owner;string title;list main = ["Title Color","Title","Finished","Ball Color"];list colours=[    "Blue",<0,0,1>,    "Orange",<1,0.5,0>,    "Cyan",<0,1,1>,    "Pink",<1,0,1>,    "Green",<0,1,0>,    "Red",<1,0,0>,    "White",<1,1,1>,    "Yellow",<1,1,0.1>,    "Purple",<0.7,0,0.7>,    "Black",<0.0,0.0,0.0>        ];vector color = <0.0,0.0,0.0>;   // for textinteger color4ball; // will new color apply to ball? (or text?)mainDialog(){    llDialog(owner,"What would you like to change?",main,dialogChan);    llSetTimerEvent(30.0);    handle = llListen(dialogChan,"",owner,"");//start listening}default{    on_rez(integer n) { llResetScript(); }    state_entry()    {        owner = llGetOwner();        dialogChan = -1000000000 - (integer)llFrand(1000000000.0);    }    touch_start(integer total_number)    {        if (llDetectedKey(0) == owner)        {            llListenRemove(handle);            mainDialog();        }    }    timer()    {        llSetTimerEvent(0.0);        llOwnerSay("Sorry, timed out.  Please touch me and try again");        llListenRemove(handle);//stop listening    }    listen(integer channel, string name, key id, string message)    {        if(~llListFindList(main,[message])) //if the message is from the first, main, menu        {            if("Finished"==message)            {                llListenRemove(handle);                llSetTimerEvent(0.0);                return;            }            llSetTimerEvent(30.0);            if(~llListFindList(["Title Color","Ball Color"],[message]))            {                if("Ball Color"==message)                    color4ball = TRUE;                else                    color4ball = FALSE;                llDialog(owner,"Please choose a color",llList2ListStrided(colours,0,-1,2),dialogChan);                return;            }            if("Title"==message)            {                llTextBox(owner,"Please enter a title and click \"Submit\"",dialogChan);                return;            }        }        integer i = llListFindList(colours,[message]); //find the index of the message in the colours list        if(~i)  // if it's not -1, then it's a color        {            vector inColor = llList2Vector(colours,(i+1));//and the appropriate vector is the next value            if (color4ball)                llSetColor(inColor, ALL_SIDES); // Assuming just one prim;            else            {                color = inColor;                llSetText(title,color,1.0); //set it            }        }        else    // it's a new title        {            title = message;            llSetText(title,color,1.0);//set it        }        mainDialog();    }}

It's a simple enough change if the object has more than one prim, or if the selection of object colors differs from that for the text, but I'm not sure whether either of those are a consideration here.

(Sorry, Innula, I made some totally arbitrary simplifications and format changes; hope I didn't break too much.)

  • Like 1
Link to comment
Share on other sites

Thanks Qie, yes, that was what I was trying to change the color and the text, in private chat Innula gave me a modification, different from what you did. And both help me a lot, because I'm learning different ways to change the same script, and I advance step by step in learning how to change the scripts, thanks :)

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 4119 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...