Jump to content

Touch trigger in If Statement?


Syle Devin
 Share

You are about to reply to a thread that has been inactive for 4057 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

So I am trying to put touch in an if statment but it isn't working. I also can't find anything on the wiki to explain why it isn't working. I get a syntax error before the touch. I am sure there is something I am missing that isn't a syntax error. The script is supposed to be set up for an HUD. You click on block and it makes the color choices visible. Then when you click the color change block it will send out the message to change the object color.

 

 else if(llToLower(message) == "chaircushion")
                { 
                    llSetAlpha(1.0, ALL_SIDES);
                    touch(integer total_number)
                        {
                        llSay(-5872695687565, "red");
                        }
                }

 

 Or should I be doing this some other way? Here is the whole code.

 

default
{
    state_entry()
    { 
        llListen(-5872695687565, "", NULL_KEY, "");
    }
    
    listen( integer channel, string name, key id, string message )
        {
                if(llToLower(message) == "exit")
                { 
                    llSetAlpha(0.0, ALL_SIDES);

                }
    
                else if(llToLower(message) == "chaircushion")
                { 
                    llSetAlpha(1.0, ALL_SIDES);
                    touch(integer total_number)
                        {
                        llSay(-5872695687565, "red");
                        }
                }
                else if(llToLower(message) == "chairlegs")
                { 
                    llSetAlpha(1.0, ALL_SIDES);
                    touch(integer total_number)
                        {
                        llSay(-5872695687565, "red");
                        }
                }
            
                else if(llToLower(message) == "chairbody")
                { 
                    llSetAlpha(1.0, ALL_SIDES);
                    touch(integer total_number)
                        {
                        llSay(-5872695687565, "red");
                        }
        }
    }
}
    

 

Thanks for your time and help :)

 

Edit: Also I seem to be having trouble with the listen but I don't see anything wrong and I have a very similar script that is working fine.

 

Link to comment
Share on other sites

...Stop that. :P

Touch is an event, just like listen(integer channel, ...etc)

It needs to go on the outside of your if statement, as:-

default
{
touch_start (integer num_det) { if(sLASTMESSAGE == "red") { Dostuff(); } }
}

 Obviously you can't carry string message from the listen event into it, so you need a global string (sLASTMESSAGE in my code above) to hold this between the listen and touch events.

 

ETA: events such as touch, listen etc still go inside the state ('default')!

Link to comment
Share on other sites

Ah I'm just having trouble wrapping my head around this one. My brain probably needs to relax but I want to get this script done.

So basically I have to have the sLASTMESSAGE equal the listen even but how would I do that?

I thought I knew how to go about doing that but after just now trying a few different things I got no where :/ I basically am just trying to get the script to say something on touch only once other messages have been said. The touch shouldn't work if there are no messages which your codes seems like it would do. From what your saying I understand that I have to have the sLASTMESSAGE = the code for the (llToLower(message) ="") but I havn't really figured out how to make integers equal a section of code yet. 

Or could I have the sLASTMESSAGE be set by another integer that is set by the listen messages?

Learning all this code is tougher than I expected but thanks for the help. :)

Link to comment
Share on other sites

There is a complete misunderstandment how a script works.

LSL is event driven. Read the wiki about the basics and events.

An event section is triggered by the event it's made for and the code inside is run whenever that event happens.

The touch event is triggered if someone touches the prim.

The listen event is triggered if a message that matches the criteria of the llListen is heared - but - a prim cannot hear itself! - what you seem to try here.

Link to comment
Share on other sites

No the script is not trying to listen to itself. Everything runs on the same channel but it is not listening to itself.  I have one box that you click and it will send out a message. The script, that I posted in this thread, then looks for that message and depending on the message this script is allowed to send out a message when clicked. Is it not possible to only have the touch start work based off of a listen message? I don't want the listen to work based off the touch start which I could do but instead the other way around. 

The thing is if touch and touch_start don't work in a listen even since they are events also I would have to figure out another way, which I don't know, to go about achieving what I want.

Link to comment
Share on other sites

just change a few things...put a variable in the if statements

 and use touch to  say the variable?

 

string color;default{    state_entry()    {         llListen(-5872695687565, "", NULL_KEY, "");    }    touch_start(integer num)    {         llSay(-5872695687565, color);
color = " "; } listen( integer channel, string name, key id, string message ) { if(llToLower(message) == "exit") { llSetAlpha(0.0, ALL_SIDES);
color = " "; } else if(llToLower(message) == "chaircushion") { llSetAlpha(1.0, ALL_SIDES); color = "red"; } else if(llToLower(message) == "chairlegs") { llSetAlpha(1.0, ALL_SIDES); color = "red"; } else if(llToLower(message) == "chairbody") { llSetAlpha(1.0, ALL_SIDES); color = "red"; } }}

 or if all colors are the same...

 

string color;default{    state_entry()    {         llListen(-5872695687565, "", NULL_KEY, "");    }    touch_start(integer num)    {         llSay(-5872695687565, color);         color = " ";            }        listen( integer channel, string name, key id, string message )    {                if(llToLower(message) == "exit")                {                     llSetAlpha(0.0, ALL_SIDES);
color = " "; } else if(llToLower(message) == "chaircushion" || llToLower(message) == "chairlegs" || llToLower(message) == "chairbody") { llSetAlpha(1.0, ALL_SIDES); color = "red"; } }}

 

Link to comment
Share on other sites

I think what you need to do is something like this:

string sLASTMESSAGE;  // a string, not an integerdefault{	state_entry()	{		llListen(-5872695687565, "", NULL_KEY, "");	}	listen( integer channel, string name, key id, string message )	{		sLASTMESSAGE="";//clear the value of sLASTMESSAGE		message = llToLower(message);		if("exit"==message)		{			llSetAlpha(0.0, ALL_SIDES);		}		else if (~llListFindList(["chaircushion","chairlegs","chairbody"],[message]))//if the message is one of those three		{			llSetAlpha(1.0, ALL_SIDES);			sLASTMESSAGE="red"; //set the value of sLASTMESSAGE to "red"		}	}	touch_start(integer total_number)	{		if(sLASTMESSAGE)		{ //shorthand for if(sLASTMESSAGE!="")			llSay(-5872695687565, sLASTMESSAGE);		}	}}

 

Link to comment
Share on other sites

Just in passing, the range of integers is −2,147,483,648 to +2,147,483,647. The -5,872,695,687,565 channel constant is outside that range and actually evaluates to 1, which is likely to crosstalk with things that really mean to use channel 1 -- and with everything that underflows that range. (Anything that overflows the range evaluates to -1.)

  • Like 1
Link to comment
Share on other sites

 

Thank you so much guys! This has been so much help and learning. While it seems the script should be working the listne now doesn't seem to be working and I am not sure why. I did change the listen channel to one that should work. I added in a couple of llSay(PUBLIC_CHANNEL, " "); to check where the script might be going wrong and nothing happens except with the first script.

Here is the script that says something.

default{    state_entry()    {    }    touch_start(integer total_number)    {        llSay(-5256, "chaircushions");        llSay(PUBLIC_CHANNEL, "chaircushions");    }}

 

but when I set the other script it does nothing. Here is the script that listens.

string color;default{    state_entry()    {         llListen(-5256, "", NULL_KEY, "");    }    touch_start(integer num)    {         color = " ";         llSay(-5257, color);         llSay(PUBLIC_CHANNEL, color);            }        listen( integer channel, string name, key id, string message )    {                if(llToLower(message) == "exit")                {                     llSetAlpha(0.0, ALL_SIDES);                    color = " ";                }                    else if(llToLower(message) == "chaircushions" ||                        llToLower(message) == "chairlegs" ||                        llToLower(message) == "chairbody")                {                     llSetAlpha(1.0, ALL_SIDES);                        color = "red";                           llSay(PUBLIC_CHANNEL, "color found");                                                           }                   }}

 

 

EDIT: How possible is it for a script to be corrupt? I got the script working but I had to copy and past the code into a new script. Previously I had jsut edited the code but nothing was working and there were no errors.

Link to comment
Share on other sites

Well, it ought to work.  The scripts compile and the listener is listening on the channel that your first script is talking on.   You do need to have the two within chat range of each other, of course, but I assume you've taken care of that.  The second script won't be able to hear the message that is generated in its own touch_start event, because a script can't hear itself (except in the special case of a dialog), so I assume you have that bit of code there to talk to some other script.  It certainly ought to be able to hear a message from the first script, though.

Link to comment
Share on other sites

  • 2 weeks later...

Actually a script can listen to itself, that's how the llDialog() works. when you press one of the buttons in the dialog a messsage is sent out on the specified channel and the script needs to listen for that message to know what to do.

 

to answer the OP, if you want to have the listen message captured and used in the touch event you will need to declare a global string value (Putting string variable1;  before the code) and then you will beable to use the variable accross multiple events.

Link to comment
Share on other sites


Mich Sopwith wrote:

Actually a script can listen to itself, that's how the llDialog() works. when you press one of the buttons in the dialog a messsage is sent out on the specified channel and the script needs to listen for that message to know what to do.
[....]

That's kinda why I put that parenthetical statement in my post .... "(except in the special case of a dialog)". :smileywink:

Link to comment
Share on other sites


Mich Sopwith wrote:

Actually a script can listen to itself, that's how the llDialog() works. when you press one of the buttons in the dialog a messsage is sent out on the specified channel and the script needs to listen for that message to know what to do.

 

Strictly speaking, a script can't hear chat from the same prim the script is in (though it can hear chat from other prims in the linkset).    The reason it can hear the message from the dialog buttons is that llDialog makes the avatar chat the message (it's the only time avatars can speak on a negative channel).    That's why, when you call something like llGiveInventory(id, message) when the prim receives a message from llDialog, it's the avatar, not the prim that receives the item.

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 4057 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...