Jump to content

I am kinda stuck...


Fritigern Gothly
 Share

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

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

Recommended Posts

I have been a scripter for a long time, and usually manage to figure out my problems with the use of the advice from the good people of a scripting group, the wiki, but mostly do I figure stuff out on my own.

However, this time I am rather stumped.

What I want to do is have an attachment which does one thing when attached, and another thing when rezzed. Having both things happen at the same time is very much undesired.

default
{  
    attach(key id)
    {
        llOwnerSay("[ATTACH]");
        if(id != NULL_KEY) // Prevent the next bit to run upon detach.
        {
            // Do stuff
        }
    }
    
    on_rez(integer s)
    {
        llOwnerSay("[ON REZ]");
        // Do different stuff.
    }
}

My issue though is that when I  attach the object, the on_rez event fires first, and then the attach event. If it were the other way around, I could have used a flag to prevent the on_rez event from executing (if(flag = TRUE) return;) but right now, I am kinda lost.

Am I just having a severe case of caffeine withdrawal, or is this really a tricky one?

Edited by Fritigern Gothly
Link to comment
Share on other sites

in the on rez event, use llGetAttached to get the attachment point. if it's not attached it will be 0

default
{  
    attach(key id)
    {
        llOwnerSay("[ATTACH]");
        if(id != NULL_KEY) // Prevent the next bit to run upon detach.
        {
            // Do stuff
        }
    }
    
    on_rez(integer s)
    {
	if(llGetAttached() != 0)return;
        llOwnerSay("[ON REZ]");
        // Do different stuff.
    }
}

 

Edited by Ruthven Willenov
  • Like 2
  • Thanks 1
Link to comment
Share on other sites

2 minutes ago, Ruthven Willenov said:

in the on rez event, use llGetAttached to get the attachment point. if it's not attached it will be 0

 

OMG! You and Rolig are right!!! Why did I not think of that?
Thank you guys so much!!!!!

*Goes to get herself some coffee before fixing her script*

Edited by Fritigern Gothly
Link to comment
Share on other sites

1 minute ago, KT Kingsley said:

If this is a worn object that rezzes when the avatar logs in, you can check llGetAgentSize, which will return ZERO_VECTOR for a few moments until the sim comes to terms with its existence.

Thanks, I will consider that option too!

Now I have two ways to fix my problem! :D 

Edited by Fritigern Gothly
Link to comment
Share on other sites

After about an hour for fooling around I ran into an issue which is strongly related.

I have played around with the llGetAgentSize() option for a bit, but that would increase the complexity of the script, as I would have to test for the avatar UUID in each event,  but I am still grateful for the suggestion.

So now I have I've implemented the llGetAttached() solution as follows:

    on_rez(integer s)
    {
        if(llGetAttached() == 0) {
            llOwnerSay("[ON REZ]");
            // Do different stuff.
        }
    }

And that works for when I attach the object, it also works when I rez the item from inventory, but when I drop the item in-world from a worn status, it behaves as if it is still attached.
In other words, if I drop the attachment, llGetAttached() prevents the on_rez event from firing, but if I remove the test, then on_rez fires when I attach them item.
I can't seem to win here because I want on_rez to fire even when the item gets dropped. What am I missing? Is there a function or perhaps even an event that I could use that I am overlooking?

P.S. from what I see so far, I don't think that the result would be any different if I had used the llGetAgentSize() option. Again, I am grateful for all suggestions!

Link to comment
Share on other sites

maybe this?

http://wiki.secondlife.com/wiki/Attach#Caveats

  • When detaching an object, llGetAttached() returns 0, but the same happens when dropping an object from an attachment point to the ground. No other indicative event is triggered in the latter case; in particular, the on_rez event is not triggered for attachment drops. If you need to distinguish a drop from a detach, a possible hack is to check llGetObjectPrimCount(llGetKey()). If it's zero, it can be assumed that the object is being detached; otherwise, that it is being dropped.
  • Thanks 2
Link to comment
Share on other sites

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