Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Adding llGetOwner troubles

Paul Wardark
Wait, what?
Join date: 10 Jan 2009
Posts: 383
07-25-2009 21:11
I have two scripts that work by touch. I'm trying to add if(llDetectedKey(0) == llGetOwner()) to these, so that only I can control them. Thing is, every time I put it in, I break the scripts. Anyone willing to help me out?


CODE


//Simple light switch. Click object with script turns light on and off.

integer light_switch;
vector light_color=< 1,1,1>;
float light_intensity=1.0;
float light_radius=04.0;
float light_falloff=1;


init ()
{

//Set light to off initially
light_switch=0;
llSetPrimitiveParams([ PRIM_GLOW, ALL_SIDES, 0.0,PRIM_POINT_LIGHT, FALSE, light_color, light_intensity, light_radius, light_falloff]);
//llOwnerSay("Set to midnight and click to toggle light!");

}

default
{
state_entry()
{

init();

}

on_rez(integer start_param)
{
init();
}

touch_start(integer total_number)
{
if(light_switch==1)
{
//Light is on, turn off
llSetPrimitiveParams([ PRIM_GLOW, ALL_SIDES, 0.0,PRIM_POINT_LIGHT, FALSE, light_color, light_intensity, light_radius, light_falloff]);
light_switch=0;
//llOwnerSay("Light turned off.");
}

else
{
//Light is off, turn on
llSetPrimitiveParams([ PRIM_GLOW, ALL_SIDES, 0.25,PRIM_POINT_LIGHT, TRUE, light_color, light_intensity, light_radius, light_falloff]);
light_switch=1;
//llOwnerSay("Light turned on.");
}

}

}



and

CODE


vector r_open = < 0.0, 0.0, 90.0>; // This prim's rotations in degrees relative to root prim when this prim is open
vector r_closed = < 0.0, 0.0, 10.0>; // and when it's in the closed state


integer close_on_rez = TRUE; // Change to false to have the prim open on rez

// ================================================== ===== Nothing from here down needs modding.

rotation LocalRot(rotation localrot)
{
rotation LocRot = localrot / ( (ZERO_ROTATION / llGetLocalRot()) * llGetRot());
return LocRot;
}

open(string door)
{
llSetPrimitiveParams([PRIM_ROTATION, LocalRot(llEuler2Rot(r_open * DEG_TO_RAD))]);
}

close(string door)
{
llSetPrimitiveParams([PRIM_ROTATION, LocalRot(llEuler2Rot(r_closed * DEG_TO_RAD))]);
}

default
{
state_entry()
{
if (close_on_rez)
{
state closed;
}
else
{
state opened;
}
}

on_rez(integer rez)
{
llResetScript();
}
}

state opened
{
state_entry()
{
open("left");
}

on_rez(integer rez)
{
llResetScript();
}

touch_start(integer n)
{
state closed;
}

}

state closed
{
state_entry()
{
close("left");
}

on_rez(integer rez)
{
llResetScript();
}

touch_start(integer n)
{
state opened;
}

}

_____________________
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
07-25-2009 22:00
So, what breaks? You have the syntax right. All you have to do is put bracket after the if statement to surround the code that you want to be affected....

CODE

if(llDetectedKey(0) == llGetOwner())
{
//do stuff
}


llDetectedKey will only work in your touch_start events, but that's most of the script anyway.
_____________________
It's hard to tell gender from names around here but if you care, Rolig = she. And I exist only in SL, so don't ask.... ;)

Look for my work in XStreetSL at
Paul Wardark
Wait, what?
Join date: 10 Jan 2009
Posts: 383
07-25-2009 22:55
I put it near the touch calls. When I do, I get a syntax error.
_____________________
Ron Khondji
Entirely unlike.
Join date: 6 Jan 2007
Posts: 224
07-25-2009 23:24
Don't put it near the touch events. Put it in them.
Like so:

CODE


touch_start(integer total_number)
{
if ( llGetOwner() == llDetectedKey(0) )
{

if(light_switch==1)
{
//Light is on, turn off
llSetPrimitiveParams([ PRIM_GLOW, ALL_SIDES, 0.0,PRIM_POINT_LIGHT, FALSE, light_color, light_intensity, light_radius, light_falloff]);
light_switch=0;
//llOwnerSay("Light turned off.");
}

else
{
//Light is off, turn on
llSetPrimitiveParams([ PRIM_GLOW, ALL_SIDES, 0.25,PRIM_POINT_LIGHT, TRUE, light_color, light_intensity, light_radius, light_falloff]);
light_switch=1;
//llOwnerSay("Light turned on.");
}
}
}

Paul Wardark
Wait, what?
Join date: 10 Jan 2009
Posts: 383
07-25-2009 23:52
Alright, thanks
_____________________