Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

touch_start and listen [help]

Shai Galli
Registered User
Join date: 16 Nov 2007
Posts: 6
03-21-2008 13:23
Hello, i hope someone can help me..xD..
consider this simple code put into an object attached to an av:
CODE

default
{
state_entry()
{
llListen(1,"",llGetOwner(),"");
}
touch_start(integer number)
{
if(llDetectedKey(0) == llGetOwner()) {
list myList = ["yes","no"];
llDialog(llGetOwner(),"switch:",myList,1);
}
}
listen(integer a, string b, key c, string msg)
{
if(msg == "yes") {
//--do something..
}
}
else if (msg == "no") {
//--do something else..
}
}

}


and another object (attached) that hear the messages "yes" and "no" with listen()..

so, i would avoid to use llDialog and send directly the msg touching the object, perhaps using a little "switch" code..for ex: when i touch for the first time, i will send yes to the listen(), and the next time the "no"...
which is the better way in order to make some similar?

Thanks, Shai^^
Kahiro Watanabe
Registered User
Join date: 28 Sep 2007
Posts: 572
03-21-2008 14:50
The second is better because you don't need to make a listener for the dialog. But there's no much difference if you kill the listener in listen event, put at the end: llListenRemove(listener); (just for the dialog, not for the other attached object).

One more thing, if you are going to attach this, instead of init the listener in state_entry

it's better to use attach event:

attach(key id)
{
if (id) // if id != NULL_KEY
{
// do stuff
}
}
Kidd Krasner
Registered User
Join date: 1 Jan 2007
Posts: 1,938
03-21-2008 17:02
Better in what sense?

Having something work as a toggle by touching can create usability problems. The user needs to be aware of what the current state is, otherwise he may touch the object expecting one thing and getting the other. The state should be obvious by looking, or perhaps listening to audio. You can't rely on messages in chat, because they may have scrolled and the user forgotten the last state. You shouldn't use it for things where accidentally touching the object would be undesirable, including accidental double clicking.

In the specific case of something attached to an av, you have to keep in mind that the av's motion can make it difficult to click on some attachments. You may be better off having the user type commands than touch the object. You should certainly give serious consideration to providing both options.

Also, regardless of which way you go, don't use "yes" and "no" on channel 1 as commands without also checking to make sure they come from the appropriate object. You shouldn't use commands that have a likelihood of conflicting with some other object.
Kidd Krasner
Registered User
Join date: 1 Jan 2007
Posts: 1,938
03-21-2008 17:03
From: Kahiro Watanabe
The second is better because you don't need to make a listener for the dialog.

This makes no sense. There's no difference between listening to the dialog for yes and no or listening to the other object for the same commands.
Shai Galli
Registered User
Join date: 16 Nov 2007
Posts: 6
03-21-2008 20:58
Thx Kahiro and Kidd..
but i would try to replace the llDialog with something like:
CODE

integer switch = FALSE;
touch_start(integer touched)
{
if(llDetectedKey(0) == llGetOwner()) {
if (switch == FALSE)
{
llListen(0,"",llGetOwner(),"yes");
switch = TRUE;
}
else if (switch == TRUE)
{
llListen(0,"",llGetOwner(),"no");
switch = FALSE;
}
}
...
...

..i know that this one dont work..xD...but i need to avoid the "dialog" and send the yes/no messages at the same way..
Kahiro Watanabe
Registered User
Join date: 28 Sep 2007
Posts: 572
03-22-2008 08:43
From: Kidd Krasner
This makes no sense. There's no difference between listening to the dialog for yes and no or listening to the other object for the same commands.


""But there's no much difference if you kill the listener in listen event, put at the end: llListenRemove(listener); (just for the dialog, not for the other attached object).""

You need another listener for the dialog. But if you close it properly after button is pressed, there's no problem in terms of efficiency.

The touch option with no dialog doesn't need to open a new listener....because there's no dialog.

Plese read well the OP and my reply. I don't know why s/he needs Two objects and one listening to other. S/he gave two options and in terms of efficiency are both similar.
There are other options, considering there is one object listening all the time maybe is better, instead of touch...simply typing it manually on an specific channel "/23 yes".

But the OP asked a different thing. It gives only two options.
Kidd Krasner
Registered User
Join date: 1 Jan 2007
Posts: 1,938
03-22-2008 08:48
From: Shai Galli
Thx Kahiro and Kidd..
but i would try to replace the llDialog with something like:
CODE

integer switch = FALSE;
touch_start(integer touched)
{
if(llDetectedKey(0) == llGetOwner()) {
if (switch == FALSE)
{
llListen(0,"",llGetOwner(),"yes");
switch = TRUE;
}
else if (switch == TRUE)
{
llListen(0,"",llGetOwner(),"no");
switch = FALSE;
}
}
...
...

..i know that this one dont work..xD...but i need to avoid the "dialog" and send the yes/no messages at the same way..

Could you provide more details about what you want? This code fragment seems perfectly valid. It works for some purpose, just not your purpose. But without those details, there's no way to tell what you really need.
Kidd Krasner
Registered User
Join date: 1 Jan 2007
Posts: 1,938
03-22-2008 09:10
From: Kahiro Watanabe
""But there's no much difference if you kill the listener in listen event, put at the end: llListenRemove(listener); (just for the dialog, not for the other attached object).""

You need another listener for the dialog. But if you close it properly after button is pressed, there's no problem in terms of efficiency.

No, you don't. One listen handler is perfectly capable of listening to commands from a dialog, the owner, or another object.

Perhaps the confusion is over the word "listener." I take it to mean the listen event handler, or more generally, an object that listens. Do you mean it as another call on llListen?
From: someone

The touch option with no dialog doesn't need to open a new listener....because there's no dialog.

It has to have a listen handler because it's still getting commands from either the first object, the dialog, or both. Depending on how it's implemented, it could be done with one or two calls on llListen.

From: someone

Plese read well the OP and my reply. I don't know why s/he needs Two objects and one listening to other. S/he gave two options and in terms of efficiency are both similar.

I did read them both. You hit the nail on the head by saying we don't know why two objects are needed. Without that information, it's really premature to worry about efficiency. Note that the OP was asking which was better, not which was more efficient.
Shai Galli
Registered User
Join date: 16 Nov 2007
Posts: 6
03-22-2008 12:06
..this is the complete code of the 1st object attached to an av: is composed by 3linked prims, and i would that: when i touch the object for the first time, say "yes" and 2prims become invisibles, then when i touch again, say "no" in chat and all prims reappear..
..the 2nd object also attached to an av, hear the yes and no with listen() and do something else:)..
(the code below concern only the 1st object)
CODE

integer switch = FALSE;

default
{
changed(integer change){
if(change && CHANGED_OWNER) llResetScript();
}
on_rez(integer rez)
{
llResetScript();
}
state_entry()
{
llSetLinkAlpha(LINK_SET,1,ALL_SIDES);
llListen(1,"",llGetOwner(),"");
}
touch_start(integer touched)
{
if(llDetectedKey(0) == llGetOwner()) {
if (switch == FALSE)
{
llListen(1,"",llGetOwner(),"yes");
llSay(0, "yes");
switch = TRUE;
}
else if (switch == TRUE)
{
llListen(1,"",llGetOwner(),"no");
llSay(0, "no");
switch = FALSE;
}
}
}
listen(integer a, string b, key c, string msg)
{
if(msg == "yes") {
integer i;
for(i=1; i<3; i++){
llSetLinkAlpha(i, 0.0, ALL_SIDES);
}
}
else if (msg == "no") {
llSetLinkAlpha(LINK_SET,1,ALL_SIDES);
}
}
attach(key id)
{
if(id == NULL_KEY) {
llSetLinkAlpha(LINK_SET, 1, ALL_SIDES);
}
}
}


...thanks again..xD..