Jump to content
Fritigern Gothly

I am kinda stuck...

Recommended Posts

Posted (edited)

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

Share this post


Link to post
Share on other sites
Posted (edited)

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

Share this post


Link to post
Share on other sites

I'm away from home and on a mobile phone so I can't test anything, but can you just add an if text in the on_rez event to see whether

if (llGetAttached() == -1) // Don't execute the on_rez stuff

?

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites
Posted (edited)
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

Share this post


Link to post
Share on other sites

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.

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites
Posted (edited)
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

Share this post


Link to post
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!

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...