Jump to content

What is wrong in this script?


Dora Gustafson
 Share

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

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

Recommended Posts

This script in a hud shall do this simple thing when hud is clicked:
Toggle camera when avi sits on something and clear camera when avi is not sitting

// toggle between Set and Clear CameraParams, script by Dora Gustafson, Studio Dora 2016
// v1.02 For hud attachment
// v1.03 trigger by mouse click
// v1.06 Disable when not sitting on object
// Logic error???

integer camon;

camset()
{
    llClearCameraParams(); // reset camera to default
    llSetCameraParams([
        CAMERA_ACTIVE, TRUE, // (TRUE or FALSE)
        CAMERA_BEHINDNESS_ANGLE, 180.0, // (0 to 180) degrees
        CAMERA_BEHINDNESS_LAG, 0.0, // (0 to 3) seconds
        CAMERA_DISTANCE, 8.0, // ( 0.5 to 50) meters
        CAMERA_FOCUS_LAG, 0.0 , // (0 to 3) seconds
        CAMERA_FOCUS_LOCKED, FALSE, // (TRUE or FALSE)
        CAMERA_FOCUS_OFFSET, <.0, .0, 3.0>, // <-10,-10,-10> to <10,10,10> meters
        CAMERA_FOCUS_THRESHOLD, 0.0, // (0 to 4) meters
        CAMERA_PITCH, 15.0, // (-45 to 80) degrees
        CAMERA_POSITION_LAG, 0.0, // (0 to 3) seconds
        CAMERA_POSITION_LOCKED, FALSE, // (TRUE or FALSE)
        CAMERA_POSITION_THRESHOLD, 0.0 // (0 to 4) meters
    ]);
}

default
{
    attach( key id)
    {
        if (id != NULL_KEY)
        {
            llRequestPermissions( id, PERMISSION_CONTROL_CAMERA);
            camon = TRUE;
        }
        else llReleaseControls();
    }
    run_time_permissions( integer perm)
    {
        if ( perm & PERMISSION_CONTROL_CAMERA )
        {
            if ( camon ) camset();
            else llClearCameraParams();
        }
    }
    touch_end( integer n)
    {
        if ( llGetPermissions() & PERMISSION_CONTROL_CAMERA )
        {
            if ( llGetAnimation( llGetOwner()) == "Sitting" )
            {
                if ( camon ) llClearCameraParams();
                else camset();
                camon = !camon;
            }
            else if ( camon )
            {
                llClearCameraParams();
                camon = !camon;
            }
// TEST monitor
llOwnerSay( llGetAnimation( llGetOwner())+"  camon = "+(string)camon);
        }
    }
}

The logic in the touch event handler works so far that the flag: camon, is toggled when it is supposed to toggle, but the camera only reacts the first time after avi sat or stood up.
It may be something simple but I can't see it and need help

Link to comment
Share on other sites

I would set camon to true in the camset function and set it to false when llClearCameraParams() instread of using a toggle.
That way camon truly reflects the camera.

The logic in th touch event would then be:

            if ( llGetAnimation( llGetOwner()) == "Sitting" )            {                if ( camon )                 {                        llClearCameraParams();                    camon = FALSE;                }                else camset();            }            else if ( camon )            {                llClearCameraParams();                camon = FALSE;            }

 

Link to comment
Share on other sites

The logic is ok, well I'm pretty sure of that :) No brackets nor direct TRUE/FALSE assignment will change that.

Did you hit <ESC> after camset()? Shouldn't be necessary every time though.

I tried it out too. Put script in a box, attached, sat on a scripted seat, clicked on the box a few times and it worked everytime, camera was moving between default and scripted position.

Whatever it is, it's not just the script. Some other factor kicks in here.

 

Link to comment
Share on other sites


Nova Convair wrote:

The logic is ok, well I'm pretty sure of that
:)
No brackets nor direct TRUE/FALSE assignment will change that.


Well, without the curly brackets camset() will never be called.

if ( camon ) llClearCameraParams();                else camset();                camon = !camon; 

 

Link to comment
Share on other sites

Thank you for showing the way:)
It is a particular seat that shows this behavior
Other seats and unscripted prims works as expected
The seat with the problem has a script with its own llSetCameraParams and although that setting is all different it makes the setting from the hud-script stay no matter how often you click
Obviously it creates some conflict of a kind

Thank you for saving me from going in sane

:smileysurprised::):smileyvery-happy:

Link to comment
Share on other sites

I do not agree, is this better do you think?

if ( camon ) { llClearCameraParams(); }else { camset(); }camon = !camon;

I think not
All I do is omit redundant curly brackets

I am sure our different views on this can lead to a long and overheated dispute

Thank you for your interest

:smileysurprised::):smileyvery-happy:

Link to comment
Share on other sites


Dora Gustafson wrote:

I do not agree, is this better do you think?
if ( camon ) { llClearCameraParams(); }else { camset(); }camon = !camon;

I think not

All I do is omit redundant curly brackets

I am sure our different views on this can lead to a long and overheated dispute

Thank you for your interest

:smileysurprised:
:)
:smileyvery-happy:

That was not my approach actually.

I just overlooked the single line dependencies on this. Sorry about that, to Nova too.:matte-motes-bashful-cute-2:

Link to comment
Share on other sites

Ooo!  Ooo!  Can I add a "Me too"?  I always put the curly bracket in, even when they aren't strictly necessary.  It saves me the embarrassment of generating an insidious logic error later, when I modify the script and add a line in a space where there should have been curly brackets all along.  Consistency saves the day.

Link to comment
Share on other sites

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