Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Newbie script: turn lights on and off by touching them

Eggy Lippmann
Wiktator
Join date: 1 May 2003
Posts: 7,939
05-29-2005 08:24
I hate to see that in this year of 2005, there are still people using voice commands for the simplest little things, like turning a light on and off.
This simple little script illustrates how you can turn lights on and off without an open listener.
Please try to avoid open listeners when they're not necessary, as they will lag the sim for everyone even when you're not around to use them - and if you use them for simple everyday objects like pose balls and lights, then people will put 50 of them in the same parcel!

CODE


default
{
touch_start(integer total_number)
{
llSetPrimitiveParams([PRIM_MATERIAL, PRIM_MATERIAL_WOOD]);
state unlit;
}
}

state unlit
{
touch_start(integer total_number)
{
llSetPrimitiveParams([PRIM_MATERIAL, PRIM_MATERIAL_LIGHT]);
state default;
}
}
Editorial Hare
Second Life Resident
Join date: 11 Nov 2004
Posts: 116
05-29-2005 08:33
Even simpler..

CODE


integer on=FALSE;

default
{
touch_start(integer total_number)
{
if(on==TRUE)
{
llSetPrimitiveParams([PRIM_MATERIAL, PRIM_MATERIAL_WOOD]);
on=FALSE;
}

else
{
llSetPrimitiveParams([PRIM_MATERIAL, PRIM_MATERIAL_LIGHT]);
on=TRUE;
}

}
}

_____________________
Please see my alternate account disclaimer here

The world tolerates conceit from those who are successful, but not from anybody else. - John Blake
Zindorf Yossarian
Master of Disaster
Join date: 9 Mar 2004
Posts: 160
05-29-2005 09:40
I like Eggy's solution better. Very elegant, with the state change. Never seen a toggle built like that before.
_____________________
Badass Ninja Penguin: Killing stuff it doesn't like since sometime in May 2004.
Lefty Belvedere
Lefty Belvedere
Join date: 11 Oct 2004
Posts: 276
05-29-2005 20:40
is it safe to assume that sensors use the same amount of resources as a listener?


I thought about having somebody script me something that changes state based on the proximity of the owner. The idea was to save on light polution during the day and even at night by limiting the light phase to something like 50m from the owner (or any other avi)

does the presence of a sensor negate the effects of sving on light?

~Lefty
Jeffrey Gomez
Cubed™
Join date: 11 Jun 2004
Posts: 3,522
05-29-2005 20:53
From: Lefty Belvedere
does the presence of a sensor negate the effects of sving on light?

No. The presence of a sensor loop does.

If it has a timer or uses llSensorRepeat, it's still lagging a sim. If you simply must do this, use a long timer (like 60 - 120 seconds), and consolidate as many lights as possible into one timer.
_____________________
---
Kyrah Abattoir
cruelty delight
Join date: 4 Jun 2004
Posts: 2,786
05-30-2005 02:12
i add my two cents
CODE

default
{
state_entry()
{
llSetColor(<0,0,0>,0);
}
}
_____________________

tired of XStreetSL? try those!
apez http://tinyurl.com/yfm9d5b
metalife http://tinyurl.com/yzm3yvw
metaverse exchange http://tinyurl.com/yzh7j4a
slapt http://tinyurl.com/yfqah9u
Eggy Lippmann
Wiktator
Join date: 1 May 2003
Posts: 7,939
05-30-2005 06:30
For those who may not understand Kyrah's post, here's a quote from the wiki:

From: someone

Prelighting is where a prim/object is lit but does not actually emit a light source. However, SL's lit objects automatically become prelit yet also emit light. SL can fake full prelighting (but still emits an "invisible" light source that counts against framerate) by changing the color of side "0" (positive z-axis--"top";) of a prim to black.
Catherine Omega
Geometry Ninja
Join date: 10 Jan 2003
Posts: 2,053
05-30-2005 09:38
From: Zindorf Yossarian
I like Eggy's solution better. Very elegant, with the state change. Never seen a toggle built like that before.
Additionally, in Eggy's solution, there's absolutely no logic necessary, so it saves further resources. Each state can only do one thing, whereas with an "if (on)" check, the script must spend time checking to see what it's supposed to do, then setting the global variable for next time.
_____________________
Need scripting help? Visit the LSL Wiki!
Omega Point - Catherine Omega's Blog
Roseann Flora
/wrist
Join date: 7 Feb 2004
Posts: 1,058
05-30-2005 09:52
Thanks all :D
_____________________
Zalandria Zaius
Registered User
Join date: 17 Jan 2004
Posts: 277
prelighting
05-30-2005 10:05
O.k. I'm reading this wiki thing on the prelight and I don't really understand.

Why would you want to use an invisible light source that still takes up framerate over emiting a regular light?
Eggy Lippmann
Wiktator
Join date: 1 May 2003
Posts: 7,939
05-31-2005 03:59
Well, if you have local lighting turned off everything light looks prelit.
Meaning, shading is turned off and the object always appears at its maximum brightness, but it does not cast light on surrounding objects.
Larger objects cast light on a wider radius, which can be very bothersome to your neighbors
If you have a large purple sign, "prelighting" will make it just as visible as real lighting, but without the added effect of tinting half a sim purple :)
Zalandria Zaius
Registered User
Join date: 17 Jan 2004
Posts: 277
prelight
05-31-2005 08:08
Ahh good to know.. I do find my building being turned purple by the neighbors quite annoying..
Gydeon Fox
Registered User
Join date: 4 Mar 2005
Posts: 148
05-31-2005 19:50
Okay, if anyone's seen my question about why light sources are bad at the end of this thread:
/54/75/48415/1.html

Don't worry about answering it there, because I'm getting some useful answers here. :-)


Gydeon.
Gydeon Fox
Registered User
Join date: 4 Mar 2005
Posts: 148
05-31-2005 23:19
Hey Eggy,

I'm going to have some light sources at my place, but I'm going to be using your script for most of them. I like my nights dark because I dig the shadows and such, but if other people don't then they don't need the light sucking up their frame rate. Thanks for the easy option. :-)


Gydeon.
Kelli Javelin
Learning
Join date: 11 Jun 2005
Posts: 7
06-26-2005 02:56
From: Eggy Lippmann
I hate to see that in this year of 2005, there are still people using voice commands for the simplest little things, like turning a light on and off.
This simple little script illustrates how you can turn lights on and off without an open listener.
Please try to avoid open listeners when they're not necessary, as they will lag the sim for everyone even when you're not around to use them - and if you use them for simple everyday objects like pose balls and lights, then people will put 50 of them in the same parcel!

CODE


default
{
touch_start(integer total_number)
{
llSetPrimitiveParams([PRIM_MATERIAL, PRIM_MATERIAL_WOOD]);
state unlit;
}
}

state unlit
{
touch_start(integer total_number)
{
llSetPrimitiveParams([PRIM_MATERIAL, PRIM_MATERIAL_LIGHT]);
state default;
}
}



I am NEW I confess that:-)

How do I upload scripts to me and how do I place them - and where do I place them:-)))

Please dont hit me pls help me. *smiles*
Zapoteth Zaius
Is back
Join date: 14 Feb 2004
Posts: 5,634
06-26-2005 04:31
From: Kelli Javelin
I am NEW I confess that:-)

How do I upload scripts to me and how do I place them - and where do I place them:-)))

Please dont hit me pls help me. *smiles*


Copy paste them into a script in your inventory in world :-)

Then place them inside the object you want to use that script.
_____________________
I have the right to remain silent. Anything I say will be misquoted and used against me.
---------------
Zapoteth Designs, Temotu (100,50)
---------------
Eloise Pasteur
Curious Individual
Join date: 14 Jul 2004
Posts: 1,952
06-26-2005 07:38
From: Kelli Javelin
I am NEW I confess that:-)

How do I upload scripts to me and how do I place them - and where do I place them:-)))

Please dont hit me pls help me. *smiles*


Ignorance is fine, we all share (with the exception of the guru's) our ignorance here, as well as eventually some hard learnt truths.

Stupidity is more likely to get you hit - so don't ask the same question next week! :) But seriously, welcome to SL and the scripting tips forum. We are usually pretty nice here. And Zap's already answered your serious question.
PetGirl Bergman
Fellow Creature:-)
Join date: 16 Feb 2005
Posts: 2,414
06-26-2005 11:06
I must test it I to... when can we expect studio flashes in SL??? Like Broncolour or Profoto?