1

Recently I started playing with Second Life. And wanted to start coding for it in LSL.

In my program, I want to change color of my avatar's shirt according to the color I mention in a Notepad file and I'm continuously changing the value randomly (writing values to Notepad), like Red to Green or to Blue etc.

But the problem is I'm stuck at how to read Notepad file (stored on my local HDD) into Second life using LSL (Linden Scripting Lang). I tried to read it as suggested here by setting my local apache server, but we cant do that as its not recognized as its not a webserver hosted over internet.

Can we do it using NoteCard...?

lonesomeday
  • 233,373
  • 50
  • 316
  • 318
kAmol
  • 1,297
  • 1
  • 18
  • 29
  • You can't do this. Exposing local files to LSL scripts would be a big security problem (and also not very useful). – Maxpm May 29 '14 at 14:36
  • Suggest some way to do it. – kAmol May 30 '14 at 04:13
  • 1
    There are ways to achieve the end goal you are looking for, but it's not clear exactly what is a "must" for you. It seems odd to edit a file and want to immediately have lsl check that change. It would be simpler(and more sensible) to have you enter the values in second life and act upon those. With more info, I can suggest a solution. – James Korden Aug 06 '14 at 13:32

4 Answers4

2

Essentially you want to use llHTTPRequest within Second Life to read something from a web server.

The most elegant solution would be to create a web interface with PHP and MySQL. A nice script is here: https://github.com/jgpippin/sldb

Even simpler option without any database:

  1. Create a text file called color.txt with just one line like green
  2. Upload text file to your server using FTP, I recommend FileZilla
  3. Create a PHP file (code below)
  4. Create an object in Second Life to read your PHP file
  5. Do something with the result

Thanks to http://lslwiki.net/lslwiki/wakka.php?wakka=ExamplellHTTPRequest for the concept and basis for this code:

PHP File sl.php

<?php
$color = file_get_contents('http://yourdomain.com/color.txt');
echo "Your color selection is " . $color . ".\n";
?>

Script in Object

key requestid; // check if we're getting the result we've asked for
// all scripts in the same object get the same replies

default
{
    touch_start(integer number)
    {
        requestid = llHTTPRequest("http://yourdomain.com/sl.php", 
            [HTTP_METHOD, "POST",
             HTTP_MIMETYPE, "application/x-www-form-urlencoded"],
            "");
    }

    http_response(key request_id, integer status, list metadata, string body)
    {
        if (request_id == requestid)
            llWhisper(0, body);
    }
}

Of course instead of just whispering the output you would want to do something with that value, for example convert a list of common color names to a HEX value or other color format, and then use that to change the color of the object in question. But you get the idea -- it's possible to read something from a text document into LSL.

Also, if you want to use Dropbox instead of FTP to get a file onto the web easier, you just have to get the public link and then add ?dl=1 to the end to force the file to open, rather than to display in the browser as a webpage with extra HTML stuff attached. So for example, you'd use:

 $color = file_get_contents('https://www.dropbox.com/s/i0wpav054k5uept/color.txt?dl=1');

Hope this helps!

  • Yes you are right. I did the same as I couldn't find any other solution, though I was troubled by the bandwidth issues like the values are not getting reflected as and when you update Notepad file. It's taking time to read the data and reflect and as I commented earlier, the values are getting updated too frequently. – kAmol Aug 08 '14 at 08:49
  • I'm not sure what bandwidth issues you mean. Of course there is some latency as you are waiting for Dropbox to sync the changed file, but from my tests this happened rather quickly, within a few seconds. Of course your own internet connection is a big factor, which will determine how quickly Dropbox or any other service can work, as well as how quickly your SL viewer can show the change. – whoaitsaimz Sep 15 '14 at 16:37
0

Since LSL need to be able to run even when you're not online, local web servers and local files cannot be used with LSL.

The only usable alternative is to publish the text file so it can be accessed from the internet. You should be able to use a Public Dropbox folder if you don't want to get a full web hosting.

Lie Ryan
  • 62,238
  • 13
  • 100
  • 144
  • I already tried with it with [OneDrive](https://onedrive.live.com/) folder. But the problem is with the sync and read/write latency. – kAmol May 29 '14 at 12:13
0

You can't use LSL to read a file on your computer - at least, not officially. Theoretically, a third-party Second Life viewer could let you. I don't think any of them actually do, though. You can check for yourself by investigating the viewers listed in the Third-Party Viewer Directory.

As it stands, then, you'll just have to move your data to a Second Life notecard or host it in a way that's accessible over the Internet. Reading data from a notecard is very easy. Hosting your file online is a little more complicated, involving the use of LSL's HTTP functions for retrieval.

Maxpm
  • 24,113
  • 33
  • 111
  • 170
  • The thing is, we can not write Notecard externally (like using Notepad) and I want to read data from local Notepad text file, hence hosting option is not possible. If you are saying its possible with Third-Party Viewer, then I doubt but I'll try it. – kAmol May 30 '14 at 19:00
0

Running a bot will allow you to script avatar actions, like creating a notecard. There's a fair few providers of paid bot hosting services, and with some you may host and adapt your own, but since you are trying to be quick and keep it local I would suggest running one on your own machine. Check the list of services on the wiki, paying special attention to the 'Programming' subheading in the feature table. Some services will be out of date (Ahh the SL Priority Drift!) so contact providers to double check crucial features, like ability to edit notecards in linked objects, or extent of messaging capabilities.

Once you are set up, you may need to do a bit of tweaking to ensure the notecards will be handled properly. Certainly test out the behaviour thouroughly before using this on a large scale, SL imposes limits on all forms of communication. Then, finally, you will have a rare and rich ability to write notecards by script when your bot is online, even when you are not.

ocæon
  • 204
  • 1
  • 12