Jump to content

[Answered] Change texture by UUID with dialog


MSTRPLN
 Share

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

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

Recommended Posts

Hi there!

I've been looking around but havent really found what i was lookign for.

I have this backdrop that i made and i want people to be able to change the texture on one face by pasting a UUID or somehow since the product is no-mod

backdrop: (wan to be able to let customers change the green face)

What i'm lookign for:

 

Could anyone be kind to give me a push in the right direction or help me with this? Thanks in advance!

Sincerely, Chris

Link to comment
Share on other sites

It looks like you almost have the script finished.  Once the user has entered a UUID in the text box, all you have to do is apply it to the face you're interested in.  So, your listen event would contain something like this:

listen (integer channel, string name, key id, string message){    llSetLinkTexture(link_number,message,face_number);}

 

Link to comment
Share on other sites

I think i have it, it works atleast if the code is valid enough i don't know.

 

integer vListener;default{    touch_start(integer num_detected)    {        integer face = llDetectedTouchFace(0);;                if ( llDetectedKey(0) == llGetOwner())        {            if ( face == 4)            {                integer channel = -13572468;                vListener = llListen( channel, "", "", "");                 llTextBox(llDetectedKey(0), "Please enter the UUID of the texture you want as background.", channel);               }                        else            {                            }         }                else        {            llSay(0, "You're not the owner, you can't change the texture.");             }    } listen (integer channel, string name, key id, string message)    {        llSetTexture(message,4);    }}
Link to comment
Share on other sites

The best way to tell is to see if it works. If it does, then you are at least 60% pf the way to success.  Then you can start plugging holes by asking questions:

Every time someone touches the object, it opens a new listen handler. How am I going to keep from opening so many that the script stalls? (The maximum allowed is 64.)

What if the owner types something other than a valid UUID in the text box?

What if the owner opens a text box but doesn't type anything in it?

Should I put a default texture UUID in the script?  When would I want the default to appear, if I did?

What if the user wanted to change the color as well as the texture?

Dop I really care what happens if the owner touches some other face?

Keep asking questions until the script feels "foolproof" and versatile enough. 

BTW, this script will almost work.  It has an extra semicolon, though.  ;)

 

 

 

Link to comment
Share on other sites

Every time someone touches the object, it opens a new listen handler. How am I going to keep from opening so many that the script stalls? (The maximum allowed is 64.)

Haven't really thought about that, any insights about how to avoid this? Although the script only works for the owner (Detect owner)

What if the owner types something other than a valid UUID in the text box?

Hmm i havent thought about that i'll try this with an if/else

What if the owner opens a text box but doesn't type anything in it?

Im gonna implement this somehow

Should I put a default texture UUID in the script?  When would I want the default to appear, if I did?

Good one! i think i can do this with a reset that changes the script back idk

What if the user wanted to change the color as well as the texture?

Im not allowing that only texture else it'll get too complex i could do this with an dialog menu with a few color options & texture option

Dop I really care what happens if the owner touches some other face?

No/yes i want it also to have an resize script im going to script later on but i could also make a prim text that when clicked would activate that seperate script

Link to comment
Share on other sites

I'm sure you can think of more questions, either to protect your script from clumsy users or to make it more flexible.  That's where the fun of scripting is, IMO.  Getting it to work is just the start.

BTW, the generic answer to the first question is to close the listen handler as soon as you don't need it any more.

Link to comment
Share on other sites

Alright, thnak you very much :)

 

 

I took a different approach.

// Example made by Kahiro Watanabe, visit modernclix.info for lsl and php/mysql tutorials// You can share this script with anyoneinteger listener;  // Listener for handling different channelsinteger simpleMenuChannel; // The channel used for the menu// Function that returns a random number (used for generating a random channel)integer randomNumber(){    return((integer)(llFrand(99999.0)*-1));}menu(key id, integer channel, string title, list buttons) // Generic menu creator{    llListenRemove(listener);    listener = llListen(channel,"",id,"");    llDialog(id,title,buttons,channel);    llSetTimerEvent(10.0);   // if no menu button is pressed in 20 seconds the timer is triggered to kill the listener}simpleMenu(key id) // This function calls the menu creator{    simpleMenuChannel = randomNumber();    menu(id,simpleMenuChannel,"Select an option",["A","B"]);}default{    touch_start(integer num)    {        simpleMenu(llDetectedKey(0));    }    listen (integer channel, string name, key id, string message)    {        if (message == "A")        {            llTextBox(id, "Please enter a message and click Submit", -165);            //do something else here            llSetTexture(message,4);        }        else if (message == "B")        {            llSetTexture("792477f4-e765-e9ec-6bd8-dc228951b7e2", 4);                //do something else here        }        // simpleMenu(id); refresh menu    }    timer()    {        llListenRemove(listener); // kill the listener        llSetTimerEvent(0.0); // stop the timer    }        changed(integer mask)    {   //Triggered when the object containing this script changes owner.        if(mask & CHANGED_OWNER)        {            llResetScript();   // This will ensure the script listens to the new owner, and doesn't continue listening to the creator.        }    }}

It's working so far the only problem is: The llSetTexture takes the message of the llDialog which is "A" so i get an error saying "Texture A cannot be found" i have absolutely no clue how to seperate the conflicts.

 

I've tried: 

llTextBox(id, "Please enter a message and click Submit", -165);            //do something else here            if( channel == -165) {            llSetTexture(message,4);            }

But unforunately nothing happend

Link to comment
Share on other sites

It already uses an if and else if to detect what button is pressed.

if i put another one it doesn't do anything i can;t figure out why

listen (integer channel, string name, key id, string message)    {        if (message == "A")        {            llTextBox(id, "Please enter a message and click Submit", -165);            //do something else here            if(channel == -165) {            llSetTexture(message,4);            }        }        else if (message == "B")        {            llSetTexture("792477f4-e765-e9ec-6bd8-dc228951b7e2", 4);                //do something else here        }        // simpleMenu(id); refresh menu    }

 

Right now im trying to filter the message on a valid uuid but it's very confusing. if(uuid) gived me an error "name not defined within scope" and this doesn't work either:

 

listen (integer channel, string name, key id, string message)    {        if (message == "A")        {            llTextBox(id, "Please enter a message and click Submit", -165);            //do something else here            message = (key)message;            if(message) {            llSetTexture(message,4);            } else { llSay(0, "You didn't enter a valid UUID");}        }        else if (message == "B")        {            llSetTexture("792477f4-e765-e9ec-6bd8-dc228951b7e2", 4);                //do something else here        }        // simpleMenu(id); refresh menu    }
Link to comment
Share on other sites

That's one of the challenges of trying to modify someone else's script instead of writing your own,  You have to figure out the other person's logic. This scripter apparently likes to put a lot of things into unnecessary user-defined functions, which makes it harder to trace through the logic. Innula's right. You need to filter the channel before you do anything else in the listen event.  You're trying to do it in the wrong place.

Link to comment
Share on other sites

When in doubt, start adding diagnostic messages to your script at key points to let the script tell you what values are being assigned to specific variables.  You might also try drawing yourself a simple flow diagram to map the logic of your script, to help visualize what's happening.

In this case, if you are using the channel number as your way to distinguish between a textbox message and a simple menu message, you'll want to test for channel number before you test for the message itself.

Note, in passing, that

message = (key) message;

is never going to work.  You can't typecast a variable to a different type of itself (but you can assign a new variable to a typecast version of an existing one).

Link to comment
Share on other sites

Okay so i've rearranged the messages to show me werther it works or not

if (message == "A")        {            llTextBox(id, "Please enter a message and click Submit", -165);            //do something else here            if(channel == -165) {            llSay(0, "It works ");            //llSetTexture(message,4);            } else { llSay(0, "It didnt work ");}        }

what i now get is:

When i click button A it imidiately says "It didnt work :(" Im not sure if i could tell the "It works/It didnt work" to wait until it receives a new message from the channel -165

Link to comment
Share on other sites

Edited to make change to listener

This is the sort of script logic you need, I think:

integer iMenuChannel = 123;integer iTextBoxChannel = 456;integer iListener;default{	state_entry()	{	}			touch_start(integer total_number)	{		llListenRemove(iListener);//close any stray listeners		key toucher = llDetectedKey(0);		iListener = llListen(iMenuChannel,"",toucher,""); //nb changed line		llDialog(toucher,"Please choose an option",["A","B"], iMenuChannel);	}	listen(integer channel, string name, key id, string message)	{		llListenRemove(iListener);				if (iMenuChannel == channel){			if("A" == message){				//open listener on iTextBoxChannel and do stuff to make a text box appear			}			else if ("B" == message){			  llSetTexture("792477f4-e765-e9ec-6bd8-dc228951b7e2", 4);			}		}		else if (iTextBoxChannel == channel){			//message from the text box.			//verify that the message is a key and, if it is, apply it to face 4		}	}}

 

  • Thanks 1
Link to comment
Share on other sites


MSTRPLN wrote:

[ .... ]

When i click button A it imidiately says "It didnt work
:(
" Im not sure if i could tell the "It works/It didnt work" to wait until it receives a new message from the channel -165

Right, so that tells you that channel != -165 at that point.  It can't be, because the message that was just received is on your main menu channel.  You won't receive one from the text box until you send it.  All that the llTextBox command does is to create the text box.

Innula's example tests for the channel number first, as I suggested earlier. ;)

Link to comment
Share on other sites

oh! now i get it. i thought i had to execute the llTextBox' message within the same structure but it's actually outside of it.

Thank you very much, this gives me a clear answer to script any further. I'll also try to see if i can valiudate if it has a valid UUID (not sure if it lets me use "if(uuid)" now or not.

Link to comment
Share on other sites


MSTRPLN wrote:

oh! now i get it. i thought i had to execute the llTextBox' message within the same structure but it's actually outside of it.

Thank you very much, this gives me a clear answer to script any further. I'll also try to see if i can valiudate if it has a valid UUID (not sure if it lets me use "if(uuid)" now or not.

Glad to help.   For checking valid UUIDs, see the Wiki example here (you're right -- if (uuid) will work, but there's a tweak you might want to know about, too -- it's not partiularly relevant here, but it's worth knowing).

Link to comment
Share on other sites

A simpler way to do it, if you prefer, might be

	touch_start(integer total_number)	{		llListenRemove(iListener);//close any stray listeners		key toucher = llDetectedKey(0);		iListener = llListen(iMenuChannel,"",toucher,"");		llDialog(toucher,"Please choose an option",["A","B"], iMenuChannel);	}	listen(integer channel, string name, key id, string message)	{		llListenRemove(iListener);		key kTexture = "792477f4-e765-e9ec-6bd8-dc228951b7e2";		if("A" == message){			//open listener on iTextBoxChannel and do stuff to make a text box appear		}		else{			if((key)message){//the message is a valid uuid				kTexture = (key)message;			}			llSetTexture(kTexture,4);		}	}

This means, if the message is "A ," put up a text box, and otherwise either use the message as the texture if the message is a valid uuid or otherwise use the default "792477f4-e765-e9ec-6bd8-dc228951b7e2" texture if it's not (whether it's B or something the user has entered that's not a UUID).

Link to comment
Share on other sites

i've read it and it gives me a "Name not defined within scope" unless i put at the top "key uuid = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";

In that case it works, but it would only allow "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" any other UUID's will render as:

else { llInstantMessage( llGetOwner(),"Not a valid UUID"); }

 

Just so there will not be any misscomunicatio this is the code so far:

 

integer iMenuChannel = 123;integer iTextBoxChannel = 486;integer iListener;key uuid = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";default{    state_entry()    {    }            touch_start(integer total_number)    {        integer face = llDetectedTouchFace(0);;        if ( face == 4 ) {        llListenRemove(iListener);//close any stray listeners        key toucher = llDetectedKey(0);        llListen(iMenuChannel,"",toucher,"");        llDialog(toucher,"Please choose an option",["Texture","Reset"], iMenuChannel);        } else {        }    }    listen(integer channel, string name, key id, string message)    {        llListenRemove(iListener);                if (iMenuChannel == channel){            if("Texture" == message){                llListenRemove(iListener);//close any stray listeners                key toucher = llDetectedKey(0);                llListen(iTextBoxChannel,"",toucher,"");                llTextBox(id, "Please enter a message and click Submit", iTextBoxChannel);                //open listener on iTextBoxChannel and do stuff to make a text box appear            }            else if ("Reset" == message){              llSetTexture("792477f4-e765-e9ec-6bd8-dc228951b7e2", 4);            }        }        else if (iTextBoxChannel == channel){            if(uuid){            llSetTexture(message,4);            } else {                llInstantMessage( llGetOwner(),"Not a valid UUID");            }            //message from the text box.            //verify that the message is a key and, if it is, apply it to face 4        }    }}

 

Unless im doing something wrong maybe i can put a few filters that check if, the entered text contains 36 characters (UUID has 36) and maybe even some other thigns but i'll have to dig deeper for that. i really appreciate you all helping me in the right direction while still letting me figure things out.

Link to comment
Share on other sites

Sorry, I didn't make myself clear.   If you're using the literal "uuid" as a variable, it has to be defined somewhere.  so

	listen(integer channel, string name, key id, string message)	{		key uuid = (key) message;		if(uuid){		}		else{			llOwnerSay("Not a valid uuid.");		}		}

should compile, and so should

	listen(integer channel, string name, key id, string message)	{		if((key)message){		}		else{			llOwnerSay("Not a valid uuid.");		}		}
Link to comment
Share on other sites

That's interesting, so in this case "message" after the (key) makes all the difference. i wish the wiki was more explained to avoid these senarios.

 

One more last question, is there a way to make the channels random? Since if you would have 2 backdrops on a land with the same script in it it woudl change the texture on both of them (i know i can just manually change them but i'd rather it to be automated)

 

i've tried a few including http://wiki.secondlife.com/wiki/LlDialog#Tips but it gives this error, not sure why since it's o the wiki.

Link to comment
Share on other sites

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