Jump to content

Object won't delete item


MSTRPLN
 Share

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

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

Recommended Posts

Hello, I'm making a kind of unusual script/system, i will explain.

Intro:
I have 2 items: Prim and a HUD

Prim contains: HUD & script: "HUD_Receiver"
HUD Contains: script: "HUD_transmittor" (the HUD also contains out of 5 prims, 4 with actions)

Within the HUD i have a button to delete all objects out of the 1st prim (including the HUD & HUD_receiver script)

The thought behind it is..

I have a prim that i want to be able to change it's textures with a HUD so the main action will be changing textures. One button to detach the HUD but also a button to delete everything from the prim once satisfied (why? because this will be a modular prim, copied multiple times within a region)

Issues:

1. When clicking on the "delete" button it would detach the HUD before it would send the message to the prim
Fix: Sending the  "Detach" function through a timer event to a 2nd state, the timer waits 2 seconds for the object to deliver the message then detach

2. With issue 1 fixed it now won't delete the (object) "HUD" itself anymore.

3. Changing the channels from -50504 to a random number, the script won't work anymore (that's why the random number is disabled) ie:
// gChan = -1 * (integer)llFrand(1000000.0) - 345; (yes i know it says gChan instead of channel that's not the issue)

 

Scripts:

// Script for texture changer receiver
integer channel = -50504;
// Channel is the integer for reception (number mus the same as a transmission channel otherwise script will not work)

delete_all_other_contents()
{
    string thisScript = llGetScriptName();
    string inventoryItemName;
 
    integer index = llGetInventoryNumber(INVENTORY_ALL);
    while (index)
    {
        --index;        // (faster than index--;)
 
        inventoryItemName = llGetInventoryName(INVENTORY_ALL, index);
 
        if (index > 0)   
            llRemoveInventory(inventoryItemName);
            llRemoveInventory(thisScript);
            llOwnerSay("Everything removed.");
    }
}

default
{
        state_entry()
        {
            llListen(channel, "", NULL_KEY, "");
        }
        
        touch_start(integer total_number)
        {
            llRezObject("HUD", llGetPos() + <0.0,0.0,1.0>, <0.0,0.0,0.0>, <0.0,0.0,0.0,1.0>, 0);
        }
        
        listen(integer channel, string name, key id, string msg)
        {
            
            if (llGetOwner() == llGetOwnerKey(id))
            // Checks if the owner of the object who is sending a message its the same owner of the receiver
            {
                // Front Face
                if (msg == "tex1")  llSetTexture("2433879f-6116-1521-38c0-eb86f2ce607a", 4);
                if (msg == "tex2")  llSetTexture("9fc13d27-47b6-1a0a-4262-7ab9e52ffc65", 4);
                // Else
                if (msg == "die")
                {
                    delete_all_other_contents();
                }
            }
        }    
}

Above script goes into the main prim (contents: HUD + above script)

 

// Choose any number up for 1024 as the channel for the transmission
integer channel = -50504;
// Delay in seconds
float delay = 2.0;

default
{
    on_rez(integer star_param)
    {
        llRequestPermissions( llGetOwner(), PERMISSION_ATTACH );
        llSetAlpha(0, ALL_SIDES);
        llSetLinkAlpha(LINK_SET, 0, ALL_SIDES);
        
        // gChan = -1 * (integer)llFrand(1000000.0) - 345;  // gChan is a global integer
    }
    
    run_time_permissions(integer perm)
    {
        if(PERMISSION_ATTACH & perm)
        {
            llAttachToAvatarTemp(ATTACH_HUD_CENTER_1);
            llOwnerSay("Attached.");
            llSetAlpha(1, ALL_SIDES);
            llSetLinkAlpha(LINK_SET, 1, ALL_SIDES);
        }
        else {
            llSay(0,"Not attached :(");
        }
                    
    }
    
     touch_end(integer tn)
    {
        if (llDetectedLinkNumber(0) == 3)
        {
            llRegionSay(channel, "tex1");
        }
        else if (llDetectedLinkNumber(0) == 2)
        {
            llRegionSay(channel, "tex2");
        }
        else if (llDetectedLinkNumber(0) == 5)
        {
            state two;
        }
        else if (llDetectedLinkNumber(0) == 4)
        {
            llRegionSay(channel, "die");
            llSetTimerEvent(delay);
        }
    }
    
    timer()
    {
        state two;
    }
}

state two
{
    state_entry()
    {
       llDetachFromAvatar();
    }
}

Above script goes inside the "HUD" object

 

I might be missing something and i need a break, any help would be more than helpfull!

Please keep in mind that these are just placeholders, the finished product would be the Mesh item itself & a stylized HUD

Object.png

HUD.png

Edited by MSTRPLN
Link to comment
Share on other sites

I haven't tried very hard to understand what's intended here, but I notice that the first script starts with a function containing the conditional "if (index > 0)" followed by three indented statements -- but those aren't enclosed in a "{" "}" block, so only the first is conditionalized -- the other two will run each time through the while loop -- which will be just once, because one of those statements deletes the script itself.

Link to comment
Share on other sites

Yeah, furthermore if the script is the second item in the inventory (index == 1) it will delete the script at first.

if you want to just delete everything, just do:

 integer index = llGetInventoryNumber(INVENTORY_ALL);
        while(index--)
        {
            string sN = llGetInventoryName(INVENTORY_ALL, index);
            if (sN != llGetScriptName())
            {
                llRemoveInventory(sN);
            }
        }
        llRemoveInventory(llGetScriptName());

 

Link to comment
Share on other sites

For #1 a brief llSleep(delay) before the detach would do it instead of the state change.

For #3. Not sure what the problem with that is? The channels will have to be kept the same in both scripts indeed. So if you do a random channel in the receiver, you'll have to pass that to the rezzed HUD. As the on_rez param for example.

Link to comment
Share on other sites

3 hours ago, arton Rotaru said:

 


 integer index = llGetInventoryNumber(INVENTORY_ALL);
        while(index--)
        {
            string sN = llGetInventoryName(INVENTORY_ALL, index);
            if (sN != llGetScriptName())
            {
                llRemoveInventory(sN);
            }
        }
        llRemoveInventory(llGetScriptName());

 

Ugh i had the above example but without deleting the script after it, i dont know why i forgot about that & thanks alot for the llSleep function! that makes things alot easier (i used llSleep(2.0)

Link to comment
Share on other sites

In case you want to target only the object you rezzed the HUD from, you could do

 key kRezzer = llList2Key(llGetObjectDetails(llGetKey(), [OBJECT_REZZER_KEY]), 0)

to get the rezzers key in the HUDs on_rez, and send messages with llRegionSayTo, instead of llRegionSay using random channels.

Just a thought...

Edited by arton Rotaru
Link to comment
Share on other sites

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