本质上,您想在 Second Life 中使用 llHTTPRequest 从 Web 服务器读取内容。
最优雅的解决方案是使用 PHP 和 MySQL 创建一个 Web 界面。一个不错的脚本在这里:https ://github.com/jgpippin/sldb
没有任何数据库的更简单的选项:
- 创建一个名为 color.txt 的文本文件,其中只有一行绿色
- 使用 FTP 将文本文件上传到您的服务器,我推荐 FileZilla
- 创建一个 PHP 文件(代码如下)
- 在 Second Life 中创建一个对象来读取你的 PHP 文件
- 对结果做点什么
感谢http://lslwiki.net/lslwiki/wakka.php?wakka=ExamplellHTTPRequest提供此代码的概念和基础:
PHP 文件 sl.php
<?php
$color = file_get_contents('http://yourdomain.com/color.txt');
echo "Your color selection is " . $color . ".\n";
?>
对象中的脚本
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);
}
}
当然,您可能希望使用该值做一些事情,而不是仅仅耳语输出,例如将常用颜色名称列表转换为 HEX 值或其他颜色格式,然后使用它来更改相关对象的颜色。但是你明白了——可以将文本文档中的某些内容读入 LSL。
此外,如果您想使用 Dropbox 而不是 FTP 来更轻松地将文件上传到网络上,您只需获取公共链接,然后在末尾添加?dl=1以强制文件打开,而不是显示在浏览器作为附加了额外 HTML 内容的网页。因此,例如,您将使用:
$color = file_get_contents('https://www.dropbox.com/s/i0wpav054k5uept/color.txt?dl=1');
希望这可以帮助!