Jump to content

How can i write it in LSL?


Yalnizxyz Footman
 Share

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

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

Recommended Posts

you can do arrays with json?

JsonGetValue

JsonSetValue

llJson2List

llList2Json

Here is a small example by Dora on how to use json that i was playing with,

... there should be forum posts on Json somewhere....

// JSON array forum example by Dora Gustafson, Studio Dora 2013
// Building an 3 by 5 array in a JSON Object
// Rows are indexed by name and columns are indexed by number = 0,1,2,3,4

string JSONVotes;
string JSONVotes2;

tellVotes( string voter)
{
    string Js = llJsonGetValue( JSONVotes, [voter]);
    list Jl = llParseString2List( Js,[",","[","]","\""],[]);
    string output = llDumpList2String( Jl, ", ");
    llOwnerSay( "Votes from "+voter+" are: "+output);
}
integer x;
string Main;
string votes;
default
{
    state_entry()
    {   // Building the JSON object
        votes = llList2Json( JSON_ARRAY, [0, 0, 0, 0, 0]); // one row
       // Main = llList2Json( JSON_OBJECT, ["MAIN",JSONVotes] );  <--- cannot define before or will be null
        JSONVotes2 = llList2Json( JSON_OBJECT, [ "Betty2", votes, "Jerry2", votes, "Pierre2", votes]); // complete object
        JSONVotes = llList2Json( JSON_OBJECT, [ "Betty", votes, "Jerry", votes, "Pierre", votes]); // complete object
         Main = llList2Json( JSON_OBJECT, ["MAIN",JSONVotes] );     //<--- top lvl defined last
    }
    touch_end( integer num)
    {   // Testing the JSON object
        ++x;
         llOwnerSay( "main before " +  Main);
         string name = llDetectedName(0);
           Main += (string) llList2Json( JSON_OBJECT, ["SECOND", JSONVotes2] );
         llOwnerSay( "main after " +  Main);
    }
}

 

Edited by Xiija
Link to comment
Share on other sites

Firstly, there is a typo in your C++ code in the original post. On line 2: " if (i<5); " you appear to have an erroneous semicolon at the end. so it wouldn't do what you expect it to do

Secondly, as other responders already mentioned, there's no arrays in LSL. The way around it is using lists. If it helps any, LSL lists are very similar to Python lists. Actually you can even emulate C++ array of structures using LSL strided lists, just have to be careful in indexing. The main thing to remember using lists is that LSL has no concept of reference so you put a whole object on the stack instead of a reference to object. Considering LSL memory restrictions it might be tricky to accommodate large lists.

 

 

 

 

Link to comment
Share on other sites

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