Jump to content

Back again with a simple? ask ... loading a random vs default image onto a prim face


Katherine Heartsong
 Share

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

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

Recommended Posts

This scripts successfully loads a random image on the clicked face from the content of a prim:

default
{
    touch_start(integer total_number)
    {
        integer face = llDetectedTouchFace(0);
        integer textureindex = (integer)llFrand(llGetInventoryNumber(INVENTORY_TEXTURE));
        llSetLinkPrimitiveParamsFast(llGetLinkNumber(),[PRIM_TEXTURE,face,llGetInventoryName(INVENTORY_TEXTURE,textureindex),<1.0, 1.0, 0.0>, <0.0, 0.0, 0.0>, 0.0]);        
    }
}

Can someone show me how to modify it so that it shows a blue drop down menu with two buttons that read "Default" and "Random"?

Clicking the random does that shown above, and "Default" would load/show an image called "default-1" from the contents.

Thanks!

 

Link to comment
Share on other sites

Assuming you just want the standard issue SL dialog box, this should work:

integer last_face; // store the last clicked face
integer last_prim; // last clicked prim

integer listen_handle;

integer CHANNEL = -3881; // channel for dialogs

default
{
    touch_start(integer total_number)
    {
        last_face = llDetectedTouchFace(0); // store the face number to be handled
        last_prim = llDetectedLinkNumber(0); // store the prim number
        llSetTimerEvent(10); // allow 10 seconds before timing out the listener
        llListenRemove(listen_handle); // release any open listen handle
        listen_handle = llListen(CHANNEL, "", llDetectedKey(0), ""); // listen to the toucher
        llDialog(llDetectedKey(0), "Random or default?", ["Random", "Default"], CHANNEL); // dialog
    }
    
    timer()
    {
      	llSetTimerEvent(0); // stop timer
        llListenRemove(listen_handle); // close listen handle
    }
    
    listen(integer channel, string name, key id, string msg)
    {
      	string texture_name = "default-1"; // default texture is, uh, default
        llListenRemove(listen_handle); // close listen handle
        if(msg == "Random") // random texture
        {
            integer textureindex = (integer)llFrand(llGetInventoryNumber(INVENTORY_TEXTURE));
            texture_name = llGetInventoryName(INVENTORY_TEXTURE,textureindex);
        }
        llSetLinkPrimitiveParamsFast(last_prim,[PRIM_TEXTURE,last_face,texture_name,<1.0, 1.0, 0.0>, <0.0, 0.0, 0.0>, 0.0]);
    }
}

In more detail, instead of assigning the random texture on click, it will instead store the clicked prim and face, open a dialog with a listener for it and wait for the user to choose random or default.

On choosing random, it uses the same code as in your example to assign the random texture from inventory (note: I changed it to retexture the prim that was clicked, not the prim the script is in; changing "last_prim" to "LINK_THIS" in the primitiveparams calls restores the original functionality).

On choosing default, it will just use the texture named "default-1" from inventory instead.

If no choice is made within 10 seconds, the listener is closed and the dialog will no longer do anything.

Edited by Frionil Fang
optimized a little
  • Thanks 2
Link to comment
Share on other sites

18 minutes ago, Love Zhaoying said:

If I understand correctly, simulating a "drop down menu" with a prim would require a second prim to display the "menu buttons", which prim you could show/hide/move as needed.

I meant standard blue dialogue box, apologies.

8 minutes ago, Frionil Fang said:

Assuming you just want the standard issue SL dialog box, this should work:

integer last_face; // store the last clicked face
integer last_prim; // last clicked prim

integer listen_handle;

integer CHANNEL = -3881; // channel for dialogs

default
{
    touch_start(integer total_number)
    {
        last_face = llDetectedTouchFace(0); // store the face number to be handled
        last_prim = llDetectedLinkNumber(0); // store the prim number
        llSetTimerEvent(10); // allow 10 seconds before timing out the listener
        llListenRemove(listen_handle); // release any open listen handle
        listen_handle = llListen(CHANNEL, "", llDetectedKey(0), ""); // listen to the toucher
        llDialog(llDetectedKey(0), "Random or default?", ["Random", "Default"], CHANNEL); // dialog
    }
    
    timer()
    {
      	llSetTimerEvent(0); // stop timer
        llListenRemove(listen_handle); // close listen handle
    }
    
    listen(integer channel, string name, key id, string msg)
    {
      	string texture_name = "default-1"; // default texture is, uh, default
        llListenRemove(listen_handle); // close listen handle
        if(msg == "Random") // random texture
        {
            integer textureindex = (integer)llFrand(llGetInventoryNumber(INVENTORY_TEXTURE));
            texture_name = llGetInventoryName(INVENTORY_TEXTURE,textureindex);
        }
        llSetLinkPrimitiveParamsFast(last_prim,[PRIM_TEXTURE,last_face,texture_name,<1.0, 1.0, 0.0>, <0.0, 0.0, 0.0>, 0.0]);
    }
}

In more detail, instead of assigning the random texture on click, it will instead store the clicked prim and face, open a dialog with a listener for it and wait for the user to choose random or default.

On choosing random, it uses the same code as in your example to assign the random texture from inventory (note: I changed it to retexture the prim that was clicked, not the prim the script is in; changing "last_prim" to "LINK_THIS" in the primitiveparams calls restores the original functionality).

On choosing default, it will just use the texture named "default-1" from inventory instead.

If no choice is made within 10 seconds, the listener is closed and the dialog will no longer do anything.

Thank you! I can roughly read the flow and many thanks!

  • Thanks 1
Link to comment
Share on other sites

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