Jump to content

Dataserver help?


Shymus Roffo
 Share

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

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

Recommended Posts

i've been making a fire alarm system and i do not want the channels the same for ever building and i decided to use dataserver; But i have not been able to figure out how to use it, and the wiki is not really helping me...

All i'm trying to do is make it so that the channel numbers is controlled from the notecard;

example notecard

 

#The channel for sending/Recieving

Channel: -3432

#The Channel sent for the pager server

Pager Channel: -8754

Link to comment
Share on other sites

You want the user to be able to specify the communication channel number by submitting it on a notecard?  That's no harder than reading anything else from a notecard.  Look at the first, really simple example in the SL wiki page for llGetNotecardLine  All you have to remember, really, is that the data you read will be interpreted as a string.  You'll need to recast it as an integer to use it as a channel number.   If your notecard line includes anything other than the channel number itself, you'll have to parse it and select only the part that you need.  For example ....

 

integer idx = llSubStringIndex(data, ":");  // Find the colon in the datainteger Channel = (integer) llGetSubString(data,idx+1,-1);  // Save only the stuff after the colon and convert it to an integer

 

 

Link to comment
Share on other sites

So far this is what i have the channel is not sappoosed to work with a dialog

 

key kQuery;integer iLine = 0;integer channel;default {     state_entry()     {        kQuery = llGetNotecardLine("Settings", iLine);    }     dataserver(key query_id, string data) {         if (query_id == kQuery)         {            if(data == EOF)            {                //Do nothing            }             else             {                kQuery = llGetNotecardLine("Settings", iLine);                channel = (integer)data;                llOwnerSay("Channel: "+(string)channel);                iLine++;            }        }    }}

 

Link to comment
Share on other sites

Good so far.  Now, your dataserver event increments the notecard line variable iline, but doesn't trigger the event to read the next line.  You need to tell it again

kQuery = llGetNotecard Line("Settings", iline);

There's no real need to include the "// Do nothing" part of the event, since it does nothing.  Just read the lines you want to read and get on with the rest of your script.

Link to comment
Share on other sites

key kQuery;integer iLine = 0;integer channel;default {     state_entry()     {        llListen(channel,"","","");        kQuery = llGetNotecardLine("Settings", iLine);    }     dataserver(key query_id, string data)     {        if (query_id == kQuery)         {            kQuery = llGetNotecardLine("Settings", iLine);            channel = (integer)data;            iLine++;        }    }        listen(integer c, string n, key id, string msg)    {        if(c == channel)        {            if(msg == "Alarm On")            {                //Alarm On Functions            }            else if(msg == "Alarm Reset")            {                //Alarm Reset Functions            }        }    }}

 

Link to comment
Share on other sites

If your building is in one region, llRegionSayTo is definitely worth a look, you could use the dataserver for that too, so you'll get experience of using notecards. Unlike Rolig and Void I can't recall code off the top of my head and I have an early start in the morning, I save all my code inworld as aide memoires when I'm scripting, otherwise I'd post some examples, Rolig definitely knows what she's on about so hopefully she will be able to point you in the right direction.

Link to comment
Share on other sites

This would be for a note card named settings:

 

#SETTINGS NC

#Channel

-3432

#Pager Channel

-8754

 

This is how i would get the info needed from a nc  add more data lines if needed you can change it to integer /float/ key data depending on what you need.  This may be a bit rough im doing it off memory lol i use it a lot

state loadSettings{    state_entry()    {        integer found = FALSE;        integer x;         count = 0;        lineCount = 0;          for (x = 0; x < llGetInventoryNumber(INVENTORY_NOTECARD); x += 1)        {            if (llGetInventoryName(INVENTORY_NOTECARD, x) == "Settings")            {                found = TRUE;             }        }        if (found)        {            llOwnerSay("Reading Settings Notecard...");            readKey = llGetNotecardLine("Settings", lineCount);         }        else        {            llOwnerSay("Settings Notecard Not Found.");            llResetScript();        }    }    dataserver(key requested, string data)    {        integer integerData;            if (requested == readKey)         {             if (data != EOF)            {                if ((llSubStringIndex(data, "#") != 0) && (data != "") && (data != " "))                {                    integerData = (integer)data;                                         if (count == 0)                    {                        if (integerData >= 0)                        {                            channel = integerData;                        }                        else                        {                            channel = 0;                        }                    }                    else if (count == 1)                    {                        if (integerData >= 1)                        {                            pager_channel = integerData;                        }                        else                        {                           pager_channel = 1;                      }                                                count += 1;                }                lineCount += 1;                readKey = llGetNotecardLine("Settings", lineCount);            }            else            {                llOwnerSay("===============");                llOwnerSay("Channel is " + (string)channel);                llOwnerSay("pager channel  is " + (string)pager_channel );                llOwnerSay("===============");

 

 

Link to comment
Share on other sites

Sorry.... RL Christmas distractions trump all.  :smileywink:

Conrad's got the shape of the thing.  The form of a dataserver event is quite simple.

 

dataserver( key Qid, string data){    if(Qid == gReadKey) //Check to be sure that you are responding to the right request    {        if (data != EOF) // Check to be sure that you haven't already finished reading the entire notecard        {            if ((llGetSubString(data,0,0) != "#") && (llGetSubString(data,0,1) != " ")) // Check for a comment line or a blank line            {                integer idx = llSubStringIndex(data,":") // Find the ":" in the data string                integer temp = (integer)llGetSubString(data,idx+1,-1);  // The tail end of the data string is a channel                if (~llSubStringIndex(data,"Pager") // Check to see whether the string "Pager" is in this line of data; if so .....                {                    gPgChan = temp // This is the Pager Channel value                }                else                {                    gChan = temp;   // This is the communication channel                }            }            gReadKey = llGetNotecardLine("Settings",++gIline);   // Ask dataserver to read another line        }    }}

 Variables that I start with a "g" have to be global variables, because they are either passed from other parts of the script or are going to be used elsewhere.  You can dress this event up more by adding features, and you can certainly compress it more than I have.  I left it open so that I would be able to add comments to present the logic.

Once you have read and stored those values of gPgChan and gChan, you can do anything you wish with them.  This is a good exercise to have played with, because notecard reading is a fundamental technique.  As others have suggested, I'm not sure that this is the most appropriate way to pass a couple of integers to a script like this, but it works and it's what you chose.  I hope the rest of it goes smoothly for you.

Merry Christmas.

 

Link to comment
Share on other sites

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