Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Automatic Light

Alpha Zaius
llLol()
Join date: 13 Mar 2004
Posts: 1,187
06-07-2004 07:59
Heres a simple little automatic light thingy.
This script turns an object to a light at night and glass during the day:

CODE

default {
state_entry() {
llSetTimerEvent(60);
}
timer() {
vector sun = llGetSunDirection();
if(sun.z > 0) {
llSetPrimitiveParams([PRIM_MATERIAL,PRIM_MATERIAL_GLASS]);
}
else {
llSetPrimitiveParams([PRIM_MATERIAL,PRIM_MATERIAL_LIGHT]);
}
}
}


Enjoy! I wrote this in the forums, so if there is a problem, spot it out for me :D

My Shop
_____________________
Raemus Patel
Registered User
Join date: 21 Jun 2004
Posts: 29
discussion thread
06-24-2004 05:23
ne - /54/aa/42572/1.html
Cashmere Falcone
Prim Manipulator
Join date: 21 Apr 2004
Posts: 185
07-24-2004 11:07
Sytax Error, on a direct copy and paste?
_____________________
Jebus Linden for President! :p
Nada Epoch
The Librarian
Join date: 4 Nov 2002
Posts: 1,423
07-24-2004 17:02
llSetPrimitiveParams ([PRIM_MATERIAL,PRIM_MATERIAL_GLASS ]);
should be one line.
_____________________
i've got nothing. ;)
Alpha Zaius
llLol()
Join date: 13 Mar 2004
Posts: 1,187
08-17-2004 05:11
I wrote in on one line, just doesnt show that it is on one.
_____________________
Samhain Broom
Registered User
Join date: 1 Aug 2004
Posts: 298
09-25-2004 19:16
I just tried that on a sphere with all white, and it is not working... any ideas?

:eek:
_____________________
rm -rf /bin/ladden #beware of geeks bearing grifts
Douglas Baldwin
Registered User
Join date: 31 Mar 2004
Posts: 4
10-22-2004 02:38
remove the space between MATERIAL and _LIGHT

llSetPrimitiveParams([PRIM_MATERIAL,PRIM_MATERIAL _LIGHT]);
Eep Quirk
Absolutely Relative
Join date: 15 Dec 2004
Posts: 1,211
01-06-2005 01:51
Any way this can be made more efficient so it doesn't have to check ever 4 seconds if the sun is "up"? Surely that is a sim script resource drain. How about just checking the initial time and then, based on what the known day-night light cycle interval is, just using that instead?
Chromal Brodsky
ExperimentalMetaphysicist
Join date: 24 Feb 2004
Posts: 243
01-06-2005 14:53
From: Eep Quirk
Any way this can be made more efficient so it doesn't have to check ever 4 seconds if the sun is "up"? Surely that is a sim script resource drain. How about just checking the initial time and then, based on what the known day-night light cycle interval is, just using that instead?

Well, sim crashes, grid reboots, and time dilation would potentially mess with that. It'd probably make more sense to increase the sleep interval to somewhere between 60 and 300 seconds. The sun isn't changing fast enough to justify a check every four seconds...
Nexus Nash
Undercover Linden
Join date: 18 Dec 2002
Posts: 1,084
01-06-2005 18:57
*hits Alpha with a stick!* set that damn timer to something > 60.0!
_____________________
Shadus Stonebender
Evil Monkey
Join date: 17 Jan 2005
Posts: 37
01-20-2005 21:02
From: Eep Quirk
Any way this can be made more efficient so it doesn't have to check ever 4 seconds if the sun is "up"? Surely that is a sim script resource drain. How about just checking the initial time and then, based on what the known day-night light cycle interval is, just using that instead?


CODE

default {
state_entry() {
llSetTimerEvent(300);
}
timer() {
vector sun = llGetSunDirection();
if(sun.z > 0) {
llSetPrimitiveParams([PRIM_MATERIAL,PRIM_MATERIAL_GLASS]);
}
else {
llSetPrimitiveParams([PRIM_MATERIAL,PRIM_MATERIAL_LIGHT]);
}
}
touch_start(integer total_number) {
vector sun = llGetSunDirection();
if(sun.z > 0) {
llSetPrimitiveParams([PRIM_MATERIAL,PRIM_MATERIAL_GLASS]);
}
else {
llSetPrimitiveParams([PRIM_MATERIAL,PRIM_MATERIAL_LIGHT]);
}
}
}


I've not tested this yet... so not telling if it actually works, but its pretty simple it *should* work... just figured it'd be a slightly better method than checking every 4s... checks every 5m (i think), if its off (for whatever reason) after sundown or on after sunup you can toggle it to the correct state by touching it.... if it doesn't work i take no responsibility... *scurries off to hide*
Gryphon Stonebender
Registered User
Join date: 25 Jan 2005
Posts: 24
01-30-2005 00:42
Can't get either to work for me...
Mikayla Gillespie
Second Life Resident
Join date: 25 Nov 2004
Posts: 7
works like a charm
02-09-2005 22:05
i'm no scriptor - but this works like a charm!!! thanks so much for the great script. you can get some pretty cool effects. i stuck a big box in the middle of this dark forest and you could see it so well!

Thank you!
Alpha Zaius
llLol()
Join date: 13 Mar 2004
Posts: 1,187
02-20-2005 20:35
ok all, I havent looked at this post for a long time, and I just noticed 2.5k people read it. Sorry about the bugs in the code, I fixed it, and set the timer to something above 60 =) Also: Give it a minute to work if you put it in the dark when you first start it, actually, wait 65 seconds for it to update :)
_____________________
Keknehv Psaltery
Hacker
Join date: 11 Apr 2005
Posts: 1,185
Fix
04-11-2005 20:51
Why not just add an "on_rez" function to it, so it automatically checks when it is rezzed?

Here are a few general improvements:

CODE


integer state; //is it on or off?

state = 0; //starts at off


update()
{
if (state==0)
{
llSetPrimitiveParams([PRIM_MATERIAL,PRIM_MATERIAL_GLASS]);
}
else
{
llSetPrimitiveParams([PRIM_MATERIAL,PRIM_MATERIAL_LIGHT]);
}
}

checktime()
{
if(sun.z > 0)
{
state=0;
}
else {
state=1;
}
update();
}

default {
on_rez{
{
checktime();
}
state_entry() {
checktime();
llSetTimerEvent(300);
}
timer() {
checktime();
}
touch_start(integer total_number) { //invert current state, like a switch
if(state == 0)
{
state=1;
}
else {
state=0;
}
update();

}
}




That should work... I don't have access to an SL-capable computer right now.

Try it out.

Also, once I get back on SL, I'll see if I can modify those annoying reproductive fish to be sterile, and to just follow around their owner as a light. (You know, the generation0, generation1, etc. virus-plague things)
Rezz McMahon
Registered User
Join date: 11 May 2007
Posts: 7
09-27-2007 03:29
Ahhh thank you for this script i built lights for someone in sl and was wondering if there was anything like this. thank you thank you thank you