Jump to content

Would love a little help with this script please


kawolf
 Share

You are about to reply to a thread that has been inactive for 4363 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

Below is a script im trying to debug but not having much luck, ive made a target rezzer that rezzes 5 different coloured balls on  timed delay, each ball will take a max number of hits before it sends its score to the main listener and then self deletes. the script below is in the listener/rezzer, what im trying to do is get it to add all the reported scores together and then say a total in the main chat. A little help would be appreciated.

 

 

 

 

//inthelistener
//5 different unlinked objects report a number on 5 different channels
//how to take those 5 numbers and add them together to make listener object report a total
// llShout(-5872,(string)points+"");reported by each object just ondifferent channel

integer totalpoints = 0;//points = 0 at start
integer points = 0;
default
{
state_entry()
{
llListen(-5869, "red", "", "");//nameoffirstobject
llListen(-5870, "green", "", "");//nameofsecondobject
llListen(-5871, "blue", "", "");//nameofthirdobject
llListen(-5872, "yellow", "", "");//nameoffourthobject
llListen(-5873, "white", "", "");//nameoffifthobject
}
listen(integer channel, string name, key id, string message)
{
totalpoints = points + message;
}
{
llSleep(190);//amount of time from 1st object reporting to last object reporting + 5 secs
llSay (0, "total points=" +totalpoints);
llSleep(2);
llResetScript();
}

Link to comment
Share on other sites

At first glance, it looks to me that it's llSleep()ing through all the fun, then resetting. The listen() event will be raised only once this way. Instead of sleeping, you probably want to llSetTimerEvent(), total up the results from subsequent listen()s, and then report the total when the timer expires. Up to you how you want that timer to work, though; you may want to set it just once, the first time listen() happens, or maybe set it to some shorter, inter-listen() interval, and expire when time after any listen() is too long. (Or... however you want to decide you're done. You may want to report the results when you've heard from each coloured ball, regardless of how long its taken, so that would be different logic.)

EDIT: Oh, wait, all the sleeping stuff isn't part of the listen() handler. That's gonna be a syntax error. So... yeah, I guess it would help to know what the exact conditions are under which you want to be "done".

Link to comment
Share on other sites

// llShout(-5872,points);reported by each object 

// have the last ball shout "finished" before it dies?integer totalpoints = 0;//points = 0 at startinteger points = 0;default{ state_entry() { llListen(-5872, "", "", ""); } listen(integer channel, string name, key id, string message) { if(message) { totalpoints += (integer)message;} if (message == finished) { llSay (0, "total points= " + (string)totalpoints); llSleep(2); llResetScript(); } }}

 is this any closer mebbe...?

you could also make a list with all the balls, and report

the points from each ball seperately

 

if(name == red) { redpoints += (integer)message;}//If's to check each ball 

if(name == green) { greenpoints += (integer)message;}

if(name == blue) { bluepoints += (integer)message;}

if(name == yellow) { yellowpoints += (integer)message;}

if(name == white) { whitepoints += (integer)message;}

 

 totalpoints += redpoints + greenpoints + bluepoints + yellowpoints + whitepoints ; 

 

Link to comment
Share on other sites

Thanks for the advice everyone after tinkering round and playing with the ideas i finally got it to work,thats what i ended up with:))

// in the listener
integer points = 0;
integer totalpoints = 0;
integer message;
default
{
touch_start(integer total_number)
{



llListen(-5869, "red", "", "");
llListen(-5870, "green", "", "");
llListen(-5871, "blue", "", "");
llListen(-5872, "yellow", "", "");
llListen(-5873, "white", "", "");
llSetTimerEvent(240);

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

if(message) { totalpoints += (integer)message;}
}
timer()
{

llSay (0, "total points= " + (string)totalpoints);
llSleep(2);
llResetScript();
}
}

 

Link to comment
Share on other sites

There's no good reason for having five separate listen channels open to do this simple job.  Listen on one channel and just sum up the responses.  And get rid of the llSleep function in your timer event.  It's not doing anything.

If you want a very different way to keep track of responses from your five colored balls, name each of the balls after its color ("red", "green", "blue" ....) and have them llRegionSay anything at all on channel -1234567 when they get hit.  This script listens....

integer total;integer OK;integer handle;default{    touch_start(integer num)    {        if (!OK)        {            llSay(0,"Timer started.");            total = 0;            llSetTimerEvent(240.0);            handle = llListen(-1234567,"","","");            OK = TRUE;        }        else        {            llSay(0,"Resetting system.");            OK = FALSE;            llSetTimerEvent(0.0);            llListenRemove(handle);        }    }    listen( integer channel, string name, key id, string msg)    {        if (channel == -1234567)        {            integer idx = llListFindList(["red","green","blue","yellow","white"],[name]);            total += (integer)llPow(100.0,idx);        }    }        timer()    {        integer white = total/100000000;        integer yellow = (total=(total - white*100000000))/1000000;        integer blue = (total = (total - yellow*1000000))/10000;        integer green = (total = (total - blue*10000))/100;        integer red = (total - green*100);        llSay(0," \nwhite = "+(string)white+" \nyellow = "+(string)yellow        + " \nblue = "+(string)blue+ " \ngreen = "+(string)green         + " \nred = "+(string)red);        llSetTimerEvent(0.0);    }}

 

 

 

 

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 4363 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...