Dora Gustafson Posted January 12, 2016 Share Posted January 12, 2016 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 More sharing options...
arton Rotaru Posted January 12, 2016 Share Posted January 12, 2016 if you are short on curly brackets, I can give you a couple for free. { } :matte-motes-wink-tongue: if ( camon ) llClearCameraParams(); else camset(); camon = !camon; Link to comment Share on other sites More sharing options...
Ron Khondji Posted January 12, 2016 Share Posted January 12, 2016 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 More sharing options...
Nova Convair Posted January 12, 2016 Share Posted January 12, 2016 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 More sharing options...
arton Rotaru Posted January 12, 2016 Share Posted January 12, 2016 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 More sharing options...
Dora Gustafson Posted January 12, 2016 Author Share Posted January 12, 2016 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 More sharing options...
BarcodeBrian Posted January 12, 2016 Share Posted January 12, 2016 Of course it will be called. Curly brackets are only optional for those single line statements, not required. Link to comment Share on other sites More sharing options...
Dora Gustafson Posted January 12, 2016 Author Share Posted January 12, 2016 I do not agree, is this better do you think? if ( camon ) { llClearCameraParams(); }else { camset(); }camon = !camon; I think notAll 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 More sharing options...
Dora Gustafson Posted January 12, 2016 Author Share Posted January 12, 2016 Thank you for taking the time and for offering another writing which even I find more clear than what I wrote :smileysurprised::smileyvery-happy: Link to comment Share on other sites More sharing options...
arton Rotaru Posted January 12, 2016 Share Posted January 12, 2016 Oh, my mistake indeed. It's line dependend. I always write my code like this, though. Where only the last line will be executed. if ( camon ) llClearCameraParams(); else camset(); camon = !camon; My appologies. Link to comment Share on other sites More sharing options...
arton Rotaru Posted January 12, 2016 Share Posted January 12, 2016 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 More sharing options...
Nova Convair Posted January 12, 2016 Share Posted January 12, 2016 Yes, we have different styles of formatting the code. Since I also don't use brackets for one-liner if-then-else (except nested if-then-else) I have an advantage here to see the logic Link to comment Share on other sites More sharing options...
steph Arnott Posted January 12, 2016 Share Posted January 12, 2016 camon = !camon;//<<<This does not always work camon = FALSE; Link to comment Share on other sites More sharing options...
steph Arnott Posted January 12, 2016 Share Posted January 12, 2016 I put them in, just find reading and debugging more easy. Link to comment Share on other sites More sharing options...
arton Rotaru Posted January 12, 2016 Share Posted January 12, 2016 Yeah, me too. For the same reasons. :matte-motes-nerdy: I really didn't wanted to turn this into a style discussion, though. I swear! :matte-motes-bashful-cute-2: Link to comment Share on other sites More sharing options...
Rolig Loon Posted January 12, 2016 Share Posted January 12, 2016 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 More sharing options...
steph Arnott Posted January 12, 2016 Share Posted January 12, 2016 Did not think you was. Was probably needed in the first years as script size was so small, but a few bits added now is hardly an issue. Link to comment Share on other sites More sharing options...
steph Arnott Posted January 12, 2016 Share Posted January 12, 2016 lol Link to comment Share on other sites More sharing options...
Madelaine McMasters Posted January 12, 2016 Share Posted January 12, 2016 Me three! I don't think languages should even allow skipping brackets for single statement blocks. That's just an invitation to make mistakes later. Link to comment Share on other sites More sharing options...
steph Arnott Posted January 12, 2016 Share Posted January 12, 2016 You mean "me four" Link to comment Share on other sites More sharing options...
arton Rotaru Posted January 12, 2016 Share Posted January 12, 2016 Alright. Too late.... Style Discussion... NOW! Just kidding. :matte-motes-smitten: Link to comment Share on other sites More sharing options...
Perrie Juran Posted January 12, 2016 Share Posted January 12, 2016 arton Rotaru wrote: Alright. Too late.... Style Discussion... NOW! Just kidding. :matte-motes-smitten: I prefer short skirts. And BIG GUNS. Link to comment Share on other sites More sharing options...
Madelaine McMasters Posted January 12, 2016 Share Posted January 12, 2016 Yes, me for requiring braces! Link to comment Share on other sites More sharing options...
steph Arnott Posted January 12, 2016 Share Posted January 12, 2016 lol, why you want to wear braces? typo Link to comment Share on other sites More sharing options...
Madelaine McMasters Posted January 12, 2016 Share Posted January 12, 2016 Cuz there's not enough gap between my two front teeth to spit a watermelon seed through. Link to comment Share on other sites More sharing options...
Recommended Posts
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