Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Apply same script to all prims in object?

Geuis Dassin
Filming Path creator
Join date: 3 May 2006
Posts: 565
11-15-2006 17:38
This is a 2 part question.

1) How can I apply the same script to all of the prims in an object instead of one at a time?
2) How can I delete all scripts in every prim in an object?
Thanto Usitnov
Lord Byron wannabe
Join date: 4 Aug 2006
Posts: 68
11-15-2006 21:40
1) Depends on what you mean.
(a)If you mean you want to have a script work on a whole object, then you just have the script in the root prim.
(b)However, if you want a script to work individually on seperate prims, you can only do that by having that script in every prim you want it to individually act on. For example, if you want a script to set the textures of all (or some) prims in a linkset, you'll need to have that script in all of those prims. Unfortunately, there's no way around that at present.

2) Have the scripts you want gone llRemoveInventory() on themselves and/or the other scripts in the same prims. See
http://www.lslwiki.com/lslwiki/wakka.php?wakka=llRemoveInventory
Senuka Harbinger
A-Life, one bit at a time
Join date: 24 Oct 2005
Posts: 491
11-16-2006 03:26
llRemoteLoadScriptPin() should be able to do what you want it to. it will transfer/overwrite a script to any object you own (and have mod perms). the only catch is that it needs the key of the prim; so you'd have to somehow pass the key for every prim in a linkset to this command for it to work. I haven't tested the following code in world, but it should work when put in a script in the root prim:


CODE


integer i;
for(i=0; i < llGetNumberOfPrims() - 1; i++)
{
key child=llGetLinkKey(i);
llRemoteLoadScriptPin(child,"Script Name", pin_number,TRUE,0)
}



where "Script Name" is the name of the script you wish to distribute and pin_number is the integer set by llSetRemoteScriptAccessPin. You'll have to call llSetRemoteScriptAcessPin for each child object, but only once and it's persistant after script deletion like llSetText or a particle system so it's great for when you need to update a large number of scripts in a linkset. For a one-time script distribution though it's more work than just manually dragging the script into each prim.
_____________________
My SLExchange shop

Typos are forgiven; desecrating the english language with reckless abandon and necrophilic acts is not.


The function is working perfectly fine. It's just not working the way you wanted it to work.
Thanto Usitnov
Lord Byron wannabe
Join date: 4 Aug 2006
Posts: 68
11-16-2006 23:21
Do keep in mind that for llRemoteLoadScriptPin, the prim you're sending the script to must have a pin set, which can only be done by script. Also, sending a script like this creates a copy, which means a new asset (from what I've heard anyway--I don't see why this would be the case, though, if it is indeed just a copy). Generally speaking, if you're already going to have a script there, it might as well be the one you're going to send. If it's something you need to be active/inactive on a whim, I suggest using a script that listens to link messages and activates/deactivates the script you want activated/deactivated accordingly.
Tripod Dangle
Registered User
Join date: 6 Jun 2005
Posts: 12
11-20-2006 15:19
Change pin.lsl
CODE

integer pin = 1234;
default
{
state_entry()
{
llSetRemoteScriptAccessPin(pin);
llSleep(0.3);
llRemoveInventory(llGetScriptName());
}
}

Drop this in the root prim
Copy to all but root.lsl
CODE

string scriptname = "Delete";//changes the script name your loading onto child prims
integer pin = 1234;
integer startP = 123;
default
{
state_entry()
{
}
touch_start(integer total_number)
{
integer len = llGetNumberOfPrims();
integer i;
for( i = 2; i < len; i++ )
{
llRemoteLoadScriptPin(llGetLinkKey(i), scriptname, pin, 1, startP);
llOwnerSay("giving away to link number: " + (string) i);
}
}
}

And then the delete scripts is already done courtesy of Alondria LeFay
CODE

// UTIL.deletescripts.lsl
// By Alondria LeFay
// Version 1.0


// Utility - Copy/Paste/Delete Scripts by Alondria LeFay
//I create quite a few things with pre-existant modules of scripts. It grew to become a pain to manually drag certain scripts into new objects over and over so I created a set of utility scripts to automate this. Inorder to copy the scripts, drop UTIL.copyscripts into the object you want to copy the scripts from, and UTIL.pastescripts into the object you want them copied into. The utility scripts will transfer all the scripts and then remove themselves. I also include UTIL.deletescripts, which is a quick way to remove all scripts from an object.
//Anyways, they are nothing too special, I just found myself using them a lot so I figured I'd pass them on.

integer lhook;
list scripts;

alInit(integer argi)
{
if (lhook)
{
llListenRemove(lhook);
}
llSay(0,"Deleting scripts....");
integer num = llGetInventoryNumber(INVENTORY_SCRIPT);
integer i;
for (i = 0; i < num; i = i + 1)
{
string tmps = llGetInventoryName(INVENTORY_SCRIPT,i);
if (tmps != llGetScriptName())
{
scripts = scripts + [ tmps ];
}
}
for (i = 0; i < llGetListLength(scripts); i = i + 1)
{
llRemoveInventory(llList2String(scripts,i));
}
llSay(0,"Done!");
//llRemoveInventory(llGetScriptName());
}

default
{
on_rez(integer argi)
{
alInit(argi);
}
state_entry()
{
alInit(0);
}
}

Drop "change pin.lsl" on all child prims you wanna access

Make sure root prim has no scripts in it first..
Drop the delete script inside root prim and then turn it off. Then take off the // in front of llRemoveInventory(llGetScriptName());
then drop the "Copy to all but root.lsl" on the root prim
Talarus Luan
Ancient Archaean Dragon
Join date: 18 Mar 2006
Posts: 4,831
11-20-2006 16:43
You can also try using llGiveInventory to give copies of a script to all child prims from the root. The only problem is that you have to Recompile All Scripts in Selection for the whole object. However, it seems that, lately, this is having some issues.

It used to work fine, but sometimes the given scripts won't show up in the prim inventory for minutes, if at all.
Nynthan Folsom
Registered User
Join date: 29 Aug 2006
Posts: 70
12-02-2006 00:13
From: Thanto Usitnov
Also, sending a script like this creates a copy, which means a new asset (from what I've heard anyway--I don't see why this would be the case, though, if it is indeed just a copy).

Might that have to do with task management? Also, if you change a script in one prim, you might not want that edit to propagate to all the other "copies."