Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Random 'constant' that survives a script reset

Photon Tokyoska
Registered User
Join date: 22 Oct 2007
Posts: 16
04-10-2008 00:38
Hi fellow coders

I have created a house that talks to various components within it (doors/lights etc) on a channel. As u can expect if i rezz two houses next to each other u can end up with one house controlling the others components. Naturally u could manually change the channel - fine for a couple of houses - but not hundreds. (Yea im dreaming)....

anyway I know how to randomly generate a new chanel number, however if the script is reset a new channel is generated - which is bad as it means all the other components have to be manually re-synced.

So what i need to do is to

1) Generate a random chanel that is saved somewhere so that if the script is reset it wont be re-generated. (so an if(house_channel >= 0) allocate new negative house chanel.

note: i have tried assigning channel numbers in the 'on_rez' function - but the chanel number never takes.

Any ides which way to go?

Cheers

Photon
Salvador Nakamura
http://www.sl-index.com
Join date: 16 Jan 2007
Posts: 557
04-10-2008 00:49
i made a few scripted houses myself, and installed a reset option for the owner, its sends the reset message to all sub-scripts.

*an alternate option would be to install a second script, that will hold your channel number
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
04-10-2008 01:51
The object description (or a prim description) might be a good place to store a channel (or perhaps an arbitrary phrase that you hash into a channel by some means like llMD5String(); that might be easier to remember than a straight number).

http://www.lslwiki.net/lslwiki/wakka.php?wakka=llSetObjectDesc
http://www.lslwiki.net/lslwiki/wakka.php?wakka=llGetObjectDesc
http://www.lslwiki.net/lslwiki/wakka.php?wakka=llGetObjectDetails
Dora Gustafson
Registered User
Join date: 13 Mar 2007
Posts: 779
Lol
04-10-2008 02:55
I had similar problems with a football game: When played in one end of a region the winner was payed prices from all football games in that region.

The only safe solution and the one I applied is to use Keys.
When a slave object is rezzed its script collects the keys of its masters.
I use llSensorRepeat() for that.
To make sure I get the right keys I use:
1. Sensor range
2. Object name
3. Test for same Object owner, slave and master
4. Test for same Object set group, slave and master)
5. Test for Slave and Master on land with the same owner and/or Slave and Master on land with the same Parcel description

The slave object script will not run until it has collected all keys.
When it runs it will only listen to masters with the right keys and it can't be commanded by other object's scripts.

If you have more objects that full fill points 2 through 5, the scheme may not work but then you asked for it.

If a master object is re-rezzed it gets a new key! and its slaves has to have their scripts reset.
_____________________
From Studio Dora
Tyken Hightower
Automagical
Join date: 15 Feb 2006
Posts: 472
04-10-2008 07:36
If these houses are only one linked object, then why aren't you using llMessageLinked instead?

Otherwise, if each house contains multiple objects, it depends on how they're rezzed. As long as they know their starting value, you could just store it in the script's containing prim's description using llSetObjectDesc, but there are many other ways if that won't work..
_____________________
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
04-10-2008 10:10
From: Dora Gustafson
The only safe solution and the one I applied is to use Keys.
When a slave object is rezzed its script collects the keys of its masters.
I use llSensorRepeat() for that.
To make sure I get the right keys I use:
1. Sensor range
2. Object name
3. Test for same Object owner, slave and master
4. Test for same Object set group, slave and master)
5. Test for Slave and Master on land with the same owner and/or Slave and Master on land with the same Parcel description

The slave object script will not run until it has collected all keys.
When it runs it will only listen to masters with the right keys and it can't be commanded by other object's scripts.

Another good way to communicate data to a rezzed object is to give it a channel number as the start parameter, have it announce itself to the rezzing object when it is fully rezzed, and then have the rezzing object send it data specific to the instance. If you do it this way you can set things up so all your configuration is in the "master" object, and it safely passes the relavent bits on to its "child" objects without having to resort to guesswork.