Jump to content

Json comes to LSL


Innula Zenovka
 Share

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

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

Recommended Posts

Via Nalates,  :https://wiki.secondlife.com/wiki/Json_usage_in_LSL

This works on the release channels, or should do.   I've just had a quick play with this, in a Magnum sandbox.   Making submenus should be a bit easier (or at least less cumbersome) from now on.

 

integer handle;
integer chan;
list mainMenu;
list subMenu;
list result;

string test;
default{

    state_entry(){
        chan = (integer)llFrand(1000000.0);
        test = llList2Json( JSON_OBJECT,
            ["Fruit",llList2Json(JSON_ARRAY,["Apple","Orange","Pear"]),
            "Colours",llList2Json(JSON_ARRAY,["Red","Green","Blue"]),
            "Drinks", llList2Json(JSON_ARRAY,["Tea","Coffee","Milk"])
                ]);
    //    llOwnerSay(test);
        result = llJson2List(test);
        mainMenu = llList2ListStrided(result,0,-1,2);
    }

    touch_start(integer total_number)
    {
        llListenRemove(handle);
        key k = llDetectedKey(0);
        handle = llListen(chan,"",k,"");
        llDialog(k, "Please choose an option",mainMenu,chan);
    }

    listen(integer channel, string name, key id, string message)
    {
        integer n = llListFindList(mainMenu,[message]);
        if(~n){
            subMenu = llParseString2List(llJsonGetValue(test,[message]),[",","[","]","\""],[]);
            llDialog(id, "Please choose an option",subMenu,chan);
        }
        else{
            llRegionSayTo(id,0,"You picked "+message);
        }
    }
}

 

  • Like 2
Link to comment
Share on other sites

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