Jump to content

Reading notecard by file name


MelodicRain
 Share

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

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

Recommended Posts

I'm trying to create a HUD that reads a specific notecard by matching it against what button in the HUD the user clicked, then parse the lines in the notecard and trigger some functions.

For example, I could have the following notecards stored in an object:

Notecard name: Note1, with following contents:

Quote

red,"Object has been painted red",-1

Notecard name: Note2, with following contents:

Quote

blue,"Object face2 has been painted blue",2

If the user clicks on a button in the HUD named "Note1", then it should parse the Note1 notecard by:

llSetColor(red,-1);
llOwnerSay("Object has been painted red");

Of course, "red" and "Object has been painted red" should be parsed from the notecard.

 

Can anyone get me started on how to accomplish this? I've gone through a few example scripts/tutorials but they all only read from one notecard.

 

 

Edited by MelodicRain
Link to comment
Share on other sites

The main things you need are:

llGetLinkName
llGetNotecardLine
llCSV2List

To set a color, you need to use a vector that contains the correct RGB values, red for example: <1,0,0> (check the llSetColor wiki page)

Reading from a notecard can be a bit tedious, especially if you need more than one line.

Edited by Wulfie Reanimator
  • Thanks 1
Link to comment
Share on other sites

Notecards are read asynchronously, that is, you can't get the notecard contents immediately after calling the notecard reading and have to handle it in the dataserver() event. There's really no particular magic to reading multiple notecards, even simultaneously: calling llGetNotecardLine returns a key which can be used to identify which request the event was a response to.

Assuming you strictly have that single line in a notecard, as in your example:

key nc_handle; // identifies the request

default {
  touch_start(integer _) {
      // use the touched prim's name as the notecard name
    string notecard_name = llGetLinkName(llDetectedLinkNumber(0));
    nc_handle = llGetNotecardLine(notecard_name, 0); // get the first line (0) of the notecard
  }

  dataserver(key id, string data) {
    // handle only the notecard read that was requested last
    if(id == nc_handle) {
      // data is the constant EOF when the notecard is finished
      if(data != EOF) {
        // parse the notecard line into variables
        list params = llCSV2List(data);
        vector color = (vector)llList2String(params, 0); // must use (vector)list2string instead of list2vector
        string message = llList2String(params, 1);
        integer face = llList2Integer(params, 2);
        llSetColor(color, face);
        llOwnerSay(message);
      }
    }
  }
}

Of course, you can't use human-readable color names like "red" and "blue" as colors in LSL directly, you need to use color vectors in the format <R, G, B> or write a function to do that yourself. The example code assumes you use a vector.

  • Thanks 1
Link to comment
Share on other sites

1 minute ago, Wulfie Reanimator said:

The main things you need are:

llGetLinkName
llGetNotecardLine
llCSV2List

To set a color, you need to use a vector that contains the correct RGB values, red for example: <1,0,0> (check the llSetColor wiki page)

Reading from a notecard can be a bit tedious, especially if you need more than one line.

I'm familiar with all the parts of the script other than picking out the correct notecard by matching the file name with the link name.

Link to comment
Share on other sites

llGetInventoryName(INVENTORY_NOTECARD,index); will give you the whole name of the notecard, starting with index 0 as the first notecard in the object's inventory.

state_entry()
{   llLinksetDataWrite("color:red","<1,0,0>");
    llLinksetDataWrite("color:blue","<0,0,1>");
}

touch_start(integer n)
{   string nameOfLink = llGetLinkName(llDetectedLinkNumber(0));
    if("note"==llGetSubString(nameOfLink,0,3))
    {   integer index = (integer)llGetSubString(nameOfLink,4,-1);
        string nameOfNote = llGetInventoryName(INVENTORY_NOTECARD,index);
        list nameParsed = llCSV2List(nameOfNote);
        // use the data:
        llSetColor(
          (vector)llLinksetDataRead("color:"+llList2String(nameParsed,0)),
          (integer)llList2String(nameParsed,2)
        );
        llOwnerSay(llList2String(nameParsed,1));
    }
}
  

 

  • Thanks 1
Link to comment
Share on other sites

Just now, MelodicRain said:

I'm familiar with all the parts of the script other than picking out the correct notecard by matching the file name with the link name.

Add a separate prim to your HUD, and rename it to match the notecard name in the HUD's contents. That way you can feed the value from llGetLinkName directly to llGetNotecardLine and read the correct card.

Link to comment
Share on other sites

2 minutes ago, Frionil Fang said:

Assuming you strictly have that single line in a notecard

Yeah it was unclear, I was assuming the notecards were litterally named red,"Object has been painted red",-1 etc. which is actually convenient in some cases.

Link to comment
Share on other sites

Just now, Quistess Alpha said:

Yeah it was unclear, I was assuming the notecards were litterally named red,"Object has been painted red",-1 etc. which is actually convenient in some cases.

Sorry, I meant the name of the notecard is "Note1", and the color/message is the content.

  • Like 1
Link to comment
Share on other sites

You could even have a separate script in each button, have that script send a linked message to the main prim with the "notecard name to read" in the linked message.

Then use link_message() in the main prim to interpret the message from the button prims as "go read this notecard".

There's many, many ways to do most tasks in LSL.  Most people just have their favorite way.

Link to comment
Share on other sites

8 hours ago, MelodicRain said:

I'm familiar with all the parts of the script other than picking out the correct notecard by matching the file name with the link name.

given that the link name is the same as the notecard name, then building off what Quistess wrote
 

touch_start(integer n)
{
   integer link = llDetectedLinkNumber(0);
   string notecard = llGetLinkName(link);

   // check that notecard is in Contents, when so then process
   if (llGetInventoryType(notecard) == INVENTORY_NOTECARD))
   {
      ... process(link, notecard) ...
   }
}

 

  • Like 1
Link to comment
Share on other sites

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