Jump to content

Touch wont work once sat!


naughtyniece
 Share

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

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

Recommended Posts

Hi,

I have what i though would be simple, a chair, you sit on it and you get a dialog menu, with choices to eat, chat, slide chair in or out.

However, once you have chosen an option after sitting, the dialog menu disappears and you can not get it back, i tried adding it to the Touch_start bu this has no effect.

Can somebody help me out, my script is a bit 'rough' but it almost works.

The goal is a seat you can sit on and then use dialog box to change animations, slide chair in and out, and then when you stand to lose dialog box.

My script

key gSitterId;

integer gDIALOG_CHANNEL = -318;
string gACTION_PROMPT = "What do you want to do?";

string gCurrentAnimation = "";
string displayName;

integer chairPos;          

default
{
    state_entry( )
    {
        llSitTarget(<-0.32,0.0,0.3>,llEuler2Rot(<0,0,90>*DEG_TO_RAD)/llGetRot());
    }
    
     touch_start(integer total_number)
    {
      llResetScript( );
      llDialog( gSitterId, gACTION_PROMPT, [ "Eat", "Eat Slow", "Chat", "Slide In", "Slide Out" ], gDIALOG_CHANNEL );
    }

    changed( integer change )
    {
       
        gSitterId = llAvatarOnSitTarget( );
        if( gSitterId != NULL_KEY )
       {
            if( llGetPermissions( ) & PERMISSION_TRIGGER_ANIMATION )
            {         
                state sat_down;
            }                    
            else
            {
                llRequestPermissions (gSitterId, PERMISSION_TRIGGER_ANIMATION );
            }
        }
        else
        {
            llResetScript( );
        }
    }

    run_time_permissions (integer perm)
    {
        
        if ( perm & PERMISSION_TRIGGER_ANIMATION )
        {
            state sat_down;
        }
    }
    
    on_rez( integer start_param )
    {
        llResetScript( );
    }
}


state sat_down
{
    state_entry( )
    {
        displayName = llGetDisplayName(gSitterId);
        llSetText("", < 1, 1, 1 >, 1 ); 
        llListen( gDIALOG_CHANNEL, "", gSitterId, "" );
        llDialog( gSitterId, gACTION_PROMPT, [ "Eat", "Eat Slow", "Chat", "Slide In", "Slide Out" ], gDIALOG_CHANNEL );
    }

    listen( integer channel, string name, key id, string message )
    {
        if( message == "Eat Slow" )
        {
            llStartAnimation( "Sit at table 3" );
            gCurrentAnimation = "sit at table 3";
            llResetScript( );
            llDialog( gSitterId, gACTION_PROMPT, [ "Eat", "Eat Slow", "Chat", "Slide In", "Slide Out" ], gDIALOG_CHANNEL );
        }
        else if( message == "Eat" )
        {
            llStartAnimation( "eating4" );
            gCurrentAnimation = "eating4";
            llResetScript( );
            llDialog( gSitterId, gACTION_PROMPT, [ "Eat", "Eat Slow", "Chat", "Slide In", "Slide Out" ], gDIALOG_CHANNEL );           
        }
        else if( message == "Chat" )
        {
            llStartAnimation( "Chat" );
            gCurrentAnimation = "Chat";
           
        }
        else if( message == "Slide In" )
        {
            llSetPos(llGetPos() + <0,0.8,0>);
            llResetScript( );
            
        }
         else if( message == "Slide Out" )
        {
            llSetPos(llGetPos() + <0,-0.8,0>);
            llResetScript( );
            
        }
    }
    
    changed( integer change )
    {
        gSitterId = llAvatarOnSitTarget( );
        if( gSitterId == NULL_KEY )
        {
            llResetScript( );
        }
    }

    on_rez( integer start_param )
    {
        llResetScript( );
    }
}

Thank you so much in advance

 

Suzie

 

Link to comment
Share on other sites

Your sat_down state doesn't have a touch_start event in it, so there's no way you can expect it to react to a touch.  That's where you need to add a new llDialog command.  Before that, though, you need a listen event in state default.  Otherwise, the script can't hear the message from the llDialog command in that state.

Link to comment
Share on other sites

Does it make sense to have more states in a script handling simple operations like sitting on a chair?

A simple check for NULL_KEY value of the variable gSitterId should be enough to handle all events correct.

IMHO the use of states in this case, just makes the script unnecessary complicated, where logic errors are easy to make and hard to find. And not to mention future maintenance of the script/updates.

 

  • Like 2
Link to comment
Share on other sites

The only advantage I can see to using states here is if -- for some reason that I can't really imagine -- you want to suppress the "touchable" finger icon when the mouse pointer is floating over the object when someone is sitting on it.   But that's the opposite of what the OP says she wants to do.

Otherwise, I would simply test for the presence of a sitter using something like this

    touch_start(integer num_detected)
    {
        key k = llDetectedKey(0);
        if(k == llAvatarOnSitTarget()){//if the toucher is sitting on the object
            llListenRemove(iHandle);//iHandle should be defined as a global variable.
            iHandle = llListen(gDIALOG_CHANNEL,"", k, "");
            llDialog(k, gACTION_PROMPT, [ "Eat", "Eat Slow", "Chat", "Slide In", "Slide Out" ], gDIALOG_CHANNEL );
        }
		//otherwise do nothing
    }

 

then if I wanted to keep the menu open while the av is seated on the chair, simply call 

llDialog(id, gACTION_PROMPT, [ "Eat", "Eat Slow", "Chat", "Slide In", "Slide Out" ], gDIALOG_CHANNEL );

again at the end of the listen event.  As people probably realise I'm using "id" there to reference the "key id" bit in 

listen(integer channel, string name, key id, string message)

 

  • Like 1
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 2077 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...