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...?
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:
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!