Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

I am having problems with a script (included)

Vade Blair
Tattoo Artist
Join date: 19 Mar 2004
Posts: 132
01-05-2005 18:06
Gun thinggy

CODE
integer shoot = FALSE;

default
{
state_entry()
{
llListen( 0, "", "", "fire" );
llListen( 0, "", "", "stop" );
}

listen(integer channel,string name, key id, string message)
{
while (shoot)
{
if (message == "fire");
{
shoot = TRUE;
}
llSleep(0.50);
vector pos = llGetPos();
llRezObject("spear",pos,<1,1,0>,<0,0,0,1>,0);
}
if(message == "stop")
{
shoot = FALSE;
}
}
}


Controller

CODE
default
{
collision_start(integer tnum)
{
llVolumeDetect(TRUE);
llShout(100,"fire");
}
collision_end(integer tnum)
{
llShout(100,"stop");
}
}


Just trying to make a "trap" on the land, this is not working... perhaps I am overlooking something, any help?
_____________________
Selling exclusively on SLExchange : My Items

RaNdOm CrAp

DoteDote Edison
Thinks Too Much
Join date: 6 Jun 2004
Posts: 790
01-05-2005 18:12
What doesn't work about it? It looks like the controller shouts on channel 100, but the gun listens on channel 0.

Also, maybe the llVolumeDetect() in your controller should be under default, instead of collision_start().
Vade Blair
Tattoo Artist
Join date: 19 Mar 2004
Posts: 132
01-05-2005 18:26
From: DoteDote Edison
What doesn't work about it? It looks like the controller shouts on channel 100, but the gun listens on channel 0.

Also, maybe the llVolumeDetect() in your controller should be under default, instead of collision_start().


Oh I changed it to 0 to test it on the main channel, it still does not work... good catch. llVolumeDetect runs the same in state_entry as it does in collision or collision_start

EDIT: What does not work about it is the rezzer is not rezzing. The problem is in these scripts somewhere, and I have been trying to figure out what the problem is.
_____________________
Selling exclusively on SLExchange : My Items

RaNdOm CrAp

Ardith Mifflin
Mecha Fiend
Join date: 5 Jun 2004
Posts: 1,416
01-05-2005 18:35
Two things: You should use public channel listens as infrequently as possible. In this case, you've initialized two separate listens when one could do the job just as well. Also, I don't think the velocity vector you're using in the rez call is high enough. Try experimenting with vectors of greater magnitude. If the collision events are firing, then it's possible your bullets just aren't getting enough oomph.

I've got some really bad code below. It probably won't even compile, and is probably of limited use. But I took the time to type it out, so I'll post it anyways.

default
{
state_entry()
{
llListen(0, "", "", "";);
}

listen(integer channel,string name, key id, string message)
{
while (message == "fire";);
{
llSleep(0.50);
vector pos = llGetPos();
llRezObject("spear", pos, <100,0,0>, ZERO_ROTATION, 0);
}
}
}
Ardith Mifflin
Mecha Fiend
Join date: 5 Jun 2004
Posts: 1,416
01-05-2005 18:37
From: Vade Blair
EDIT: What does not work about it is the rezzer is not rezzing. The problem is in these scripts somewhere, and I have been trying to figure out what the problem is.


That's probably because in your listen, shoot is initially false. Your rezzing code is contained with the while loop, which checks to see if shoot is true. Since shoot is initially not true, then the contents of the while loop are never executed.

I think...
Vade Blair
Tattoo Artist
Join date: 19 Mar 2004
Posts: 132
01-05-2005 18:42
From: Ardith Mifflin
That's probably because in your listen, shoot is initially false. Your rezzing code is contained with the while loop, which checks to see if shoot is true. Since shoot is initially not true, then the contents of the while loop are never executed.

I think...


:confused: I thought all while loops have to be initially false, otherwise it will run no matter if the condition has been met or not. As far as the listens, I have them both on chan 0 for now, just so I could get it working... they will change when it works.
_____________________
Selling exclusively on SLExchange : My Items

RaNdOm CrAp

Kurt Zidane
Just Human
Join date: 1 Apr 2004
Posts: 636
01-05-2005 18:54
CODE
integer shoot = FALSE;

default
{
state_entry()
{
llListen( 0, "", "", "fire" ); // no need for two listens. Call it as llListen( 0, "", "", "" );
//I would also set it to listen to you , or the object. not every one.
llListen( 0, "", "", "stop" );
}

listen(integer channel,string name, key id, string message)
{
while (shoot) // shoot == FALSE so any thing in the bracket bellow dose not run.
{
if (message == "fire");
{
shoot = TRUE;
}
llSleep(0.50);
vector pos = llGetPos();
llRezObject("spear",pos,<1,1,0>,<0,0,0,1>,0);
}
if(message == "stop")
{
shoot = FALSE;
}
}
}


it appear what you want to do .. if { on fire { set timer .50} } else if { on stop { set timer to 0.0 (o.o is off) } }
in the timer get pos, rex object at pos.
Vade Blair
Tattoo Artist
Join date: 19 Mar 2004
Posts: 132
01-05-2005 18:58
From: Kurt Zidane
it appear what you want to do .. if { on fire { set timer .50} } else if { on stop { set timer to 0.0 (o.o is off) } }
in the timer get pos, rex object at pos.


I am sorry, I am having problems understanding what you are trying to say.
_____________________
Selling exclusively on SLExchange : My Items

RaNdOm CrAp

Danny DeGroot
Sub-legendary
Join date: 7 Jul 2004
Posts: 191
01-05-2005 19:41
Hi Vade,

At first glance, I see a couple of things that could be giving you problems.

Ardith gave you one of them...if you enter a "while" loop with a false condition, the interior code never gets executed.

Also: chat events are queued, and listen events fire once for each incoming message. If you start running a loop inside a listen, I don't think you'll get a chance to hear the "stop" message. You need the message to get out of the loop. But the loop won't finish until it hears the message. And the listen handler has to exit (and re-fire) before the "stop" message makes it into the script. But it won't because it's in a loop.

I _think_ that's right.

Here's something that's laid out a little simpler, that might get you where you're going:

CODE


default {

state_entry() {
llListen( 0, "", "", "" );
}

listen( integer channel, string name, key source, string msg ) {
if ( "stop" == msg ) {
llSetTimerEvent( 0.0 );
}
if ( "shoot" == msg ) {
llSetTimerEvent( 0.5 );
}
}


timer() {
//
// Aiming/rezzing code goes here
//
}


}



== danny d.
Vade Blair
Tattoo Artist
Join date: 19 Mar 2004
Posts: 132
01-06-2005 14:03
Thnaks Danny, I actially got it working last night by doing something similar to what you posted. Anyone who would want to do something sililar, I would suggest following Danny's basic code, mine is a bit more complex, but his will work flawlessly.
_____________________
Selling exclusively on SLExchange : My Items

RaNdOm CrAp