Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

beginner question

Brendan Etzel
Registered User
Join date: 22 Jul 2007
Posts: 33
02-20-2009 10:22
I only just started to scripts things....

I have made a box that rezzes an object on touch with this :

touch_start(integer total_number) {

// This line will pick the first object out of the container and rez it
llRezObject(llGetInventoryName(INVENTORY_OBJECT,0), llGetPos()+<1.5,0,0>,ZERO_VECTOR,ZERO_ROTATION,0);

problem is it rezzes another object once I touch the box again

I've been reading the Wiki on LLGetStartParameter
Is that what you use to test if the object is rezzed and prevent rezzing another one?

Thanks,
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
02-20-2009 10:34
No, but you can script your way around the problem. One way to do it is to put a second script in the object to be rezzed. Then add language in the touch_start event in your parent object that calls out on a private channel to see if the rezzed object already exists. If the script in your second object replies, "Here I am!" on that private channel, then the touch_start event doesn't rez a new copy.
Ee Maculate
Owner of Fourmile Castle
Join date: 11 Jan 2007
Posts: 919
02-20-2009 10:38
Or assuming you want each object to be able to rez exactly one new object, use a flag to keep track of whether you have rezzed or not:

//
integer flag = 0; // initialise flag

default
{

touch_start(integer total_number) {

if(flag == 0) // if flag has not been changed yet
{

llRezObject(llGetInventoryName(INVENTORY_OBJECT,0) , llGetPos()+<1.5,0,0>,ZERO_VECTOR,ZERO_ROTATION,0);

flag = 1; // change flag so we know we have rezzed
}
}

}
//
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
02-20-2009 10:54
Yes, that method works. If you delete a rezzed object and later want to rez a new one, though, you won't be able to do it, because flag has already been set. It really depends on what the goal is. If you simply want to keep from having two rezzed copies at the same time, then you do something like this..

In the parent object ......

CODE

default
{
state_entry()
{
llListen(-3456,"",NULL_KEY,"");
}
touch_start(integer number)
{
llSay(-3456,"Anyone there?");
}
listen(integer channel, string name, key id, string message)
{
if (message == "Here I am!")
{return;}
else
{
llRezObject(llGetInventoryName(INVENTORY_OBJECT,0) ,llGetPos()+<1.5,0,0>,ZERO_VECTOR,ZERO_ROTATION,0);
}
}
}


and in the rezzable one ....

CODE

default
{
state_entry()
{
llListen(-3456,"",NULL_KEY,"");
}
listen(integer channel, string name, key id, string message)
{
if (message == "Anyone there?")
{
llSay(-3456, "Here I am!");
}
}
}
Brendan Etzel
Registered User
Join date: 22 Jul 2007
Posts: 33
02-20-2009 11:53
Thanks so much, that looks neat, I 'll go play with it in-world.
Not exactly beginner's material though.

/Brendan
Cherry Hainsworth
Registered User
Join date: 31 Jul 2006
Posts: 125
02-20-2009 15:38
No, it's OK, Brendan. Rolig's script is simple and easy to break down into steps (assuming it works - which it should do!)

The LSL wikis are your friends :) Just look up each "ll.." function and follow any links that catch your interest. You can simply Google them, you'll find all the wiki entries.
Also read up on states. Each wiki has a section on the main page, where touch_start, state_entry and all the rest are described.

It's a programming language. If this is your first, then you've had a soft landing. LSL is fairly basic (therefore, gives a decent grounding for other programming languages) and is incredibly well documented - although the documentation is messy!

If it's not your first, all you have to get your head around is the "making things do stuff in VR" aspect of it ... which still ties my brain in knots, almost 3 years in!!

Massively helpful script editor: LSLeditor by Alphons van der Heijden (SL: Alphons Jano). Download it from http://www.lsleditor.org/

Welcome :D

Cherry
_____________________
=================
My stuff on XSt:-
http://tinyurl.com/383mgh
Cypher Ragu
[Mad Scientist]
Join date: 6 Jul 2008
Posts: 174
02-21-2009 18:10
As an alternative to the flag option, you could have a sensor activate on the touch_start event.

That way, you can just put llRezObject in the no_sensor event.
_____________________
Life is a highway... And I just missed my exit.
Innula Zenovka
Registered User
Join date: 20 Jun 2007
Posts: 1,825
02-21-2009 18:22
From: Cypher Ragu
As an alternative to the flag option, you could have a sensor activate on the touch_start event.

That way, you can just put llRezObject in the no_sensor event.
Clarification for beginner scripters (cos i think this idea is a good one).. when someone touches the rezzer, that makes the rezzer use llSensor to look for one of the objects it rezzes. If it finds one, it doesn't do anything... it only rezzes one if it can't find one nearby (that's the no_sensor event).
Ruthven Willenov
Darkness in your light
Join date: 16 Jan 2008
Posts: 965
02-21-2009 18:52
From: Innula Zenovka
Clarification for beginner scripters (cos i think this idea is a good one).. when someone touches the rezzer, that makes the rezzer use llSensor to look for one of the objects it rezzes. If it finds one, it doesn't do anything... it only rezzes one if it can't find one nearby (that's the no_sensor event).


lol, that could be a way to make a temp rezzer cause more lag. (sensor repeat) not that i'd suggest it, just sayin
_____________________
Dark Heart Emporium

http://www.xstreetsl.com/modules.php?name=Marketplace&MerchantID=133020

want more layers for tattoos, specifically for the head? vote here
http://jira.secondlife.com/browse/VWR-1449?

llDetectedCollision* Functions similar to touch
http://jira.secondlife.com/browse/SVC-3369
Innula Zenovka
Registered User
Join date: 20 Jun 2007
Posts: 1,825
02-21-2009 21:19
From: Ruthven Willenov
lol, that could be a way to make a temp rezzer cause more lag. (sensor repeat) not that i'd suggest it, just sayin
Sorry, but I don't understand.

Why would anyone want to use llSensorRepeat for this? I thought the idea was that the rezzer sits there, doing nothing, until someone comes up and touches it. Then it needs to know if it should rez something or if there's something already there. So it fires off llSensor once, rezzes an object or doesn't, and then shuts down until you touch it again.
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
02-21-2009 22:01
What are you quoting? Anyway, I usually don't even use a sensor any more for that kind of rezzer. More often I can get away with llGetObjectDetails(), because I usually have the rezzer keep track of the object(s) it has rezzed. Since it knows who they are, it can look for them directly without having to do costly sensor sweeps.

Not that there AREN'T situations where you would want a sensor or even a repeated sensor. But you are right that you should carefully consider just how much you need and do no more than that.
Brendan Etzel
Registered User
Join date: 22 Jul 2007
Posts: 33
02-22-2009 05:28
After hours of puzzling I found that Rolig's script does not work for me. If there is no prim the script wil just sit there listening. It does not rez a new one.
So finally I did use a script with two states, this rezzes one object and no more:



default //default state is mandatory
{
state_entry() // runs each time the state is entered
{
}

touch_start(integer total_number) // another event with only one function inside
{
llRezObject(llGetInventoryName(INVENTORY_OBJECT,0) ,llGetPos()+<1.5,0,0>,ZERO_VECTOR,ZERO_ROTATION,0);
state off; // sets the script to a new "state" and starts running "state off"
}
} // this curly bracket ends the body of the default state.

state off // a second state besides "default"
{
state_entry() // this is run as soon as the state is entered
{

}

on_rez(integer start_param)
{
// Restarts the script every time the object is rezzed
llResetScript();
}

}
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
02-22-2009 08:33
Aha! Your solution is the simplest of all. Once it has rezzed an object, the script just shuffles off into purgatory until you re-rez the object. Nicely done.

I learned something here too. I had assumed that hearing nothing was the same as not hearing a message that says something. As a result, my suggested script listens for something ("Here I am!";) and does a fine job of ignoring it, but doesn't react when it hears nothing at all. So much for that idea. I wonder if there's a way to test for "no message"? :(
Ruthven Willenov
Darkness in your light
Join date: 16 Jan 2008
Posts: 965
02-22-2009 16:01
you could set a timer when you send the message "Anyone There?" if you don't get a response by the time the timer goes off, it'll rez the object, otherwise if it does get a response, it'll just turn the timer off

default
{
state_entry()
{
llListen(-3456,"",NULL_KEY,"Here I am!";);
}
touch_start(integer number)
{
llSay(-3456,"Anyone there?";);
llSetTimerEvent(20.00);
}

listen(integer channel, string name, key id, string message)
{
llSetTimerEvent(0.0);
}

timer()
{
llRezObject(llGetInventoryName(INVENTORY_OBJECT,0) ,llGetPos()+<1.5,0,0>,ZERO_VECTOR,ZERO_ROTATION,0);
llSetTimerEvent(0.0);
}
_____________________
Dark Heart Emporium

http://www.xstreetsl.com/modules.php?name=Marketplace&MerchantID=133020

want more layers for tattoos, specifically for the head? vote here
http://jira.secondlife.com/browse/VWR-1449?

llDetectedCollision* Functions similar to touch
http://jira.secondlife.com/browse/SVC-3369
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
02-22-2009 17:35
Single script:

CODE

key objKey;
string objName;
vector objVector;

rez(){
if (objVector == ZERO_VECTOR) {
llRezObject(objName, llGetPos() + <1.5,0,0>, ZERO_VECTOR, ZERO_ROTATION, 0);
}
}

obj(){
objName = llGetInventoryName(INVENTORY_OBJECT, 0);
}

default {
state_entry() {
obj();
}
touch_start(integer number) {
rez();
llSetTimerEvent(30.0);
}
timer() {
objVector = llList2Vector(llGetObjectDetails(objKey,[OBJECT_POS]), 0);
rez();
}
object_rez(key id) {
objKey = id;
}
changed(integer change) {
if (change && CHANGED_INVENTORY) {
obj();
}
}
}

If you wanted to use this for something like a vehicle so that the rezzed object could still be in the same sim but unavailable for someone else; then you could use an llVecDist test.
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime.
From: someone
I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
amiz Georgette
Registered User
Join date: 8 Jul 2008
Posts: 22
02-23-2009 07:01
Brendan I have to say I love the way you do your scripts... the break down I mean. This "simple" example really helped me out. I think in practice from now on I am going to do the same..over kill... meh maybe but very helpful to the scripting novice like me. I'm trying to do a sensor repeat particle target script for just one AV.