Sari6t Posted January 13, 2017 Share Posted January 13, 2017 Hi and thanks for helping. I've managed to get most of this working. I'm learning LSL, clearly lol and almost got this to work. What I am wanting is for this light switch to glow when it is off and to not glow when its on. The glow effect is perfect and it turns the light ona and off withthe other scripts Im using but I can't figure out how to make the timer() sit somewhere that I can tell it what state the switch is in. I've tried If else, but I've hit my knowledge wall and can't quite figure it out. Here is the working code that I'm certian someone will go "pfft that's east...do this" in like two seconds. :) That would be great too . So thanks , looking forward to learning how this works. // Switch On and Off myon_state() { rotation rot = llGetRot(); vector vrot = llRot2Euler(rot); vrot+=<-30*DEG_TO_RAD,0,0>; rot=llEuler2Rot(vrot); llSetRot(rot); } myoff_state() { rotation rot = llGetRot(); vector vrot = llRot2Euler(rot); vrot+=<30*DEG_TO_RAD,0,0>; rot=llEuler2Rot(vrot); llSetRot(rot); } default { state_entry() { myoff_state(); llSetTimerEvent(0.1); } // Make nice glowing pulsing light timer() { llSetTimerEvent(0.0); float glow =0.0; while(glow < 0.5) { glow+=0.01; llSetLinkPrimitiveParamsFast(LINK_THIS,[PRIM_GLOW, ALL_SIDES, glow]); llSleep(0.01); } glow = 0.5; while(glow > 0.1) { glow-=0.01; llSetLinkPrimitiveParamsFast(LINK_THIS,[PRIM_GLOW, ALL_SIDES, glow]); llSleep(0.01); } llSetLinkPrimitiveParamsFast(LINK_THIS,[PRIM_GLOW, ALL_SIDES, 0.0]); llSetTimerEvent(0.1); } // See the event work and stare as I can't make it work with my glow thingy link_message(integer sender_num, integer num, string str, key id) { if(str=="stop") { myoff_state(); } if(str=="start") { myon_state(); } } } Link to comment Share on other sites More sharing options...
Rolig Loon Posted January 13, 2017 Share Posted January 13, 2017 Oscillators are fun to script. What you want to do is let the magnitude of some value increase until it gets to a maximum and then turn around and come back down, turn around at a minumum and go back up again .... over and over and over. Suppose you take the modulus operator and play with it. If you write timer(){ gCount = (++gCount)%5; // Where gCount is a global integer llSay(0, (string) gCount);} you'll see that it does half the job. At least, it cycles from 0 to 4. The trouble is, it always starts each cycle at 0: 0,1,2,3,4,0,1,2,3,4,0,1,2,3,4 .... It doesn't turn around at 4 and come back down. We can't use gCount directly, but we can use it to flip a switch that makes the cycle change direction at the top and bottom end. Like this .. timer(){ if ((++gCount)%5 == 0) { gDir *= -1; // where gDir is a non-zero integer (like 1) }} So gDir will flip from positive to negative every 5th time that the timer fires. So, all we need to do is use gDir to make a slow change in the value we are trying to control -- in this case glow. Like this ... integer gON;integer gCount;integer gDir = 1;float gGlow;default{ touch_start(integer num) { llSetTimerEvent(0.1 * (gON = !gON)); //simple toggle swutch gGlow = 0.01; } timer() { if ((++gCount)%5 == 0) { gDir *= -1; } gGlow += 0.01*gDir; llSay(0,"Count = " + (string)gCount + " Dir = " + (string)gDir + " Glow = " +(string)gGlow); llSetLinkPrimitiveParamsFast(LINK_THIS,[PRIM_GLOW,ALL_SIDES,gGlow]); }} Each time the timer fires, gGlow changes by 0.01, but because gDir changes direction each 5th time, the change also switches from 0.01 to -0.01. The only thing you have to be careful of is that it never dips below 0.0, which is why we start the timer with gGlow = 0.01. You can write code that uses this sort of logic in many ways, but this is nice and compact. You should be able to see how it could fit into your script. BTW, this effect looks nice at night (I tried it), especially if your object is set to fullbright and is tinted a mid-range gray. Link to comment Share on other sites More sharing options...
Sari6t Posted January 13, 2017 Author Share Posted January 13, 2017 Thank you so much, I can't wait to get a minute and try out your example. There is a lot for me to understand in it. I might not understand what you wrote so if you covered it it's just me not knowing, but what I am trying to do is the following . lol Ok imagine you are in a room, it's dark expect for a single oscillating glowing button on a table, you walk to the table and click the glowing button and the lights come on, the glowing button stops glowing as well. Does your example allow for that in the code I worte so far? Again , if it does it's just me being a noob. So, many many thanks for this. You answeredd better than I could ever have hoped for. Link to comment Share on other sites More sharing options...
Rolig Loon Posted January 13, 2017 Share Posted January 13, 2017 I'm not going to write your script for you, because that's not what we do in this forum. What I wrote was an oscillator than will make object have a gentle pulsating glow. You'll have to spend time digesting it and figuring out how to insert it (or something like it) into your own script. The first step is to try it out and see how it works, and play with it. There are some new concepts in there, I'm sure. So experiment until you understand what's going on. Link to comment Share on other sites More sharing options...
Sari6t Posted January 13, 2017 Author Share Posted January 13, 2017 Thank you for your help. Your script throws an error btw . Cheers, Link to comment Share on other sites More sharing options...
Rolig Loon Posted January 13, 2017 Share Posted January 13, 2017 It does? What sort of error? It runs fine for me. Link to comment Share on other sites More sharing options...
Xiija Posted January 13, 2017 Share Posted January 13, 2017 simple fix, in your myon_state() ... just add .... llSetTimerEvent(0.1); at the end and in myoff_state() ... add llSetTimerEvent(0.0); at the end Link to comment Share on other sites More sharing options...
Sari6t Posted January 16, 2017 Author Share Posted January 16, 2017 Thanks, I just figured that one out. Yay!! Thank you so much though. Link to comment Share on other sites More sharing options...
Sari6t Posted January 16, 2017 Author Share Posted January 16, 2017 It runs fine the first couple times then [17:08] llSetPrimitiveParams error running rule #1 (PRIM_GLOW): bounds error; -0.01 is not in (0, 1). but thanks for the other example I was able to duct tape it into someting that nearly works. Link to comment Share on other sites More sharing options...
Rolig Loon Posted January 16, 2017 Share Posted January 16, 2017 Oh, is THAT it? Remember, I said that it has to start with 0.01. Otherwise, it won't stop at zero when it comes back down.. It wil go to -0.01, which is not allowed. 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