Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Communicating with multiple instances of the same script?

Zerobeta Hax
Registered User
Join date: 19 Mar 2007
Posts: 2
03-19-2007 01:31
I'm creating an object where I communicate with the script via a dialog box. If I rez two objects, they will both be responding to input, no matter what object brought the dialog box up. Example:

A prim has a script that when touched brings up a dialog box to change the color of the prim. Rezzing two of those objects (from inventory) will make them both change color when I click a specific button in either ones dialog box.

I'm trying to work out a sollution where either object will only listen to chat sent from that objects dialog box, but I just can't straighten it out. I was thinking of, somehow, letting each rezzed object use a channel based on the scripts key, but I don't know if that's a good way to do it, and I certainly don't know how to convert the key to an integer.

I bet there is a better solution! Please give me your input!

Best regards,
Zerobeta Hax
Hg Beeks
llGetElement(80);
Join date: 13 Apr 2006
Posts: 134
03-19-2007 02:29
The best thing I can think of is to have it randomize the channel that the dialog responds on when you activate it.
CODE

integer channelNum;
default {
touch_start(integer total_number)
{
channelNum = llCeil(llFrand(3000)) + 1;
llDialog(llDetectedKey(0), "Hello, I like cake.", /*yourOptionsHere*/, channelNum)
llListen(channelNum, "", NULL_KEY, "");
}
listen(integer channel, string name, key id, string message)
{
//----> THIS IS WHERE YOU PUT YOUR NORMAL COMMANDS
llListenRemove(channelNum);
}
}

The reason the key idea doesn't work is that it's a hexadecimal value, so there's no part of it that will always be pure numbers.
Deanna Trollop
BZ Enterprises
Join date: 30 Jan 2006
Posts: 671
03-19-2007 04:48
From: Hg Beeks
The reason the key idea doesn't work is that it's a hexadecimal value, so there's no part of it that will always be pure numbers.

On the contrary, since it is hexadecimal, you can easily convert up to an 8-character section to a number by appending "0x" to the beginning and casting to integer:

CODE

integer SomeInt = (integer)( "0x" + llGetSubString( SomeKey, 0, 7 ) );

Of course, keys being formatted as they are, the easiest sections to deal with are the first 8 charcters, or any 8 of the last 12, unless you want to get into removing the dashes.
Rael Delcon
Registered User
Join date: 23 Nov 2006
Posts: 86
03-19-2007 09:54
For a similar problem (doors) i adopted the following strategy:

CODE

- Normally doors do not listen to any channel
- When clicked a door goes into a state "command"
- In state "command"
- a timer is set to, say, 10 seconds
- a llListen() is set to, say, -414 (but could have been random)
- a llDialog() is shown with the options
- if listen() "hears" the user choice
-- remove the listener
-- reset the timer
-- process the selected option
-- go to the default state
- if timeout occurs
-- remove the listener
-- go to the default state


I found that using a separate state produce a tidier code

Hope it helps.
Zerobeta Hax
Registered User
Join date: 19 Mar 2007
Posts: 2
03-19-2007 11:42
Thank you for all your input! Problem solved based on your input :)

This is a great fora with great people! :)

/Zerobeta Hax
Hg Beeks
llGetElement(80);
Join date: 13 Apr 2006
Posts: 134
03-19-2007 13:21
From: Deanna Trollop
On the contrary, since it is hexadecimal, you can easily convert up to an 8-character section to a number by appending "0x" to the beginning and casting to integer:

CODE

integer SomeInt = (integer)( "0x" + llGetSubString( SomeKey, 0, 7 ) );

Of course, keys being formatted as they are, the easiest sections to deal with are the first 8 charcters, or any 8 of the last 12, unless you want to get into removing the dashes.

...Right. This is why I shouldn't code when I've lost a lot of sleep. x.x;