Difference between revisions of "Object rez"

From Second Life Wiki
Jump to: navigation, search
m
 
Line 8: Line 8:
 
* Triggers in all running scripts with an [[object_rez]] event, AND in the same '''prim''' as the script calling [[llRezObject]] or [[llRezAtRoot]].
 
* 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.
 
** 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 either (1) include a brief delay ( llSleep(0.2) ) in the object_rez event or (2) provide for a communication handshake between the rezzer and the new object.
+
* 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=
 +
Script in the parent object "Rezzer.lsl"
 
<source lang="lsl2">
 
<source lang="lsl2">
//gives inventory to object when it rezzes.
+
////////////////////////
string inventory;
+
// Rezzer script.
string object;
+
// 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;
 +
}
 +
}
 +
}
 +
</source>
 +
Script in the child object "Rezzee.lsl"
 +
<source 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.
 +
}
 
}
 
}
 
</source>
 
</source>

Latest revision as of 10:50, 4 October 2019

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 );