Jump to content

Help needed with scripting


Kobra Stein
 Share

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

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

Recommended Posts

ok I do not want to post the script I need help with on here it is basically a notecard configured device that you can talk to on a channel defined in the notecard but I am having trouble getting the channel set via the notecard to the listen

 

I inclued this link to a simple notecard config which I used as my start of point Note Card Configuration (please note I set the link to open in a new link)

 

if you think you can help please feel free to contact me in Second Life via IM I am willing to pay L$  if  you are able to help me solve this and get it to a final working order

Link to comment
Share on other sites

You didn't specify if the communication is object-to-object or avatar-to-object.  Use negative channel numbers for object-to-object (inter-script communication example: llShout(-123456,"command"); and positive channel numbers for avatar-to-object (local chat example:  /4 command).

All notecard data is treated as text.  When you parse it, you need to sort it out into the various data types your script needs.  Your typical notecard data is going to have a keyword, separator and data (example:  channel=-123456).

Link to comment
Share on other sites

I have here is snippet of the code from the notecard

Channel = 75

 

and here is the two sections I am using it in

 

string Channelinit(){	//  reset configuration values to default	Channel = "90";	if(llGetInventoryType(configurationNotecardName) != INVENTORY_NOTECARD)	{		//  notify owner of missing file		llOwnerSay("Missing inventory notecard: " + configurationNotecardName);		//  don't do anything else		return;	}	//  initialize to start reading from first line (which is 0)	line = 0;	notecardQueryId = llGetNotecardLine(configurationNotecardName, line);}processConfiguration(string data){	//  if we are at the end of the file	if(data == EOF)	{		//  notify the owner		llOwnerSay("We are done reading the configuration");		//  notify what was read		llOwnerSay("The Channel is: " + Channel);		//  do not do anything else		return;	}	//  if we are not working with a blank line	if(data != "")	{		//  if the line does not begin with a comment		if(llSubStringIndex(data, "#") != 0)		{			//  find first equal sign			integer i = llSubStringIndex(data, "=");			//  if line contains equal sign			if(i != -1)			{				//  get name of name/value pair				string name = llGetSubString(data, 0, i - 1);				//  get value of name/value pair				string value = llGetSubString(data, i + 1, -1);				//  trim name				list temp = llParseString2List(name, [" "], []);				name = llDumpList2String(temp, " ");				//  make name lowercase (case insensitive)				name = llToLower(name);				//  trim value				temp = llParseString2List(value, [" "], []);				value = llDumpList2String(temp, " ");				//  name				if(name == "Channel")					Channel = value;								//  unknown name				else					llOwnerSay("Unknown configuration value: " + name + " on line " + (string)line);			}			//  line does not contain equal sign			else			{				llOwnerSay("Configuration could not be read on line " + (string)line);			}		}	}	//  read the next line	notecardQueryId = llGetNotecardLine(configurationNotecardName, ++line);}	state_entry()	{		init();		llListen(Channel, "",llDetectedKey(0), "");	}

 

Link to comment
Share on other sites

Yep, that's the problem.  You're storing the channel as a string and not an integer.  Upon further inspection, it appears you've posted a partial script, missing a number of items. The script, as posted, would never work.

 

  • Channel should be an integer, not a string, in order to store a numeric value (whole number).
  • Incoming notecard data is in the form of a string (text) and needs converted to an integer before storing into Channel.  Example:  Channel = (integer)value;  This is called typecasting (changing from one data type to another).
  • Since Channel is now numeric and not a string, your llListen will listen to the channel read by the notecard.
  • Name is being converted to lowercase to negate case sensitivity, but your IF statement for channel is comparing name to "Channel".  It should be "channel" because it will never match and thus never store the channel number in Channel.
  • Use llStringTrim(mystring,STRING_TRIM); to remove leading and trailing spaces from data, so your IF statements always catch data that otherwise might not match with the extra spaces..
  • Your dataserver event is missing.  Nothing would be read in that case. 
  • There are a number of other items missing from the script which I had to add in to make it work; taken from the wiki example.  Either you didn't paste a complete script or your script has always been incomplete and never would've worked.

I fixed the script you posted, to get it working.  It's up to you to make it your own.

 

integer Channel;
string configurationNotecardName = "Application.Config";
key notecardQueryId;
integer line;

init()
{
    //  reset configuration values to default
    Channel = 90;

    if(llGetInventoryType(configurationNotecardName) != INVENTORY_NOTECARD)
    {
        //  notify owner of missing file
        llOwnerSay("Missing inventory notecard: " + configurationNotecardName);
        //  don't do anything else
        return;
    }

    //  initialize to start reading from first line (which is 0)
    line = 0;
    notecardQueryId = llGetNotecardLine(configurationNotecardName, line);
}

processConfiguration(string data)
{
    //  if we are at the end of the file
    if(data == EOF)
    {
        //  notify the owner
        llOwnerSay("We are done reading the configuration");

        //  notify what was read
        llOwnerSay("The Channel is: " + (string)Channel);


        //  do not do anything else
        return;
    }

    //  if we are not working with a blank line
    if(data != "")
    {
        //  if the line does not begin with a comment
        if(llSubStringIndex(data, "#") != 0)
        {
            //  find first equal sign
            integer i = llSubStringIndex(data, "=");

            //  if line contains equal sign
            if(i != -1)
            {
                //  get name of name/value pair
                string name = llGetSubString(data, 0, i - 1);

                //  get value of name/value pair
                string value = llGetSubString(data, i + 1, -1);

                //  trim name
                list temp = llParseString2List(name, [" "], []);
                name = llDumpList2String(temp, " ");

                //  make name lowercase (case insensitive)
                name = llToLower(name);

                                
                name = llStringTrim(name,STRING_TRIM);

                //  trim value
                temp = llParseString2List(value, [" "], []);
                value = llDumpList2String(temp, " ");


                value = llStringTrim(value,STRING_TRIM);

                //  name
                if(name == "channel")
                    Channel = (integer)value; // Changed: String to Integer

                
                //  unknown name
                else
                    llOwnerSay("Unknown configuration value: " + name + " on line " + (string)line);

            }
            //  line does not contain equal sign
            else
            {
                llOwnerSay("Configuration could not be read on line " + (string)line);
            }
        }
    }

    //  read the next line
    notecardQueryId = llGetNotecardLine(configurationNotecardName, ++line);
}

default
{
    on_rez(integer start_param)
    {
        init();
    }
 
    changed(integer change)
    {
        if(change & (CHANGED_OWNER | CHANGED_INVENTORY))
            init();
    }
 
    state_entry()
    {
        init();
    }
 
    dataserver(key request_id, string data)
    {
        if(request_id == notecardQueryId)
            processConfiguration(data);
    }
}

 

When you get more comfortable with scripts, here's a before and after.  The data parsing code in the wiki example...

 

	//  if we are not working with a blank line	if(data != "")	{		//  if the line does not begin with a comment		if(llSubStringIndex(data, "#") != 0)		{			//  find first equal sign			integer i = llSubStringIndex(data, "=");			//  if line contains equal sign			if(i != -1)			{				//  get name of name/value pair				string name = llGetSubString(data, 0, i - 1);				//  get value of name/value pair				string value = llGetSubString(data, i + 1, -1);				//  trim name				list temp = llParseString2List(name, [" "], []);				name = llDumpList2String(temp, " ");				//  make name lowercase (case insensitive)				name = llToLower(name);				//  trim value				temp = llParseString2List(value, [" "], []);				value = llDumpList2String(temp, " ");				//  name				if(name == "channel")					Channel = (integer)value;								//  unknown name				else					llOwnerSay("Unknown configuration value: " + name + " on line " + (string)line);			}			//  line does not contain equal sign			else			{				llOwnerSay("Configuration could not be read on line " + (string)line);			}		}	}

 

...can be reduced to this...

 


if (llGetSubString(data, 0, 0) != "#" && llStringTrim(data, STRING_TRIM) != "")
{
if (llSubStringIndex(data, "=") > -1)
{
list temp = llParseString2List(data, ["="], []); string name = llStringTrim(llToLower(llList2String(temp, 0)), STRING_TRIM); string value = llStringTrim(llList2String(temp, 1), STRING_TRIM); if (name == "channel") { Channel = (integer)value; } else { llOwnerSay("Unknown configuration value: " + name + " on line " + (string)line); }

// Add other IF statements for your various notecard settings here.

} else { llOwnerSay("Configuration could not be read on line " + (string)line); }
}
Link to comment
Share on other sites

Yup, it looks like Ron was right.  You are reading Channel as a string variable and not converting it to an integer before you use it.  The easiest solution is to define Channel as an integer and then write

if (name == "Channel"){    Channel = (integer)value;}

 

BTW, For your future peace of mind, also note that you have omitted all of the {curly brackets} following if statements.  That is acceptable when you have only one line of code there, but it's not a safe practice.  It's too easy to forget that the brackets are missing when you add lines at a later date.  Curly brakets make it much easier to see where the scope of each segment of the script starts and ends.  :smileywink:

 

Link to comment
Share on other sites

One general issue: Please do specify in the subject of your forum message the abstract of your question. For example: "Loading channels with notecard?". Almost everyone who is posting here needs help with scripting, so your subject does not give the reader any usefull information. Thanks for being a bit more specific next time

PS: Oops, I wanted to reply to Kobra, not to Rolig!

Link to comment
Share on other sites

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