Difference between revisions of "Object rez"

From Second Life Wiki
Jump to navigation Jump to search
(Undo revision 921722 by Mako Nozaki (Talk) Sorry Mako but, "If exist" is very poor grammar.)
m (Replaced <source> with <syntaxhighlight>)
(11 intermediate revisions by 7 users not shown)
Line 1: Line 1:
{{Issues/SVC-2926}}{{Issues/SVC-3421}}{{LSL_Event|event_id=28|event_delay|event=object_rez
{{LSL_Event|event_id=28|event_delay|event=object_rez
|inject-2={{Issues/SVC-2926}}{{Issues/SVC-3421}}
|p1_type=key|p1_name=id|p1_desc=[[UUID]] of object rezzed.
|p1_type=key|p1_name=id|p1_desc=[[UUID]] of object rezzed.
|event_desc=Triggered when the object rezzes an object.
|event_desc=Triggered when the object rezzes an object.
|constants
|constants
|spec
|spec
|caveats=*This event (if used) will trigger in all running scripts in the same '''prim''' as the script calling [[llRezObject]] or [[llRezAtRoot]].
|caveats=
**This event (if used) will NOT trigger in scripts in linked prims as a result of that call.
* Triggers in all running scripts with an [[object_rez]] event, AND in the same '''prim''' as the script calling [[llRezObject]] or [[llRezAtRoot]].
** Does NOT trigger in linked prims.
* A message sent to the rezzed object may arrive before the object has opened a channel and is ready to receive it unless you provide for a communication handshake between the rezzer and the new object.
|examples=
|examples=
<lsl>
Script in the parent object "Rezzer.lsl"
//gives inventory to object when it rezzes.
<syntaxhighlight lang="lsl2">
string inventory;
////////////////////////
string object;
// Rezzer script.
// Rez' an object from inventory, establishes a communication channel and
//  gives the rezzed object inventory.


default
integer COM_CHANNEL=-17974594; // chat channel used to coordinate between rezzer and rezzee
string REZZEE_NAME="Rezzee";
 
string CMD_REZZEE_READY = "REZZEE_READY";
string CMD_REZZER_DONE = "REZZER_DONE";
 
key rezzee_key;
 
default  
{
//...
touch_start(integer count)
{
state configure_child;
}
//...
}
 
// rez and configure a child
state configure_child
{
state_entry()
{
// where to rez
vector position = llGetPos() + <0.0, 0.0, 1.0>;
// establish rezzer's listen on the command channel
llListen( COM_CHANNEL, "", "", "" );
// rez the object from inventory.  Note that we are passing the
// communication channel as the rez parameter.
llRezObject(REZZEE_NAME, position, ZERO_VECTOR, ZERO_ROTATION, COM_CHANNEL);
}
 
object_rez(key id)
{ // the object has been rezzed in world.  It may not have successfully
// established its communication yet or done anything that it needs to
// in order to be ready for config. Don't do anything till we get the signal
rezzee_key = id;
}
listen(integer channel, string name, key id, string message)
{
if (message == CMD_REZZEE_READY)
{ // the rezzee has told us that they are ready to be configured.  We can
// we can sanity check id == rezzee_id, but in this trivial case that is
// not necessary.
integer count = llGetInventoryNumber(INVENTORY_NOTECARD);
// give all note cards in our inventory to the rezzee (we could do scripts or objects here too)
while(count)
{
string name = llGetInventoryName(INVENTORY_NOTECARD, --count);
llGiveInventory(id, name);
}
// And now tell the rezzee that we have finished giving it everything.
llRegionSayTo(id, COM_CHANNEL, CMD_REZZER_DONE);
// And we can leave configure child mode.
state default;
}
}
}
</syntaxhighlight>
Script in the child object "Rezzee.lsl"
<syntaxhighlight lang="lsl2">
// Rezzee
 
integer com_channel = 0;
key parent_key = NULL_KEY;
 
string CMD_REZZEE_READY = "REZZEE_READY";
string CMD_REZZER_DONE = "REZZER_DONE";
 
default
{
//...
on_rez(integer start_param)
{
com_channel = start_param;
state configure;
}
//...
}
 
state configure
{
{
    touch_start(integer count)
state_entry()
    {
{
        object=llGetInventoryName(INVENTORY_OBJECT,0); //get name of the 1st object in inventory
// Get the key of the object that rezzed us
        llRezObject(object, llGetPos() + <0.0, 0.0, 0.5>, ZERO_VECTOR, ZERO_ROTATION, 0)//rez the 1st object
list details = llGetObjectDetails( llGetKey(), [ OBJECT_REZZER_KEY ] );
    }
parent_key = llList2Key(details, 0);
    object_rez(key id)
    {
// establish our command channel and only listen to the object that rezzed us
        inventory=llGetInventoryName(INVENTORY_OBJECT,1)//get name of the 2nd object in inventory
llListen(com_channel, "", parent_key, "");
        llGiveInventory(id,inventory); //give 2nd object to 1st object when rezzed
// Our rezzer will be giving us inventory.
    }
llAllowInventoryDrop(TRUE);
// finally tell our rezzer that we are ready
llRegionSayTo( parent_key, com_channel, CMD_REZZEE_READY );
}
listen( integer channel, string name, key id, string message )
{ // in a more complex example you could check that the id and channel
// match but for this example we can take it on faith.
if (message == CMD_REZZER_DONE)
{ // the parent has told this script that it is done we can go back to
// our normal state.
state default;
}
}
state_exit()
{ // turn off inventory drop. 
llAllowInventoryDrop(FALSE);
// We don't need to clean up the listen since that will be done automatically
// when we leave this state.
}
}
}
</lsl>
</syntaxhighlight>
|helpers
|helpers
|also_header
|also_header

Revision as of 10:02, 1 October 2022

Description

Event: object_rez( key id ){ ; }

Triggered when the object rezzes an object.

• key id UUID of object rezzed.

Caveats

  • Triggers in all running scripts with an object_rez event, AND in the same prim as the script calling llRezObject or llRezAtRoot.
    • Does NOT trigger in linked prims.
  • A message sent to the rezzed object may arrive before the object has opened a channel and is ready to receive it unless you provide for a communication handshake between the rezzer and the new object.
All Issues ~ Search JIRA for related Bugs

Examples

Script in the parent object "Rezzer.lsl"

////////////////////////
// Rezzer script.
//	Rez' an object from inventory, establishes a communication channel and
//  gives the rezzed object inventory.

integer COM_CHANNEL=-17974594; // chat channel used to coordinate between rezzer and rezzee
string 	REZZEE_NAME="Rezzee";

string CMD_REZZEE_READY = "REZZEE_READY";
string CMD_REZZER_DONE = "REZZER_DONE";

key 			rezzee_key;

default 
{
	//...
	touch_start(integer count)
	{
		state configure_child;
	}
	//...
}

// rez and configure a child
state configure_child
{
	state_entry()
	{
		// where to rez
		vector position = llGetPos() + <0.0, 0.0, 1.0>;	
		// establish rezzer's listen on the command channel
		llListen( COM_CHANNEL, "", "", "" );	
		// rez the object from inventory.  Note that we are passing the 
		// communication channel as the rez parameter.
		llRezObject(REZZEE_NAME, position, ZERO_VECTOR, ZERO_ROTATION, COM_CHANNEL);	
	}

	object_rez(key id)
	{	// the object has been rezzed in world.  It may not have successfully 
		// established its communication yet or done anything that it needs to 
		// in order to be ready for config. Don't do anything till we get the signal
		rezzee_key = id;
	}
	
	listen(integer channel, string name, key id, string message)
	{
		if (message == CMD_REZZEE_READY)
		{	// the rezzee has told us that they are ready to be configured.  We can 
			// we can sanity check id == rezzee_id, but in this trivial case that is
			// not necessary.
			integer count = llGetInventoryNumber(INVENTORY_NOTECARD);
			// give all note cards in our inventory to the rezzee (we could do scripts or objects here too)
			while(count)
			{
				string name = llGetInventoryName(INVENTORY_NOTECARD, --count);
				llGiveInventory(id, name);
			}
			// And now tell the rezzee that we have finished giving it everything.
			llRegionSayTo(id, COM_CHANNEL, CMD_REZZER_DONE);
			// And we can leave configure child mode.
			state default;
		}
	}
}

Script in the child object "Rezzee.lsl"

// Rezzee

integer com_channel = 0;
key parent_key = NULL_KEY;

string CMD_REZZEE_READY = "REZZEE_READY";
string CMD_REZZER_DONE = "REZZER_DONE";

default 
{
	//...
	on_rez(integer start_param)
	{
		com_channel = start_param;
		state configure;
	}
	//...
}

state configure
{
	state_entry()
	{	
		// Get the key of the object that rezzed us
		list details = llGetObjectDetails( llGetKey(), [ OBJECT_REZZER_KEY ] );
		parent_key = llList2Key(details, 0);	
		
		// establish our command channel and only listen to the object that rezzed us
		llListen(com_channel, "", parent_key, "");
		// Our rezzer will be giving us inventory.
		llAllowInventoryDrop(TRUE);	
		// finally tell our rezzer that we are ready
		llRegionSayTo( parent_key, com_channel, CMD_REZZEE_READY );
	}
	
	 listen( integer channel, string name, key id, string message )
	 { // in a more complex example you could check that the id and channel 
		// match but for this example we can take it on faith.
		if (message == CMD_REZZER_DONE)
		{	// the parent has told this script that it is done we can go back to 
			// our normal state.
			state default;
		}
	 }
	 
	 state_exit()
	 {	// turn off inventory drop.  
		llAllowInventoryDrop(FALSE);	
		// We don't need to clean up the listen since that will be done automatically 
		// when we leave this state.
	 }
}

See Also

Events

•  on_rez Triggered when the object the script is in is rezzed

Functions

•  llRezObject Used to rez an object at the center of mass
•  llRezAtRoot Used to rez an object at the root

Deep Notes

Issues

All Issues

~ Search JIRA for related Issues
   object_rez() erroneously triggers on full parcel
   Possible Mono bug with object_rez

Signature

event void object_rez( key id );