RilaVirum Posted March 18, 2021 Share Posted March 18, 2021 Hello, I need help with my Timer Event, I'm really close. My timer event is only working in my state_entry, for some reason, but it's not working in my touch_start event, why is this happening? //Light Script integer switch; default { state_entry() { //Prim is suppose to be asleep here switch; llSetTimerEvent(2.0); llSetColor(<0.169, 0.169, 0.169>, ALL_SIDES); llSetAlpha(1.0, ALL_SIDES); } touch_start(integer total_number) { key clicked = llDetectedKey(0); if(clicked) { llSay(0, "Object Touched"); } } timer() { llSetTimerEvent(0.0); switch = !switch; if(switch == TRUE) { llSetPrimitiveParams([PRIM_POINT_LIGHT, TRUE, <0.041, 0.959, 0.959>, 1.0, 5.0, 1.0, PRIM_GLOW, ALL_SIDES, 0.6, PRIM_COLOR, ALL_SIDES, <0.041, 0.959, 0.959>, 0.6]); } else { llSetPrimitiveParams([PRIM_POINT_LIGHT, TRUE, <0.000, 1.000, 0.500>, 1.0, 5.0, 1.0, PRIM_GLOW, ALL_SIDES, 0.6, PRIM_COLOR, ALL_SIDES, <0.821, 0.393, 0.958>, 0.6]); } llSetTimerEvent(2.0); } touch_end(integer num_detected) { llResetScript(); } } Link to comment Share on other sites More sharing options...
Rolig Loon Posted March 18, 2021 Share Posted March 18, 2021 (edited) Your touch_start and touch_end events don't contain any code that might affect the light functions that are in the timer event. All the touch_start event is scripted to do is send a chat message. The touch_end event just resets the script. I really have no idea what you are trying to do. Do you perhaps think that one event is inside another one? Or maybe that execution follows linearly from the top of a script to the bottom? Neither is true. But this little if test key clicked = llDetectedKey(0); if(clicked) will always be TRUE. llDetectedKey(0) always exists if the touch_start event has been triggered, and it is always a key. Therefore if(clicked) is always TRUE. Edited March 18, 2021 by Rolig Loon 1 Link to comment Share on other sites More sharing options...
Quistess Alpha Posted March 18, 2021 Share Posted March 18, 2021 It's not really clear why you would need a timer even for a simple on/off lightbulb. For comparison, here's my light bulb script, which I think might have been the first pr second script I ever wrote in LSL: integer bulb_lit=FALSE; default { touch_start(integer total_number) { if(bulb_lit==FALSE) { llSetPrimitiveParams([PRIM_POINT_LIGHT, TRUE, <1,1,1>, 1, 10, 2]); llSetPrimitiveParams([PRIM_GLOW, 0, 0.15]); bulb_lit=TRUE; } else { llSetPrimitiveParams([PRIM_POINT_LIGHT, FALSE, <1,1,1>, 1, 10, 2]); llSetPrimitiveParams([PRIM_GLOW, 0, 0.0]); bulb_lit=FALSE; } } } (Yes I know it might have been cleaner to use the bulb_lit=!bulb_lit; flipping trick) this section: touch_end(integer num_detected) { llResetScript(); } seems quite out of place. Resetting the script is something you generally don't want to do very often, and this will reset the script every time you stop touching the object. 1 Link to comment Share on other sites More sharing options...
Mollymews Posted March 18, 2021 Share Posted March 18, 2021 (edited) when we press our mouse button (mouse down) then touch_start event fires. When we release the mouse button (mouse up) then touch_end fires as the script is resetting the timer when the mouse button is released then there is no practical effect Edited March 18, 2021 by Mollymews 1 Link to comment Share on other sites More sharing options...
Quistess Alpha Posted March 18, 2021 Share Posted March 18, 2021 (edited) Grasping at straws as to what you're trying to do, but for a sane example of using a touch_start() touch_end() and timer() event to do something only if the object is touched for 2 seconds (or longer): default { touch_start(integer i) { llSetTimerEvent(2.0); } touch_end(integer i) { llSetTimerEvent(0); } timer() { llSetTimerEvent(0); llSay(0,"I have been touched for 2 seconds."); } } Edited March 18, 2021 by Quistessa 1 Link to comment Share on other sites More sharing options...
Wulfie Reanimator Posted March 18, 2021 Share Posted March 18, 2021 (edited) 1 hour ago, Quistessa said: (Yes I know it might have been cleaner to use the bulb_lit=!bulb_lit; flipping trick) Not only that, but in simple cases like this, you don't even need any if-else cases. integer bulb_lit; default { touch_start(integer total_number) { bulb_lit = !bulb_lit; // Set 1 (true) or 0 (false) llSetPrimitiveParams([PRIM_POINT_LIGHT, bulb_lit, <1,1,1>, 1, 10, 2]); llSetPrimitiveParams([PRIM_GLOW, 0, 0.15 * bulb_lit]); } } The variable 'bulb_lit' directly correlates with the values we want to give as parameters. So if we do that, we don't need to duplicate code and there is less room for errors. OP's case is different though, as both cases have the light/glow on, just a different intensity and color. Edited March 18, 2021 by Wulfie Reanimator 5 Link to comment Share on other sites More sharing options...
Quistess Alpha Posted March 18, 2021 Share Posted March 18, 2021 Ooh, clever! for the case of both being on but different intensities you could scale and offset the on/off, so OP's case isn't actually that different, except for the fact that the hues are a bit different which would get a bit overly-complicated (but not actually impossible) to differentiate by scaling and offsetting the 'bulb_lit' variable. Link to comment Share on other sites More sharing options...
Mollymews Posted March 18, 2021 Share Posted March 18, 2021 building off Wulfie's code then in the case of switching between different vector values, we can use llList2Vector indexed on bulb_lit example: bulb_lit = !bulb_lit; llSetPrimitiveParams([PRIM_POINT_LIGHT, TRUE, llList2Vector([<0.000, 1.000, 0.50>,<0.041, 0.959, 0.959>], bulb_lit), 1, 10, 2]); 2 Link to comment Share on other sites More sharing options...
Wulfie Reanimator Posted March 18, 2021 Share Posted March 18, 2021 (edited) 31 minutes ago, Quistessa said: Ooh, clever! for the case of both being on but different intensities you could scale and offset the on/off, so OP's case isn't actually that different, except for the fact that the hues are a bit different which would get a bit overly-complicated (but not actually impossible) to differentiate by scaling and offsetting the 'bulb_lit' variable. 15 minutes ago, Mollymews said: building off Wulfie's code then in the case of switching between different vector values, we can use llList2Vector indexed on bulb_lit I think there comes a point where 'little tricks' can become a problem on their own. While getting rid of a conditional check can make the code simpler, care should be taken so that we don't replace it with something too fancy. For example, like you said, Quintessa, you could calculate different non-zero values based on an on/off toggle but it would get a bit overly-complicated and hurt readability more than the conditional. Likewise making function-calls can become slower and more memory-intensive than what we started with. Now, that's not to say that these things matter that much in a small script, or that the List2Vector is somehow unreadable or overly complex. I say this as a word of caution in the context of a much larger script where most/all conditionals were hidden as extra calculations, or if you're sharing your code with other people (to whom these things might be unexpected and confuse new readers). Edited March 18, 2021 by Wulfie Reanimator 1 Link to comment Share on other sites More sharing options...
Mollymews Posted March 18, 2021 Share Posted March 18, 2021 1 hour ago, Wulfie Reanimator said: Now, that's not to say that these things matter that much in a small script, or that the List2Vector is somehow unreadable or overly complex. I say this as a word of caution in the context of a much larger script where most/all conditionals were hidden as extra calculations, or if you're sharing your code with other people (to whom these things might be unexpected and confuse new readers). i agree with this sentiment i have to remember who I am responding to when posting code snippets. I should have prefaced my post with Quistessa's name in addressing Quistessa's underlying question: How might different vectors be fetched in a single statement ? i should also have mentioned that using llList2Vector in this way uses up 20 more runtime memory bytes (which is freed eventually by the garbage collector) than does using: If Else. But still, 20 memory bytes used unnecessarily at runtime is not good 1 Link to comment Share on other sites More sharing options...
Love Zhaoying Posted March 18, 2021 Share Posted March 18, 2021 7 hours ago, Quistessa said: bulb_lit=!bulb_lit; Now we know how many people it takes to change a light bulb! 1 Link to comment Share on other sites More sharing options...
RilaVirum Posted March 18, 2021 Author Share Posted March 18, 2021 (edited) Ok so to get the Timer to work, I have to write some conditionals for it? Ok l see there what I did, thank you Rolig. The touch_end! I thought touch_end is ment for the last touch?! Oo, thanks Quistessa for the code, I can see a bit better on how objects turn on and off, Thanks everyone. Edited March 18, 2021 by RilaVirum 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