Reputation: 1389
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...?
Upvotes: 1
Views: 1338
Reputation: 202
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.
Upvotes: 0
Reputation: 36
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!
Upvotes: 2
Reputation: 25602
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.
Upvotes: 0
Reputation: 64923
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.
Upvotes: 0