Change font size
It is currently Mon Feb 18, 2019 1:08 pm

Forum rules


{L_IMAGE}



Post a new topicPost a reply Page 1 of 1   [ 6 posts ]
Author Message
 Post subject: help wanted on NC writing and reading via a script.
PostPosted: Sat May 26, 2018 2:41 pm 
Furious Typer

Joined: Tue Oct 28, 2008 4:53 pm
Posts: 166
I'm trying to make a script that can read an NC's data 1 line at a time, then act on each piece of data without just reading the entire file.

EG.

{L_CODE}:
key Data_Query;
integer NC_Line;
string NC_Name = "Test Data";

default
{
          state_entry()
          {
                 if (llGetInventoryType(NC_Name) != -1)
                      {
                            Data_Query = llGetNotecardLine(NC_Name, NC_Line);
                       }
            }

             dataserver(key id, string data)
              {
                      if (id == Data_Query)
                          {
                               if (data == EOF)
                                   {
                                    }
                           llSay(0, data);
//                         placing variables here would assign the same variables the same data from the NC starting at line 0
                            ++NC_Line;
                             Data_Query = llGetNotecardLine(NC_Name, NC_Line);
                            }
                }
}


I'm running this of memory, so there might be some errors.

The way the script is now,,, it'll read the NC until the EOF is reached, but if I inserted a few variables in there, each variable would have the same data as the file,,, EG after the Data_Query line in the dataserver event, if I put something like:-

variable1 = data
variable2 = data
variable3 = data

variable1, 2 and 3 would get the same data until the EOF

What I want is for a script to read a line, assign a variable to the data, read the next line assign another variable to the data, and so on until the EOF is reached.

EG
if the NC has 4 line and the lines contain:-

12
5
7
200

the the script would read line 0 and assign a variable for the data 12, then read the next line then assign a different variable to 5, and so on.


Top
 Profile  
 
 Post subject: Re: help wanted on NC writing and reading via a script.
PostPosted: Sat May 26, 2018 6:44 pm 
Furious Typer
User avatar

Joined: Fri Mar 26, 2010 12:11 pm
Posts: 159
Location: Belgium / Brussels
I'm not sure I understood everything ... :P

Script:
{L_CODE}:
// Notecard Datas Reader v0.1 by djphil (CC-BY-NC-SA 4.0)

default
{
    state_entry()
    {
        string notecard = llGetInventoryName(INVENTORY_NOTECARD, 0);
       
        if (notecard != "")
        {
            integer i;
            integer x = 100;
            integer n = osGetNumberOfNotecardLines(notecard);
            llOwnerSay("DATA = " + x);

            for(i = 0; i < n; ++i)
            {
                x += (integer)llStringTrim(osGetNotecardLine(notecard, i), STRING_TRIM);
                llOwnerSay("DATA = " + x);
            }
        }
    }
}

Notecard:
{L_CODE}:
10
20
30
40
50

Enjoy! :)

_________________
Webmaster @ digitalconcepts.free.fr & digigrids.free.fr


Top
 Profile  
 
 Post subject: Re: help wanted on NC writing and reading via a script.
PostPosted: Sun May 27, 2018 5:01 pm 
Furious Typer

Joined: Tue Oct 28, 2008 4:53 pm
Posts: 166
Maybe this small B.A.S.I.C. snippet would explain it.

{L_CODE}:
DIM data$(4): REM Pretend this is a file and not stored in memory, 4 locations to hold 4 string items.

REM declare empty variables as integer
a = 0
b = 0
c = 0
d = 0

REM Assign data to each location simulating the NC in LSL.
data$(1) = "10"
data$(2) = "20"
data$(3) = "30"
data$(4) = "40"

REM Now read each location and assign a different variable to it's data, but being that the locations contain string data, a conversion is required to turn them into integer.

a = val(c$(1)): REM using an if condition here in LSL would check to see if a = 0 and if it does then assign a new variable as bool FALSE otherwise if a = 1 then assign that new variable to bool TRUE
b = val(c$(2))
c = val(c$(3))
d = val(c$(4))



Hopefully this helps,,,, being that I'm and old school BASIC programmer, this is the only way I can explain it :)

What I wanted was to have an NC with 4 items in 4 lines
{L_CODE}:
0
20
30
40

Then a script would read that NC 1 line at a time, and each line's data would be assigned to different variables.

EG

Being that NC lines start at 0 and NC data is text.

Line 0 = 0, a bool expression, thus assign a string variable to contain it's data, then check to see if that data is 0 or 1, and assign a new variable as an integer bool TRUE or FALSE

Line 1 = 20 assign a different variable but convert it from string to integer
Line 2 = 30 do the same
Line 3 = 40 do the same

Similar to this explanation:-

First check how many lines in the NC and use that as the EOF
Read NC line 0, assign a string variable then check to see if it's a 0 or 1 and if 0 then convert to integer and assign a different variable to FALSE, but if 1 then convert it to integer and assign that same new variable to TRUE

Read NC line 1, convert it's data from string to integer and assign another variable to it's data.
Read NC Line 2, the same
Read NC Line 3, the same

Resulting in 4 integer variables, each containing 1 line of the NC's data.

What shouldn't happen is the entire NC being read as one lump shot, and not using a loop of any kind,,, each line of the NC should be read individually, with each line's data being contained in 4 separate variables.


Top
 Profile  
 
 Post subject: Re: help wanted on NC writing and reading via a script.
PostPosted: Mon May 28, 2018 6:27 am 
Furious Typer
User avatar

Joined: Fri Mar 26, 2010 12:11 pm
Posts: 159
Location: Belgium / Brussels
I'm not sure I understood everything better now ... :P

Script:
{L_CODE}:
// Notecard Datas Reader v0.2 by djphil (CC-BY-NC-SA 4.0)

default
{
    state_entry()
    {
        string notecard = llGetInventoryName(INVENTORY_NOTECARD, 0);
       
        if (notecard != "")
        {
            integer data_0;
            integer data_1;
            integer data_2;
            integer data_3;

            integer line;
            integer lines = osGetNumberOfNotecardLines(notecard);

            for (line = 0; line < lines; ++line)
            {
                integer data = (integer)llStringTrim(osGetNotecardLine(notecard, line), STRING_TRIM);

                if (line == 0)
                {
                    if (data == 0) data_0 = FALSE;
                    else if (data == 1) data_0 = TRUE;
                   
                    else
                    {
                        llOwnerSay("ERROR: First line must be 0 or 1 ... and is " + data);
                        return;
                    }
                }

                else if (line == 1) data_1 = data;
                else if (line == 2) data_2 = data;
                else if (line == 3) data_3 = data;

                else
                {
                    llOwnerSay("ERROR: Too many lines in the notecard ("+lines+")");
                    return;
                }
            }

            llOwnerSay("data_0 = " + data_0);
            llOwnerSay("data_1 = " + data_1);
            llOwnerSay("data_2 = " + data_2);
            llOwnerSay("data_3 = " + data_3);
        }
    }
}

Notecard:
{L_CODE}:
0
20
30
40

Enjoy! :)

_________________
Webmaster @ digitalconcepts.free.fr & digigrids.free.fr


Top
 Profile  
 
 Post subject: Re: help wanted on NC writing and reading via a script.
PostPosted: Mon May 28, 2018 7:55 pm 
Furious Typer

Joined: Tue Oct 28, 2008 4:53 pm
Posts: 166
I tried that script,,, but it really didn't do what I wanted, but the below script with some modifying does what I wanted, even though it uses llSay for testing, it's basically what I wanted.

{L_CODE}:
list pbsSettings;
key pbsNC_Query;
integer pbsNC_Line;
string pbsNC_Name = "PBSSettings";

integer pbsListLength;
list pbsSetTemp;


// Test data - can be changed for testing.
integer pbsSetEngineAdvanced = TRUE;
integer pbsAccess = 2002;
integer pbsSetWindType = 2020;
// End test data.

list tempData;

list pbsMenu = ["RESET", "SAVE"];
integer pbsMenuChan = -778;

pbsInit()
{
    pbsNC_Query = llGetNotecardLine(pbsNC_Name, pbsNC_Line);
}

pbsSave(integer pbsSetEngineAdvanced, integer pbsAccess, integer pbsSetWindType)
{
    llSay(0, "Saving Settings......");
    pbsSettings = [pbsSetEngineAdvanced, pbsAccess, pbsSetWindType];
    if (llGetInventoryType(pbsNC_Name) != -1)
    {
        llRemoveInventory(pbsNC_Name);
    }
    osMakeNotecard(pbsNC_Name, pbsSettings);
}

default
{
    state_entry()
    {
        pbsInit();
        llListen(pbsMenuChan, "", NULL_KEY, "");
    }
   
    on_rez(integer params)
    {
        pbsInit();
    }
   
    touch_start(integer tot_num)
    {
        llDialog(llDetectedKey(0), "Select Option", pbsMenu, pbsMenuChan);
    }
   
    listen(integer chan, string name, key id, string msg)
    {
        if (msg == "RESET") pbsInit();
        if (msg == "SAVE") pbsSave(pbsSetEngineAdvanced, pbsAccess, pbsSetWindType);
    }
   
    dataserver(key id, string data)
    {
        if (id == pbsNC_Query)
        {
            if (data == EOF)
            {
                llSay(0, (string)tempData);
                integer pbsDataLength = llGetListLength(tempData);
                integer pbsDataLine = 0;
                if (pbsDataLine != pbsDataLength)
                {
                    if (llList2String(tempData, pbsDataLine) == "0") pbsSetEngineAdvanced = FALSE;
                    if (llList2String(tempData, pbsDataLine) == "1") pbsSetEngineAdvanced = TRUE;
                    ++pbsDataLine;
                    pbsAccess = (integer)llList2String(tempData, pbsDataLine);
                    ++pbsDataLine;
                    pbsSetWindType = (integer)llList2String(tempData, pbsDataLine);
                    ++pbsDataLine;
                }
                llSay(0, (string)pbsSetEngineAdvanced + "\n" + (string)pbsAccess + "\n" + (string)pbsSetWindType);
            }
            else
            {
                tempData = tempData + (list)data;
                ++pbsNC_Line;
                pbsNC_Query = llGetNotecardLine(pbsNC_Name, pbsNC_Line);
            }
        }
    }
}


Top
 Profile  
 
 Post subject: Re: help wanted on NC writing and reading via a script.
PostPosted: Tue May 29, 2018 9:53 am 
Furious Typer
User avatar

Joined: Fri Mar 26, 2010 12:11 pm
Posts: 159
Location: Belgium / Brussels
I'm curious, I'd like to understand ... If I'm too curious, ignore this message.

Since the script is still incomplete, it is a bit difficult to understand why to store the values of the notecard in a list and then apply them to variables.
I imagine that it is for the purpose of modifying their values before re-recording them in a new notecard.

Your script is a bit "strange".
- Why convert 0 and 1 to true/false ?
- The list contains an empty element.
- Listening to the menu remains open.

If you wish to improve/optimize it, you should say more about your final project.

_________________
Webmaster @ digitalconcepts.free.fr & digigrids.free.fr


Top
 Profile  
 
Display posts from previous:  Sort by  
Post a new topicPost a reply Page 1 of 1   [ 6 posts ]


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  


Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
610nm Style by Daniel St. Jules of Gamexe.net