Jump to content

Unpacker script - unpacks twice


ainst Composer
 Share

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

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

Recommended Posts

Hello! There is such a script unpacker. for me it works fine, but when I give it to a friend, the first time it unpacks twice, and then as usual. why it happens?

list lContents;
string strFolderName = "A folder of goodies";// change to the name you want for your folder

default {
    state_entry() {//some preliminary work to set things up
        //first, populate the lContents list
        string strThisScript = llGetScriptName();//note the name of this script, since you don't want to give that as part of the folder
        integer max = llGetInventoryNumber(INVENTORY_ALL);//note the number of items in the object's inventory
        integer counter = 0;
        do{
            string str = llGetInventoryName(INVENTORY_ALL, counter);//check the name of each item
            if(str!=strThisScript){//and if it's not this script
                lContents +=[str];//add the name to lContents
            }
        }
        while(++counter < max);//and keep on doing this, advancing the counter each time, until  all items have been checked.
        if(llStringLength(strFolderName)== 0){//sanity check -- if no folder name is provided
            strFolderName = llGetObjectName();//then use the name of this object for the folder
        }
    }

    changed(integer change) {
        if(change & CHANGED_INVENTORY){//if the contents of the object's inventory change
            llResetScript();//then reset the script in order to rebuild the list
        }
        else if(change & CHANGED_OWNER){//if the object's owner changes, give the folder to the new owner
            llGiveInventoryList(llGetOwner(), strFolderName,lContents);//give the folder to the new owner
        }
    }

    attach(key id) {
       if(id){//if someone attaches the object
            llGiveInventoryList(id, strFolderName,lContents);//give them the folder
       } 
    }


}

 

Link to comment
Share on other sites

3 minutes ago, Wulfie Reanimator said:

Wild guess, but it's probably because the attach event triggers when your friend attaches it and they get the lContents... and then the changed event triggers because of new owner, giving them the lContents again.

Thanks very much for your answer! is there any way to fix it?

 

Link to comment
Share on other sites

11 minutes ago, ainst Composer said:

Thanks very much for your answer! is there any way to fix it?

Another guess (I can't get in-world to test), but I don't think you need to give the contents on CHANGED_OWNER. The attach event by itself is enough, it will work even without resetting the script.

Edit: Yes, you did it right.

Edited by Wulfie Reanimator
  • Like 1
  • Thanks 1
Link to comment
Share on other sites

Just now, Wulfie Reanimator said:

Another guess (I can't get in-world to test), but I don't think you need to give the contents on CHANGED_OWNER. The attach event by itself is enough, it will work even without resetting the script.

Thanks very much again! I just removed lines:

else if(change & CHANGED_OWNER){//if the object's owner changes, give the folder to the new owner
 llGiveInventoryList(llGetOwner(), strFolderName,lContents);//give the folder to the new owner
}

And everything works fine. Did i do right?

  • Like 1
Link to comment
Share on other sites

That looks like a script I've posted somewhere (my style of formatting and the sort of comments I put in public examples).   

If it is, then clearly I missed out a test in the changed event, to ensure the script gives the folder there only if it's rezzed on the ground rather than attached to the avatar.   Something like this:

list lContents;
string strFolderName = "A folder of goodies";// change to the name you want for your folder

default {
	state_entry() {//some preliminary work to set things up
		//first, populate the lContents list
		string strThisScript = llGetScriptName();//note the name of this script, since you don't want to give that as part of the folder
		integer max = llGetInventoryNumber(INVENTORY_ALL);//note the number of items in the object's inventory
		integer counter = 0;
		do{
			string str = llGetInventoryName(INVENTORY_ALL, counter);//check the name of each item
			if(str!=strThisScript){//and if it's not this script
				lContents +=[str];//add the name to lContents
			}
		}
		while(++counter < max);//and keep on doing this, advancing the counter each time, until  all items have been checked.
		if(llStringLength(strFolderName)== 0){//sanity check -- if no folder name is provided
			strFolderName = llGetObjectName();//then use the name of this object for the folder
		}
	}

	changed(integer change) {
		if(change & CHANGED_INVENTORY){//if the contents of the object's inventory change
			llResetScript();//then reset the script in order to rebuild the list
		}
		else if(change & CHANGED_OWNER){//if the object's owner changes, give the folder to the new owner
			if(!llGetAttached()) {//if the object is not attached
				llGiveInventoryList(llGetOwner(), strFolderName,lContents);//give the folder to the new owner
			}
		}
	}

	attach(key id) {
		if(id){//if someone attaches the object
			llGiveInventoryList(id, strFolderName,lContents);//give them the folder
		}
	}


}

 

 

  • Thanks 1
Link to comment
Share on other sites

25 minutes ago, Kyrah Abattoir said:

This is completely off topic but... after looking at what your script does... why not use the builtin unpack function (default click action to "open")?

I stopped using that type of script long ago. I do not even box contents on the MP. It passes a file with everything in it. If the container was for unrestricted passing inworld then i would. Simply doing the way you described is far less hassle.

  • Like 1
Link to comment
Share on other sites

1 hour ago, Kyrah Abattoir said:

This is completely off topic but... after looking at what your script does... why not use the builtin unpack function (default click action to "open")?

Because shop owners who don't have areas in their shops where rezzing is allowed  frequently say that their customers prefer to be able to attach a box containing the item(s) and have the contents appear in their inventories rather than have to take it home to unpack.   Often these boxes are in the form of a shopping bag, complete with holding animation.

Edited by Innula Zenovka
  • Thanks 1
Link to comment
Share on other sites

25 minutes ago, Innula Zenovka said:

Because shop owners who don't have areas in their shops where rezzing is allowed  frequently say that their customers prefer to be able to attach a box containing the item(s) and have the contents appear in their inventories rather than have to take it home to unpack.   Often these boxes are in the form of a shopping bag, complete with holding animation.

I'm referring to the script that has been posted on the thread.

  • Like 1
Link to comment
Share on other sites

4 minutes ago, ainst Composer said:

@Kyrah Abattoir @steph Arnott

This script with detailed comments was kindly created by @Innula Zenovka to help to understand how unpackers work for a person who wants to create their own unpacker.

 

 

I am aware of that which is why i added the additional at the end.

Edited by steph Arnott
A word was incorrect in meaning.
  • Like 1
Link to comment
Share on other sites

9 minutes ago, Kyrah Abattoir said:

Hm, well sorry for the misunderstanding.

As a general point, anything I post here (as opposed to in the Script Library, should I ever get round to doing that) is to demonstrate a point about how to do something and almost certainly requires further work (particularly error handling) before it's suitable for use in a finished product.

I think Rolig once said any examples posted here should be treated like a example on a chalkboard (thus showing her and my age) in response to a question.   I think that's the best way to use them.  

  • Like 2
  • Thanks 1
Link to comment
Share on other sites

1 minute ago, steph Arnott said:

Put "STOP" in the list and call it in the script.

Where? How?

Please let's move on to that topic, I feel like a lawbreaker! I added a new version there. It works, but something superfluous and incomprehensible.

Link to comment
Share on other sites

You can't stop a sound that is already playing.  Once it is triggered, it plays to the end. When a sound is made up as a composite of many 10 second clips glued together, though, the "end" is simply the end of the current clip. In this case, you STOP the whole thing by stopping the timer that wants to keep triggering a new clip.  The action of the STOP button is therefore just llSetTimerEvent(0.0);

Since we're rambling well off topic -- you really shouldn't jam a brand new question into a completely different thread --- @Innula Zenovka is quite right. Code snippets or examples posted in this forum should never be assumed to be complete or free of errors.  They are almost always written on the fly and untested in world, offered purely to illustrate a method or suggest a solution to a specific short problem. This is a forum for scripters, so we assume that other scripters here will be focusing on the logic in the code and will not be troubled by the sorts of typographical errors that we all make when we are scribbling a quick note.

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

1 hour ago, Rolig Loon said:

You can't stop a sound that is already playing.  Once it is triggered, it plays to the end. When a sound is made up as a composite of many 10 second clips glued together, though, the "end" is simply the end of the current clip. In this case, you STOP the whole thing by stopping the timer that wants to keep triggering a new clip.  The action of the STOP button is therefore just llSetTimerEvent(0.0);

Since we're rambling well off topic -- you really shouldn't jam a brand new question into a completely different thread --- @Innula Zenovka is quite right. Code snippets or examples posted in this forum should never be assumed to be complete or free of errors.  They are almost always written on the fly and untested in world, offered purely to illustrate a method or suggest a solution to a specific short problem. This is a forum for scripters, so we assume that other scripters here will be focusing on the logic in the code and will not be troubled by the sorts of typographical errors that we all make when we are scribbling a quick note.

I'm not sure who the second part of your post is addressed to, but in my question I didn’t specify whose script it was, I didn’t even know that it was some kind of mistake, I needed to find out why this was happening and, if possible, make sure that this did not happen. like this.

Link to comment
Share on other sites

4 minutes ago, ainst Composer said:

I'm not sure who the second part of your post is addressed to, but in my question I didn’t specify whose script it was, I didn’t even know that it was some kind of mistake, I needed to find out why this was happening and, if possible, make sure that this did not happen. like this.

Rollig is just saying that a new thread would have been the correct course of action. Nothing more.

  • Like 2
Link to comment
Share on other sites

50 minutes ago, ainst Composer said:

I'm not sure who the second part of your post is addressed to, but in my question I didn’t specify whose script it was, I didn’t even know that it was some kind of mistake, I needed to find out why this was happening and, if possible, make sure that this did not happen. like this.

Don't worry about it.  That little parenthetic comment about trying not to jam a second unrelated question into an ongoing thread was just a gentle reminder.  Keeping topics separate just makes it easier for people who are searching later.  The real point of my comment was not specifically pointed in your direction but really reinforcing Innula's earlier comment.  Non-scripters who wander into this forum sometimes expect that they will find complete scripts here that have been tested in world.  Innula and I take the opportunity every once in a while to point out that it's a bad assumption.  We make no claims about writing clean, complete scripts here.  We're all scribbling quickly on the public blackboard,, throwing out ideas that anyone is welcome to clean up and test for her/himself.

Edited by Rolig Loon
  • Like 1
  • Thanks 1
Link to comment
Share on other sites

5 hours ago, ainst Composer said:

Where? How?

Please let's move on to that topic, I feel like a lawbreaker! I added a new version there. It works, but something superfluous and incomprehensible.

I quote myself asking to move to another topic.

I am very sorry about this little chaos i made!

Link to comment
Share on other sites

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