SubZeroWins Posted May 19, 2018 Share Posted May 19, 2018 Hello all, Im experimenting with the following script http://www.aliciastella.com/modules/AMS/article.php?storyid=39 to check whether its day or night. I put 2 seconds for the timer's interval but it seems that it doesn't work. Can anyone tell me why? Link to comment Share on other sites More sharing options...
Xiija Posted May 19, 2018 Share Posted May 19, 2018 (edited) Your isday variable is mebbe messin stuff up? dunno... this may work... integer time = 120; //How many seconds between checking Check() { vector sun_dir = llGetSunDirection(); if (sun_dir.z > 0 ) { llSay(0, "It is currently day."); //Do something here for when it is DAY. } else { llSay(0, "It is currently night."); //Do something here for when it is NIGHT. } } default { on_rez(integer start_param) { llResetScript(); } state_entry() { Check(); llSetTimerEvent(time); } touch_start(integer total_number) { Check(); } timer() { Check(); } } Edited May 19, 2018 by Xiija Link to comment Share on other sites More sharing options...
SubZeroWins Posted May 19, 2018 Author Share Posted May 19, 2018 17 minutes ago, Xiija said: Your isday variable is mebbe messin stuff up? dunno... this may work... integer time = 120; //How many seconds between checking Check() { vector sun_dir = llGetSunDirection(); if (sun_dir.z > 0 ) { llSay(0, "It is currently day."); //Do something here for when it is DAY. } else { llSay(0, "It is currently night."); //Do something here for when it is NIGHT. } } default { on_rez(integer start_param) { llResetScript(); } state_entry() { Check(); llSetTimerEvent(time); } touch_start(integer total_number) { Check(); } timer() { Check(); } } I tried that already, still doesn't work. Thanks. Link to comment Share on other sites More sharing options...
Rolig Loon Posted May 19, 2018 Share Posted May 19, 2018 That's one of the simplest scripts going. The only way it could fail would be if you mistyped the number 2. I can't imagine another reason . Two seconds is WAY too fast, though. The SL sky doesn't change that fast (neither does the RL sky). Two minutes is ideal. Link to comment Share on other sites More sharing options...
SubZeroWins Posted May 19, 2018 Author Share Posted May 19, 2018 9 minutes ago, Rolig Loon said: That's one of the simplest scripts going. The only way it could fail would be if you mistyped the number 2. I can't imagine another reason . Two seconds is WAY too fast, though. The SL sky doesn't change that fast (neither does the RL sky). Two minutes is ideal. I set it like integer time = 2 Is this wrong? Link to comment Share on other sites More sharing options...
Berksey Posted May 19, 2018 Share Posted May 19, 2018 (edited) integer time = 2; ^ That's how it should read. If you don't have a semicolon at the end, it shouldn't even compile, though... Edited May 19, 2018 by Berksey Link to comment Share on other sites More sharing options...
KT Kingsley Posted May 19, 2018 Share Posted May 19, 2018 Are scripts allowed where you're trying this out? Is the "Running" checkbox in the script editor checked? Are you getting an error when you try to save the script, or does it save ok, but then nothing happens? 1 Link to comment Share on other sites More sharing options...
Berksey Posted May 19, 2018 Share Posted May 19, 2018 OMG yeah, make sure the land you're on is set to allow scripts to run and/or that you have the right group tag on, etc. I got so distracted by the missing semicolon I forgot I was going to say that, too! Link to comment Share on other sites More sharing options...
Rolig Loon Posted May 19, 2018 Share Posted May 19, 2018 The missing semicolon would certainly kill it, yes. Even after you fix that, though, I strongly advise leaving the timer set at 120 seconds. Anything faster than that is unrealistic and a waste of server time. The sun simply does not rise or set fast enough to make a faster timer reasonable. 1 Link to comment Share on other sites More sharing options...
Berksey Posted May 19, 2018 Share Posted May 19, 2018 I agree with Rolig; in fact, I suggest trying a fresh copy and not changing it, and seeing what it does. I can understand setting it to something relatively low for testing purposes, also, but 2 seconds is really fast. If you have your script sending you feedback when testing, it'll overwhelm you with chat spam, and that gets annoying fast, too. If anything, for testing the script personally I would just remove the 0 from the end of 120, leaving the semicolon intact, and wait the twelve seconds to see the changes, if any, then set it back when finished testing the script. Link to comment Share on other sites More sharing options...
SubZeroWins Posted May 19, 2018 Author Share Posted May 19, 2018 Missing semicolon was only a typo while posting it. And yes, Its my land and I run other scripts with no problem. I will post the modified code Im using for my purposes (there are very few changes though) integer Countdown=5; integer IsDay; Check() { vector sun_dir = llGetSunDirection(); if (sun_dir.z > 0 && IsDay == FALSE) { IsDay = TRUE; } else if (sun_dir.z < 0 && IsDay == TRUE) { IsDay = FALSE; } Countdown=5; llSetTimerEvent(1.0); } default { on_rez(integer start_param) { llResetScript(); } state_entry() { vector sun_dir = llGetSunDirection(); IsDay = (sun_dir.z < 0); Check(); llSetTimerEvent(1.0); } timer() { Countdown--; if(Countdown==-1) { Countdown=5; Check(); } } } The problem appears when switching from day to night or the opposite. Its exactly the moment when the timer stops. Im not that experienced with lsl but I cant see the reason its happening. Btw, thank you all for your contributions. Link to comment Share on other sites More sharing options...
Xiija Posted May 19, 2018 Share Posted May 19, 2018 There is nothing wrong with my script or yours that i can see, try copying the script and rezzing a new prim to put it in. Link to comment Share on other sites More sharing options...
KT Kingsley Posted May 20, 2018 Share Posted May 20, 2018 (edited) How are you testing this? I ask because waiting through the SL four hour day cycle can be a bit tedious, so the temptation must be to take a short cut and manipulate the time of day manually. Now, I don't think that using the basic time of day settings will work here. I think you'd need to actually switch Windlight day settings to have an effect. Haven't actually tested this, so I'll log in right now… ETA: OK, what worked for me was to wear the scripted object as a HUD and then TP to some fixed sun regions that were either always day or always night, and one that had a contrary day cycle completely out of sync with the SL default. The script then correctly identified day and night. Sundarban - always day. Selidor - always night (just the night side of sunset) Skye Neist Point - has it's own idea of when night and day are I think to shortcut the testing you need to be able to set the Windlight for the region you're in, which means being the owner or an estate manager there. Any other setting will be viewer-side only. Edited May 20, 2018 by KT Kingsley Link to comment Share on other sites More sharing options...
animats Posted May 20, 2018 Share Posted May 20, 2018 10 hours ago, SubZeroWins said: I tried that already, still doesn't work. Thanks. I just tried it in a newly rezzed cube, and it's quietly ticking away. [19:54] Object: It is currently night. [19:54] Object: It is currently night. [19:56] Object: It is currently night. [19:58] Object: It is currently night. [20:00] Object: It is currently night. Sent the OP a working cube with the script inside. Link to comment Share on other sites More sharing options...
Fluffy Sharkfin Posted May 20, 2018 Share Posted May 20, 2018 5 hours ago, SubZeroWins said: Missing semicolon was only a typo while posting it. And yes, Its my land and I run other scripts with no problem. I will post the modified code Im using for my purposes (there are very few changes though) integer Countdown=5; integer IsDay; Check() { vector sun_dir = llGetSunDirection(); if (sun_dir.z > 0 && IsDay == FALSE) { IsDay = TRUE; } else if (sun_dir.z < 0 && IsDay == TRUE) { IsDay = FALSE; } Countdown=5; llSetTimerEvent(1.0); } default { on_rez(integer start_param) { llResetScript(); } state_entry() { vector sun_dir = llGetSunDirection(); IsDay = (sun_dir.z < 0); Check(); llSetTimerEvent(1.0); } timer() { Countdown--; if(Countdown==-1) { Countdown=5; Check(); } } } The problem appears when switching from day to night or the opposite. Its exactly the moment when the timer stops. Im not that experienced with lsl but I cant see the reason its happening. Btw, thank you all for your contributions. I don't know if you have anything else going on in your script that you've omitted which would require you to decrement the value of Countdown but if not then using a 1 second timer then only performing an action once every 6th time the event is triggered is hideously inefficient, you may as well just remove Countdown entirely and use a longer duration for the timer instead. Also there's no need for the llSetTimerEvent command in the Check() function since you set a timer in the state_entry event after calling the function and you only need to set the timer event once rather than each time the function is called. I'd strongly recommend you heed Roligs advice and use a much slower timer, 1 second (or even 6) is far too rapid for detecting a change that only happens once every few hours (you can always use the changed event to detect changes in sun position when moving between different regions, there really is no need to be using a timer that fast if all you're doing is checking to see if the sun is up). Additionally I can't help wondering if it would be simpler and more efficient to remove vector sun_dir = llGetSunDirection(); IsDay = (sun_dir.z < 0); from the state_entry event and replace the multiple if statements in the Check() function with Check() { vector sun_dir = llGetSunDirection(); IsDay = (sun_dir.z > 0); } so the final script would look something like this... integer IsDay; Check() { vector sun_dir = llGetSunDirection(); IsDay = (sun_dir.z > 0); } default { on_rez(integer start_param) { llResetScript(); } state_entry() { Check(); llSetTimerEvent(120.0); } timer() { Check(); } changed(integer change) { if (change & CHANGED_REGION) { Check(); } } } Link to comment Share on other sites More sharing options...
SubZeroWins Posted May 20, 2018 Author Share Posted May 20, 2018 8 hours ago, Fluffy Sharkfin said: I don't know if you have anything else going on in your script that you've omitted which would require you to decrement the value of Countdown but if not then using a 1 second timer then only performing an action once every 6th time the event is triggered is hideously inefficient, you may as well just remove Countdown entirely and use a longer duration for the timer instead. Also there's no need for the llSetTimerEvent command in the Check() function since you set a timer in the state_entry event after calling the function and you only need to set the timer event once rather than each time the function is called. I'd strongly recommend you heed Roligs advice and use a much slower timer, 1 second (or even 6) is far too rapid for detecting a change that only happens once every few hours (you can always use the changed event to detect changes in sun position when moving between different regions, there really is no need to be using a timer that fast if all you're doing is checking to see if the sun is up). Additionally I can't help wondering if it would be simpler and more efficient to remove vector sun_dir = llGetSunDirection(); IsDay = (sun_dir.z < 0); from the state_entry event and replace the multiple if statements in the Check() function with Check() { vector sun_dir = llGetSunDirection(); IsDay = (sun_dir.z > 0); } so the final script would look something like this... integer IsDay; Check() { vector sun_dir = llGetSunDirection(); IsDay = (sun_dir.z > 0); } default { on_rez(integer start_param) { llResetScript(); } state_entry() { Check(); llSetTimerEvent(120.0); } timer() { Check(); } changed(integer change) { if (change & CHANGED_REGION) { Check(); } } } I read that a timer's long interval consumes memory so I thought that a 1 second timer would be better, so when using the Countdown and reaching -1 to trigger the function and then start again from 5. Finally using the original script exactly as it is it does my work. Though Im very curious, back to my script integer Countdown=5; integer IsDay; Check() { vector sun_dir = llGetSunDirection(); if (sun_dir.z > 0 && IsDay == FALSE) { IsDay = TRUE; llOwnerSay("DAY"); } else if (sun_dir.z < 0 && IsDay == TRUE) { IsDay = FALSE; llOwnerSay("NIGHT"); } Countdown=5; llSetTimerEvent(1.0); } default { on_rez(integer start_param) { llResetScript(); } state_entry() { vector sun_dir = llGetSunDirection(); IsDay = (sun_dir.z < 0); Check(); llSetTimerEvent(1.0); } timer() { Countdown--; if(Countdown==-1) { Countdown=5; llOwnerSay("CHECK"); Check(); } } } The timer was printing "CHECK" every 5 seconds but when the day became night I was expecting it to print "NIGHT" but it didn't and it continued to print "CHECK". Link to comment Share on other sites More sharing options...
SubZeroWins Posted May 20, 2018 Author Share Posted May 20, 2018 11 hours ago, animats said: I just tried it in a newly rezzed cube, and it's quietly ticking away. [19:54] Object: It is currently night. [19:54] Object: It is currently night. [19:56] Object: It is currently night. [19:58] Object: It is currently night. [20:00] Object: It is currently night. Sent the OP a working cube with the script inside. Thank you pal. Link to comment Share on other sites More sharing options...
Ivanova Shostakovich Posted May 20, 2018 Share Posted May 20, 2018 (edited) Doesn't llSetTimerEvent() require a float? Edited May 20, 2018 by Ivanova Shostakovich Link to comment Share on other sites More sharing options...
Lindens Rider Linden Posted May 22, 2018 Lindens Share Posted May 22, 2018 I think that I see the what the issue may be. The problem is not your timer. From your testing you can see that it is happily ticking away. The problem is llGetSunDirection(). The current implementation of this function returns a vector to the current position of the region's sun. The keyword here is "region". The region's sun is not affected by whatever Windlight settings are applied to the region. (Think of it as pointing to an invisible sun... that gives its heat to everyone... ) When EEP rolls to the grid, this will no longer be the case. llGetSunDirection is being changed to accurately give you a vector pointed to the sun as calculated by the environment settings. There will additionally be a function added called llGetMoonDirection that will provide a vector pointing to the moon since it will be able to be moved independently. 5 Link to comment Share on other sites More sharing options...
Ruthven Ravenhurst Posted May 22, 2018 Share Posted May 22, 2018 2 hours ago, Rider Linden said: I think that I see the what the issue may be. The problem is not your timer. From your testing you can see that it is happily ticking away. The problem is llGetSunDirection(). The current implementation of this function returns a vector to the current position of the region's sun. The keyword here is "region". The region's sun is not affected by whatever Windlight settings are applied to the region. (Think of it as pointing to an invisible sun... that gives its heat to everyone... ) When EEP rolls to the grid, this will no longer be the case. llGetSunDirection is being changed to accurately give you a vector pointed to the sun as calculated by the environment settings. There will additionally be a function added called llGetMoonDirection that will provide a vector pointing to the moon since it will be able to be moved independently. EEP? Link to comment Share on other sites More sharing options...
Lindens Rider Linden Posted May 22, 2018 Lindens Share Posted May 22, 2018 EEP is the Environmental Enhancement Project. It allows you to store sky, water and day settings in your inventory. It revamps much of the old windlight code and adds a few new functions for interacting with the environment. Inara Pey is a much better writer than I am and did an excellent write up for the project. 2 Link to comment Share on other sites More sharing options...
Innula Zenovka Posted May 22, 2018 Share Posted May 22, 2018 Thanks, @Rider Linden. I wasn't aware llSetAgentEnvironment and llAdjustAgentEnvironment were in the pipeline (now I come to think of it, I may have seen an announcement at one point but I'd forgotten about it). Inara's article is dated last June, so almost a year ago. How are the functions progressing? Is there an ETA for them? Link to comment Share on other sites More sharing options...
Lindens Rider Linden Posted May 22, 2018 Lindens Share Posted May 22, 2018 It has been a long process but I'm nearing a point that I'll be able to start rolling out an initial project viewer very soon now. The most complex part has turned out to be the addition of settings objects to inventory, I think this is the first new inventory type that we've added since mesh so the change has taken quite a bit of archaeology, and more than a little prayer, to make. The first project viewer will most likely not have the scripting functions since I want to get settings into creator's hands as quickly as possible. They will follow soon after though. 3 Link to comment Share on other sites More sharing options...
martinmoun Posted October 27, 2019 Share Posted October 27, 2019 Rider, it's 1.5 years later. Can you confirm or disconfirm this, please? Quote The current implementation of this function returns a vector to the current position of the region's sun. The keyword here is "region". The region's sun is not affected by whatever Windlight settings are applied to the region. (Think of it as pointing to an invisible sun... that gives its heat to everyone... ) When EEP rolls to the grid, this will no longer be the case. llGetSunDirection is being changed to accurately give you a vector pointed to the sun as calculated by the environment settings. There will additionally be a function added called llGetMoonDirection that will provide a vector pointing to the moon since it will be able to be moved independently. Link to comment Share on other sites More sharing options...
Whirly Fizzle Posted October 27, 2019 Share Posted October 27, 2019 16 hours ago, martinmoun said: Rider, it's 1.5 years later. Can you confirm or disconfirm this, please? It's implemented now. http://wiki.secondlife.com/wiki/LlGetSunDirection http://wiki.secondlife.com/wiki/LlGetMoonDirection http://wiki.secondlife.com/wiki/LlGetRegionSunDirection 1 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