Jump to content

Notecard reader bug -- could you help debugging?


Swimmie Chaffe
 Share

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

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

Recommended Posts

Hi, I have used almost identical notecard reader codes in another project, and it was working fine in that setting. But when I used them, they are not working. In the first llOwnerSay (llOwnerSay(": "+data);), it returns lines in the NC, so it is reading something...but then in llOwnerSay in the end, two strings return as "unknown" (llOwnerSay("This board is for: " + avatar_rpname + " and the avatar key is "+ avatar_keyid);). The NC simply states:

Character Name=Swimmie
Key=2a7c9edd-bd0e-44ce-82ca-e9c18e38dc5f

in separate lines.

I'd appreciate if anyone can help me fixing this. Thank you in advance!


Swimmie

// Codes below//

 

//Notecard reader variables
integer VERBOSE = TRUE;
integer NoteLine;
integer gLN;
key NoteKey;
string notecard_name = "Avatar";
string avatar_rpname;
string avatar_keyid;



default
{
 on_rez(integer start_param)
    {
    
        llResetScript();
    }
    
    changed(integer change)
    {
        if(change & CHANGED_INVENTORY) llResetScript();
    }

    
    state_entry()
    {
       avatar_rpname="unknown";
       avatar_keyid="unknown";
        NoteLine = 0;
        gLN = 0;
        if( ~llGetInventoryType(notecard_name) )
        {
            NoteKey = llGetNotecardLine(notecard_name, NoteLine);
        }
        else
        {
            llOwnerSay("Notecard '"+notecard_name+"' was not found in inventory.");
        }
        
    }
    
      dataserver(key QueryID, string data)
    {
        if (QueryID == NoteKey)
        {
            if (data != EOF)
            {
                gLN++;
               if(VERBOSE)
                    llOwnerSay(": "+data);
                if(data != "")    // ignore blank lines
                {  
                    if(llGetSubString(data,0,0) != "#" ) // ignore comment
                    {
                         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);
                        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 == "Character Name")
                        avatar_rpname=value;
 
                        // key
                        else if(name == "Key")
                        avatar_keyid=value;
                        }
                    }
            
                }  
            NoteLine ++;
            NoteKey = llGetNotecardLine(notecard_name, NoteLine);
        }
   
    else //the end of the NC
        {
            llOwnerSay("This board is for: " + avatar_rpname + " and the avatar key is "+ avatar_keyid);
        }
    }
  }
 }

Link to comment
Share on other sites

You're welcome.

I'm just thinking about the nature and problems of coding, spurred by the 'researcher' thread.  It is often the case that we're so close to our code and know so well what it 'should' be doing, that it is very hard to spot this sort of thing in our own work but dead simple for someone else.  Asking for such assistance is what I've always known as 'a sanity check'.

Link to comment
Share on other sites

 


PeterCanessa Oh wrote:It is often the case that we're so close to our code and know so well what it 'should' be doing, that it is very hard to spot this sort of thing in our own work but dead simple for someone else. 


Hehehe... I think it's because we have all made the same mistakes over and over ourselves.  After a while, we become immune to them in our own work but they leap right out as familiar problems when we see them in a different setting.  I never see the paintings that have been hanging on my own walls for years, but I'm drawn immediately to paintings by the same artist on someone else's wall.

 

Link to comment
Share on other sites

Oh I entirely agree - we stop really looking at our own stuff and see what we expect, not what is really there.  As soon as we look at something different - someone else's or even an old example of our own work - we have to read it fresh and run it through our own compilers.

Link to comment
Share on other sites

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

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...