Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Script lag?

Eaglebird Cameron
YTMND *********
Join date: 1 Jul 2006
Posts: 68
07-27-2006 08:33
I have a script for a turret in SL.

I asked a question in Answers forum, because for part of the script I'd like to be able to implement some trig to correct the turret's view.

My question here is:
The turret fires a 'bolt', after it plays a sound, sleeps, sounds and fires simultaeneously. It seems to lag though, because a lot of times it will fire twice before returning to a controllable state, and may idle after firing for up to 5 seconds before it returns to a controllable state.
The first problem, double firing, may come from a double firing of my control event, left mouse button click held too long. I think this can be fixed with a quick sleep after the link message to fire is made, something like llSleep(0.5);
The lag isn't so easy though. I think a while script would work, but I don't know how to include it in the script. Even if I could, I have a feeling it would destroy the rest of the script, because it would ignore another on_touch event, which turns it on or off.
Bitzer Balderdash
Dazed and Confused
Join date: 21 Dec 2005
Posts: 246
07-27-2006 08:43
Kind of difficult to say without seeing the code - any chance you could post the scripts?

Also, with regards to your post in SL Answers about distance tracking, it is very much non-trivial to determine the first collider on a path (i.e. what you are looking at), but there are some ideas and suggestions that may help with that in the last couple of weeks in this forum.
Eaglebird Cameron
YTMND *********
Join date: 1 Jul 2006
Posts: 68
07-27-2006 08:50
From: Bitzer Balderdash
Kind of difficult to say without seeing the code - any chance you could post the scripts?

Also, with regards to your post in SL Answers about distance tracking, it is very much non-trivial to determine the first collider on a path (i.e. what you are looking at), but there are some ideas and suggestions that may help with that in the last couple of weeks in this forum.

Well the thing is I'm looking at a point in space. Not always an object or avatar. If I look off into void space, like, the sky for example, it's fine for the turret to copy my rotation. If I have ground or an object or an avatar in my 'crosshairs', though, I'd like for it to know the distance between me and it. Keep in mind this is all in mouselook.

I'll post the script in a bit, as soon as I load up SL and grab it.
Bitzer Balderdash
Dazed and Confused
Join date: 21 Dec 2005
Posts: 246
07-27-2006 08:56
From: Eaglebird Cameron
Well the thing is I'm looking at a point in space. Not always an object or avatar. If I look off into void space, like, the sky for example, it's fine for the turret to copy my rotation. If I have ground or an object or an avatar in my 'crosshairs', though, I'd like for it to know the distance between me and it. Keep in mind this is all in mouselook.

I'll post the script in a bit, as soon as I load up SL and grab it.


... and the only way to know if you are looking at a prim, an avatar, land, water, or the sky is to trace the path from your eye along the vector of where you are looking to see what it first collides with, which is what I was saying is a non-trivial task.

You can't use a scanner to do it with a very narrow cone, but that will miss prims unless you are looking at the geometric center of them, you can't use a wide cone, because that will give too many false positives.

You can't use a volumeDetect, becasue that would only detect if something moved into your line of sight

Which basically leaves rezzing "pings" - little physical bullets that move along the path, which will technically succeed in scanning along the line, and can report back when they hit something, but, of course, this one leaves you open to abuse reports for shooting people.
Eaglebird Cameron
YTMND *********
Join date: 1 Jul 2006
Posts: 68
07-27-2006 08:59
key owner;
key toucher;
string toucherS;
float SPEED = 80.0;
integer LIFETIME = 7;
float DELAY = 0.2;
vector vel;
vector pos;
rotation rot;
integer in_use;
integer have_permissions = FALSE;
integer armed = TRUE;

default
{
on_rez(integer startParam)
{
llResetScript();
}
state_entry()
{
owner = llGetOwner();
in_use = FALSE;
llTriggerSound("beep rez", 1.0);
llTriggerSound("gun lock", 1.0);
}
touch_start(integer total_number)
{
if(in_use == FALSE)
{
toucher = llDetectedKey(0);
if(toucher == owner)
{
llRequestPermissions(toucher, PERMISSION_TAKE_CONTROLS|PERMISSION_TRIGGER_ANIMATION);
llSetText("Requesting Permissions", <1,1,1>, 1);
llTriggerSound("beep question", 1.0);
}
}
if(in_use == TRUE)
{
if(llDetectedKey(0) == toucher && llDetectedKey(0) == owner)
{
llReleaseControls();
llSensorRemove();
llSetRot(<-0.00000, -0.00000, 0.70711, 0.70711>;);
llSetText("Unit Offline", <1,1,1>, 1);
llTriggerSound("beep no", 1.0);
in_use = FALSE;
}
}
}
sensor(integer sense)
{
rotation k = llDetectedRot(0);
llRotLookAt(k, 1, 1);
}
no_sensor()
{
llReleaseControls();
llSensorRemove();
llSetRot(<-0.00000, -0.00000, 0.70711, 0.70711>;);
llSetText("Unit Offline - Connection Lost", <1,1,1>, 1);
llTriggerSound("beep alert", 1.0);
in_use = FALSE;
}
run_time_permissions(integer perm)
{
if(perm)
{
llSetText("", <1,1,1>, 1);
llTakeControls(CONTROL_ML_LBUTTON, TRUE, FALSE);
llSensorRepeat("", toucher, AGENT, 20, TWO_PI, .1);
llSetText("Unit Online", <1,1,1>, 1);
llTriggerSound("beep yes", 1.0);
llTriggerSound("gun lock load", 1.0);
in_use = TRUE;
}
else
{
in_use = FALSE;
llSetText("Unit Offline", <1,3,1>, 1);
}
}
control(key name, integer levels, integer edges)
{
if ((levels & CONTROL_ML_LBUTTON) == CONTROL_ML_LBUTTON)
{
llMessageLinked(LINK_THIS, 0, "fire_nonmistakable", NULL_KEY); ///This is the messagelinked that fires the bolt. It may need a short llSleep after the messagelinked to keep it from seeing a continuous mouseclick?
}
}
link_message(integer sender_num, integer num, string fire_nonmistakable, key id)
{
rot = llGetRot();
vel = llRot2Fwd(rot);
pos = llGetPos();
pos = pos + vel;
pos.z += 0.0;
vel = vel * SPEED;
llTriggerSound("TESLACHA", 1.0); ///This is where the lag seems to start
llSleep(2);
llTriggerSound("TESLAZAP", 1.0);
llRezObject("Tesla Bolt", pos, vel, rot, 1); ///This can be rezzed up to three or four times before the script is back to normal control
}
}
Eaglebird Cameron
YTMND *********
Join date: 1 Jul 2006
Posts: 68
07-27-2006 09:01
From: Bitzer Balderdash

Which basically leaves rezzing "pings" - little physical bullets that move along the path, which will technically succeed in scanning along the line, and can report back when they hit something, but, of course, this one leaves you open to abuse reports for shooting people.

Which is what I'm trying to avoid. Even so, I think it'd be even laggier to fire ping bullets, communicate with me, then to the turret. Thats why I want to know of a function or possibility of a function which can do this.
Christopher Omega
Oxymoron
Join date: 28 Mar 2003
Posts: 1,828
07-27-2006 09:14
From: Bitzer Balderdash

You can't use a volumeDetect, becasue that would only detect if something moved into your line of sight

Which basically leaves rezzing "pings" - little physical bullets that move along the path, which will technically succeed in scanning along the line, and can report back when they hit something, but, of course, this one leaves you open to abuse reports for shooting people.


Make the ping bullets use llVolumeDetect :D
==Chris
Bitzer Balderdash
Dazed and Confused
Join date: 21 Dec 2005
Posts: 246
07-27-2006 09:15
From: Eaglebird Cameron
Which is what I'm trying to avoid. Even so, I think it'd be even laggier to fire ping bullets, communicate with me, then to the turret. Thats why I want to know of a function or possibility of a function which can do this.


Yeah, it is a pain at the moment - it makes it tough for things like smart bots to avoid moving into things, too.

There currently isn't anysuch function, and it is unlikely to be added in the forseeable future - but it can't do any harm to put in a feature request, and even to start a voting proposal.


Now... the script... a tip for future, is that it would be much easier to read if you put it in [ php ] [ /php ] tags....

You are checking the controls wrong - you will react on every control event for both clicks and holds of the mouse button, so you will probalby queue quite a few up...

Straight from the wiki
CODE
control(key id, integer held, integer change) {
integer pressed = held & change;
integer down = held & ~change;
integer released = ~held & change;
integer inactive = ~held & ~change;

if (pressed & CONTROL_LBUTTON) llOwnerSay("click");
}


shows how to select what controls have just been presses, which are still held, and which have been released.

Changing it over should be a lot better than just adding a sleep into the contrl() event, since that will stop it from firing the first time until the sleep is over, the event exits, and it can process the linkMessage, and you will still be queueing control events during that time.
Eaglebird Cameron
YTMND *********
Join date: 1 Jul 2006
Posts: 68
07-27-2006 19:27
Well, I don't want to queue the controls. I want one click = one shot. Two clicks in quick succession = one shot. Any number of clicks within the time period of about 3 seconds = 1 shot.

Also, I still don't know where the lag is coming from after the first shot.

CODE

key owner;
key toucher;
string toucherS;
float SPEED = 80.0;
integer LIFETIME = 7;
float DELAY = 0.2;
vector vel;
vector pos;
rotation rot;
integer in_use;
integer have_permissions = FALSE;
integer armed = TRUE;

default
{
on_rez(integer startParam)
{
llResetScript();
}
state_entry()
{
owner = llGetOwner();
in_use = FALSE;
llTriggerSound("beep rez", 1.0);
llTriggerSound("gun lock", 1.0);
}
touch_start(integer total_number)
{
if(in_use == FALSE)
{
toucher = llDetectedKey(0);
if(toucher == owner)
{
llRequestPermissions(toucher, PERMISSION_TAKE_CONTROLS|PERMISSION_TRIGGER_ANIMAT ION);
llSetText("Requesting Permissions", <1,1,1>, 1);
llTriggerSound("beep question", 1.0);
}
}
if(in_use == TRUE)
{
if(llDetectedKey(0) == toucher && llDetectedKey(0) == owner)
{
llReleaseControls();
llSensorRemove();
llSetRot(<-0.00000, -0.00000, 0.70711, 0.70711>);
llSetText("Unit Offline", <1,1,1>, 1);
llTriggerSound("beep no", 1.0);
in_use = FALSE;
}
}
}
sensor(integer sense)
{
rotation k = llDetectedRot(0);
llRotLookAt(k, 1, 1);
}
no_sensor()
{
llReleaseControls();
llSensorRemove();
llSetRot(<-0.00000, -0.00000, 0.70711, 0.70711>);
llSetText("Unit Offline - Connection Lost", <1,1,1>, 1);
llTriggerSound("beep alert", 1.0);
in_use = FALSE;
}
run_time_permissions(integer perm)
{
if(perm)
{
llSetText("", <1,1,1>, 1);
llTakeControls(CONTROL_ML_LBUTTON, TRUE, FALSE);
llSensorRepeat("", toucher, AGENT, 20, TWO_PI, .1);
llSetText("Unit Online", <1,1,1>, 1);
llTriggerSound("beep yes", 1.0);
llTriggerSound("gun lock load", 1.0);
in_use = TRUE;
}
else
{
in_use = FALSE;
llSetText("Unit Offline", <1,3,1>, 1);
}
}
control(key name, integer levels, integer edges)
{
if ((levels & CONTROL_ML_LBUTTON) == CONTROL_ML_LBUTTON)
{
llMessageLinked(LINK_THIS, 0, "fire_nonmistakable", NULL_KEY); ///This is the messagelinked that fires the bolt. I need to know what if statement to use to do a one shot = one click thing, etc., like I explained at first.}
}
link_message(integer sender_num, integer num, string fire_nonmistakable, key id)
{
rot = llGetRot();
vel = llRot2Fwd(rot);
pos = llGetPos();
pos = pos + vel;
pos.z += 0.0;
vel = vel * SPEED;
llTriggerSound("TESLACHA", 1.0); ///This is where the lag seems to start
llSleep(2);
llTriggerSound("TESLAZAP", 1.0);
llRezObject("Tesla Bolt", pos, vel, rot, 1); ///This can be rezzed up to three or four times, unintentionally, before the script is back to normal control
}
}
</DIV>
Eaglebird Cameron
YTMND *********
Join date: 1 Jul 2006
Posts: 68
07-28-2006 02:18
I figured it out. It was the llRezObject script delay.
I got past it by rezzing the object with a velocity of 1 and then having the object, no its own rez, llApplyImpulse.