Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Repeating event on collision?

Synthia Gynoid
PRIMAL DREAMS
Join date: 10 Jul 2007
Posts: 52
11-15-2007 13:36
Hi, I'm fairly new to scripting, so please forgive if this question is inappropriate or covered elsewhere.

I'm trying to set up a situation whereupon entering an invisible prim volume, an avi triggers an event that keeps happening over and over while they're occupying that volume, but which ends as soon as they leave. I've set up a root prim (the invisible volume one) to use llVolumeDetect and collision_start to send a repeating link_message (on a timer) to a second linked prim, which actually does the repeating trigger event. The repeating event could be anything, like changing a texture or instantiating an object, etc...

My problem is that I can't seem to get out of the logic loop of repetition. I've been staring at this tiny bit of code for hours and trying everything I know (which admittedly isn't that much), but it won't work. Can someone tell me what I'm doing wrong?

Again, if this isn't the right place, I profusely apologize for any offense or disturbance.

Here are the scripts:

In the root prim:
---------------------------------
default
{
state_entry()
{
llVolumeDetect(TRUE); // turns llVolumeDetect on.
}

collision_end(integer num_detected) {
llMessageLinked(LINK_SET, 0, "deactivate", NULL_KEY);
}

collision_start(integer num_detected) {
llSetTimerEvent(1.0); // generate a timer event every 3 seconds;
}

timer()
{
integer phantom = llGetStatus(STATUS_PHANTOM);
if(phantom==FALSE)
{
llResetScript();
}else
{
if(phantom==TRUE)
{
llMessageLinked(LINK_SET, 0, "activate", NULL_KEY);
}
}
}
}
--------------------------------------


In the linked prim:
--------------------------------------
default
{
link_message(integer sender_num, integer num, string str, key id)
{
if(str=="activate";)
{
llSay(0,"activated";);
llSetColor(<llFrand(1.0),llFrand(1.0),llFrand(1.0)>,ALL_SIDES); // set a random color
}else
{
if(str=="deactivated";)
{
llSay(0,"deactivated";);
llSetColor(<1.0,1.0,1.0>,ALL_SIDES);
}
}
}
}
----------------------------



Again, the random color thing is just a dummy event, basically an event placeholder while I work up the logic structure. Same thing with the "activated" "deactivated" announcements.

Thanks for any help provided. :))
Galena Qi
Registered User
Join date: 9 Sep 2006
Posts: 249
11-15-2007 14:43
Your llMessageLinked says "deactivate", while your linked prim is listening for "deactivated"

Fix that and see if it works.

No scripting question is inappropriate in a scripting forum!
Synthia Gynoid
PRIMAL DREAMS
Join date: 10 Jul 2007
Posts: 52
11-15-2007 15:37
From: Galena Qi
Your llMessageLinked says "deactivate", while your linked prim is listening for "deactivated"


Yeah, that was a stupid syntax error on my part, lol. :) But even fixing it doesn't help... it starts announcing 'activated' and the color changes constantly, but after exiting the volume it doesn't stop color-changing, although it does announce 'deactivated'.

I looked at it some more, but can't spot the logic flaw or syntax misuse. Still learning, so please forgive if it's something obvious... that's just me being stupid, lol. :)
Nika Talaj
now you see her ...
Join date: 2 Jan 2007
Posts: 5,449
11-15-2007 15:44
Relative scripting noob here too, but you never deactivate the timer (llSetTimerEvent(0.)). So it keeps firing, and the only way I see for the loop to end is for the object to test as phantom TRUE, so the script gets reset.

But I don't see anything here that changes the object to phantom, tho I don't know the physics commands well ....
Synthia Gynoid
PRIMAL DREAMS
Join date: 10 Jul 2007
Posts: 52
11-15-2007 16:45
From: Nika Talaj
Relative scripting noob here too, but you never deactivate the timer (llSetTimerEvent(0.)). So it keeps firing, and the only way I see for the loop to end is for the object to test as phantom TRUE, so the script gets reset.

But I don't see anything here that changes the object to phantom, tho I don't know the physics commands well ....



No, you're right, but that's why I'm using llVolumeDetect.... on collision the big invisible prim goes phantom, automatically, and then resumes being solid after it stops encountering a physical object (avi). When I wrote it I was trying to use that as a way for the loop to test for continuing presence of an avi... when the avi takes up the detector-prim's volume at all, the test for phantom should be TRUE, then when they leave it should test FALSE.

Lol, but it's not working, so probably i'm not understanding correctly what I just explained. :D
Jacques Groshomme
Registered User
Join date: 16 Mar 2005
Posts: 355
11-15-2007 17:03
Once a timer event starts, it will keep going until you explicitly stop it using llSetTimerEvent(0). Such functionality is missing from your script.


It looks like you are attempting to stop it by reseting the script itself, but by having it in a condition that never evaluates true, the llResetScript() call is never being fired. You are checking for a non-phantom status, but you aren't ever setting such a status anywhere by calling llSetStatus().
Synthia Gynoid
PRIMAL DREAMS
Join date: 10 Jul 2007
Posts: 52
11-15-2007 17:19
From: Jacques Groshomme
Once a timer event starts, it will keep going until you explicitly stop it using llSetTimerEvent(0). Such functionality is missing from your script.


It looks like you are attempting to stop it by reseting the script itself, but by having it in a condition that never evaluates true, the llResetScript() call is never being fired. You are checking for a non-phantom status, but you aren't ever setting such a status anywhere by calling llSetStatus().



Thank you very much! :) I will go test the llSetTimerEvent(0) call. To your second point, I didn't set it up with a llSetStatus() call because I had thought that automatically, as soon as an avi vacates the llVolumeDetect() area, the volume would go back to solid status, and the llGetStatus(STATUS_PHANTOM) would return as FALSE, as a result. This may be (likely is) where I'm missing something basic about the way llVolumeDetect works, or something along those lines. In any event, I'll see if I can try what you describe. Thanks! :)
Synthia Gynoid
PRIMAL DREAMS
Join date: 10 Jul 2007
Posts: 52
11-15-2007 17:44
OMG that worked! :D

I put in both a llStopTimerEvent() and explicit statements at collision_start and collision_end to set the status as STATUS_PHANTOM as TRUE and FALSE, respectively.

Today I've learned something!

Thank you so much, Galena, Nika and Jacques! :D