Jump to content

data from one object effecting which notecard is read in another.


Tighern McDonnell
 Share

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

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

Recommended Posts

Yes I am still a newbie when it comes to the scripting. Been in SL for 5 years now but just taking on scripting. Here is what I am trying to do...

Object A has a speak on channel X when touched. It says its description.

Object B currently listens for that description and then says a line on public channel. Very simple...

What I want to make it do is Object A stay the same... Object B, listen on channel for description, have that description be the name of the notecard on file in object B. Object B then reads the line contained on notecard...

Where I am confused is I use a listen line in current setup... everytime i try and put that set of lines in the other script it doesn't work.

 

key kQuery;
integer iLine = 0;
string notecard_name
key notecard_key = NULL_KEY;
 
config_init()
{
    key nc_key = llGetInventoryKey(notecard_name);
    if (nc_key == notecard_key)
    {
        // Some other inventory item changed, not the configuration notecard.
        return; // Skip reading the notecard in this case.
    }
    // Remember the new notecard key from now on.
    notecard_key = nc_key;
    iLine = 0;
    kQuery = llGetNotecardLine(notecard_name, iLine);
}
 
default
{
    state_entry()
    {
        // Read the notecard once at startup.
        config_init();
    }
 
    changed(integer change)
    {
        if (change & CHANGED_INVENTORY)         
        {
            // Read the notecard when the inventory has changed.
            config_init();
        }
    }
 
    dataserver(key query_id, string data) 
    {
        if (query_id == kQuery) 
        {
            // this is a line of our notecard
            if (data == EOF) 
            {
                llOwnerSay("Finished reading configuration.");
            } 
            else 
            {
                // TODO: handle notecard line here.  For not just inform the owner.
                llOwnerSay("Read notecard line: " + data);
                // increment line count
                ++iLine;
                //request next line of notecard.
                kQuery = llGetNotecardLine(notecard_name, iLine);
            }
        }
    }
}

 My question is how can i get the description from Object A and pass it along to Object B? This is a snip from a script in the wiki... really not sure where to go about it...

 

Link to comment
Share on other sites

This first script -- the one you pulled from the wiki -- reads a single notecard once when the script resets.  In this particular example, it doesn't do anything with the information that it reads. It doesn't even store it.  The interesting part is meant to be inserted where the script merely says "TODO: handle notecard line here." 

What you want to do is somewhat different.  You plan to have two or more notecards in your object B, choosing the one to read on the basis of a signal from object A.  So, what you'll want to do is move the stuff that's in the config_init block into a listen event.  Get rid of the state_entry and changed events, because they no longer make sense in your model.  When object A sends a message, then, it will flow through

listen (integer channel, string name, key id, string msg){    kQuery = llGetNotecardLine(msg,(iLine = 0));}

Assuming that you actually have a notecard with the proper name in object B's inventory -- you really ought to write a little if test to check -- that little bit in the listen event triggers the dataserver event and reads the chosen card.  The dataserver event stays as written except that, of course, you still have to deal with "TODO: handle notecard line here.".

Link to comment
Share on other sites

Here is what I have so far after adding the listen event in. 

key kQuery;integer iLine = 0;key notecard_key = NULL_KEY;string notecard_name; default{ state_entry(){    llListen(-25,"","","");}        listen (integer channel, string name, key id, string notecard_name){    kQuery = llGetNotecardLine(notecard_name,(iLine = 0));}    dataserver(key query_id, string data)     {        if (query_id == kQuery)         {            // this is a line of our notecard            if (data == EOF)             {                llSay(0, "End of information.");            }             else             {               llSay(0, data );               // increment line count                ++iLine;                //request next line of notecard.                kQuery = llGetNotecardLine(notecard_name, iLine);             }        }    }}

 What it is doing now is saying that it cannot find notecard "". I think I understand why. it is because I do not have notecard_name defined where it can be used under the dataserv event. But how do I do this then? Right now it will pick the right card, and read the first line but then will pop up the error.

Link to comment
Share on other sites

I guess your problem stems from the script in object A - do you say the object's description there? You have simplified your concept in your last post - in the second one, the listening script has two options in respect to what object  A says, so that you would have to do it a little differently from just saying the description, since you already say a command. There are again different ways to do that - here is one:

Object A still says either KFPadd or KFPadd2.

In object B, you can thus still differentiate betwenn the two commands - I assume, "data" should make the script read the nc. Now, you use llGetObjectDesc to get the description from object A so you have your nc name. If we include the check for the nc in the inventory of B, it could look something like this:

key kQuery;integer iLine;
string notecard_name;default{ state_entry() { llListen(-25,"","",""); } listen(integer chan, string name, key id, string msg) { if (msg == "KFPadd") { llSay(0, "notes"); } if (msg == "KFPadd2") {
norecard_name = ""; notecard_name = llList2String(llGetObjectDetails(id,[OBJECT_DESC], 0); if (llGetInventoryType(notecard_name) != -1) { kQuery = llGetNotecardLine(msg,(iLine = 0)); } else { llSay(0, "Notecard with the name: '"+ notecard_name + "' could not be found."); } } } dataserver(key query_id, string data) { if (query_id == kQuery) { // this is a line of our notecard if (data == EOF) { llSay(0, "End of information."); } else { llSay(0, data ); // increment line count ++iLine; //request next line of notecard. kQuery = llGetNotecardLine(notecard_name, iLine); } } }}

 

Link to comment
Share on other sites

Right. You have two variables named notecard_name.  One is a global variable, declared at the top of your script.  The other is a local variable, declared in the listen event.  The second one gets a value that is passed from your script in object A.  Since that notecard_name variable is different from the global one, though, the value is not available to the dataserver event.  Don't re-use variable names like that.

Darkie's got the idea.  If you really want to have object A send coded information to object B, instead of sending the notecard_names themselves, you'll have to provide a way to decode them in object B before you can use them.  My suggestion took the other approach, having object A send the notecard_names themselves instead of saying "KPFadd" or "KPFadd2".  In the end, it doesn't make any difference which way you do it.

Link to comment
Share on other sites

so what I am doing is having object b actually pass the name of the notecard in the listen event. Do I just need to make it a different variable name and have that stored as the global notecard_name variable so it can be accessed in the dataserve event? Going to be re-reading the variable section in the wiki tonight. Thank you for all your help. I'm starting to get hooked to scripting. As you can tell it is my first venture into programing that I have actually stuck with.

Link to comment
Share on other sites

In that case, you simply assign the actual message to the variable that contains the name of the notecard:

key kQuery;integer iLine;string notecard_name;default{	state_entry()	{		llListen(-25,"","","");	}	listen(integer chan, string name, key id, string msg)	{		notecard_name = msg;		if (llGetInventoryType(notecard_name) != -1) {			kQuery = llGetNotecardLine(notecard_name,(iLine = 0));		} else {			llSay(0, "Notecard with the name: '"+ notecard_name + "' could not be found.");		}	}	dataserver(key query_id, string data) {            if (query_id == kQuery) {            // this is a line of our notecard            if (data == EOF) {                llSay(0, "End of information.");            }             else {               llSay(0, data );               // increment line count                ++iLine;                //request next line of notecard.                kQuery = llGetNotecardLine(notecard_name, iLine);             }        }    }}

 

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 4163 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...