Jump to content

Problems, Read config from Notecard, llRegionSay not heard


ohn
 Share

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

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

Recommended Posts

hi!

i am doing something wrong and have been trying for hours to figure out what it is. I have two prims that i want to talk to each other, BASE and SAT. Each have a script in them and each have the same notecard in them. the notecard defines the listen channel, the object name of the BASE and the object name of the SAT. I modified scripts, which I believe I had found in the wiki, so that they were supposed to read the configs from the notecard. If either is touched, it should send a message to the other object. when either object hears a message sent to it from the other object, it should chat the message it received ... "should" that is, if i were doing it right.

It appears that both are successfully reading the notecard, as at one point i added llOwnerSay to check (now removed) and each appeared to correctly read the needed configs.

Any ideas? The notecard, SAT script, and BASE script are below:

//NOTECARD "config"
CHANNEL=93829488
SATNAME=SAT
BASENAME=BASE

 

//SAT script
//NOTECARD VARIABLES
integer line;
string ConfigurationFile = "config";
key readLineId;


integer listen_handle; 
integer listen_channel;
string base_name;


initialize()
{
    //NOTECARD INITIALIZATION
     
    // make sure the file exists and is a notecard
    if(llGetInventoryType(ConfigurationFile) != INVENTORY_NOTECARD)
    {
        // notify owner of missing file
        llOwnerSay("Missing inventory notecard: " + ConfigurationFile);
        return; // don't do anything else
    }
 
    // initialize to start reading from first line
    line = 0;
 
    // read the first line
    readLineId = llGetNotecardLine(ConfigurationFile, 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");
 
        // 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 configs
                list temp = llParseString2List(data, ["="], []);
                if(llGetListLength(temp) == 2) {
                    
                    if( llList2String(temp, 0) == "CHANNEL") {
                        
                        listen_channel = (integer) llList2String(temp, 1);
                       
                    }
                   
                    if( llList2String(temp, 0) == "BASENAME") {
                        
                        base_name = llList2String(temp, 1);

                    }
                   

                }

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

        }
    }
 
    // read the next line
    readLineId = llGetNotecardLine(ConfigurationFile, line++);
 
}



default
{
    state_entry() {
        initialize();
        listen_handle = llListen(listen_channel, base_name, "", "");
    
    
    }

    on_rez(integer start_param) {
        initialize();
    }

     touch_start(integer total_number)
    {
       
         llRegionSay(listen_channel,"msg TO base\n");
        
    }

    changed(integer change)
    {
     if(change & CHANGED_INVENTORY) initialize();
     if(change & CHANGED_OWNER) initialize();

    }

    listen( integer listen_channel, string name, key id, string message )
    {
           llSay(0, "MSG FROM BASE:" + message + "\n");
           
          
        
        
    }

     dataserver(key request_id, string data)
    {
        if(request_id == readLineId)
            processConfiguration(data);
 
    }

}

 

//BASE script
//NOTECARD VARIABLES
integer line;
string ConfigurationFile = "config";
key readLineId;

integer listen_handle;
integer listen_channel;
string sat_name;



initialize()
{
    //NOTECARD INITIALIZATION
     
    // make sure the file exists and is a notecard
    if(llGetInventoryType(ConfigurationFile) != INVENTORY_NOTECARD)
    {
        // notify owner of missing file
        llOwnerSay("Missing inventory notecard: " + ConfigurationFile);
        return; // don't do anything else
    }
 
    // initialize to start reading from first line
    line = 0;
 
    // read the first line
    readLineId = llGetNotecardLine(ConfigurationFile, 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");
 
        // 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 configs
                list temp = llParseString2List(data, ["="], []);
                if(llGetListLength(temp) == 2) {
                    
                    if( llList2String(temp, 0) == "CHANNEL") {
                        
                        listen_channel = (integer) llList2String(temp, 1);
                        
                    }
                    
                    if( llList2String(temp, 0) == "SATNAME") {
                        
                        sat_name = llList2String(temp, 1);
                    }
                }

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

        }
    }
 
    // read the next line
    readLineId = llGetNotecardLine(ConfigurationFile, line++);
 
}


default
{
    state_entry()
    {
        initialize();
        listen_handle = llListen(listen_channel, sat_name, "", "");
       
    }
    
    on_rez(integer start_param) {
        initialize();
    }


    touch_start(integer total_number)
    {
       
         llRegionSay(listen_channel,"msg TO SAT");
        
    }
    
      changed(integer change)
    {
     if(change & CHANGED_INVENTORY) initialize();
     if(change & CHANGED_OWNER) initialize();

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

           llSay(0, "MSG FROM SAT: " + message);    
      
       
    }
     dataserver(key request_id, string data)
    {
        if(request_id == readLineId)
            processConfiguration(data);
 
    }

}

 

Link to comment
Share on other sites

The problem in both scripts is that your script is never seeing the line in state_entry that defines listen_handle.  As soon as the script restarts and enters state_entry, it is told to run your user-defined function initialize.  That function, in turn, calls the dataserver event to read the notecard.  There's no way to get back to state_entry.  The point is that you cannot jump in and out of an event.  Once you're out, you're out.  The solution in this case is easy and is twofold.  The quick answer is to take the

listen_handle = llListen(listen_channel, base_name, "","");

and put it at the end of your dataserver event, so that it is executed after the notecard is read.  The second, longer, answer is to take as much of the stuff you have in user-defined functions and inline it instead.  Unless you are calling a function more than four or five times, it's inefficient to make the script jump out of an event to execute the function rather than just doing all the work right there.  Your functions are used once, when the script restarts and needs to read the card, so you don't need any user defined functions.  Inlining them will also help you avoid problems like the one you just had.

Link to comment
Share on other sites

I think the problem is that you open the listener before you're read the notecard, so it doesn't know what values to use for listen_channel and base_name (I'd have thought that creates an open listener on 0, but maybe not);

Anyway, I would try opening it when you've finished reading the notecard, not in state_entry, like this

if(data == EOF)	{		listen_handle = llListen(listen_channel, base_name, "", "");		// notify the owner		llOwnerSay("We are done reading the configuration");		// do not do anything else		return;	}

 ETA Rolig beat me to it.

Link to comment
Share on other sites

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