Just had a quick question about detecting a name with a script. It's super easy to do, you only need one line:
touch_start(integer total_number)
{
llOwnerSay(llDetectedName(0));
}
In this example I put it in a touch event, but it could also go in a collision event. You can also set things to be run by the owner of the object only by using the following snippet. Anything between the brackets will be owner only:
if(llDetectedKey(0) == llGetOwner()){
}
skip to main |
skip to sidebar
Pages
LSL help: any question is fair game!
Showing posts with label llGetOwner. Show all posts
Showing posts with label llGetOwner. Show all posts
Saturday, November 27, 2010
Wednesday, May 26, 2010
Dave's Giant Database Insertion Tutorial
So, I've had a request to explain inserting data into an external database from SL. This is a pretty lengthy subject but to shorten it up for this post I'm going to assume a few things, such as:
That being said, let's get started. The first thing you will need is to set up your database and know what you are going to store. For this example let's say you want to insert the name of an avatar into a database whenever the object is touched, and keep a running tab of how many times they have touched it.
Assume you have a database called "SL" with a table called "stats". Stats has two columns, "name" and "number". Name will be the name of the avatar (for this example it would need to be set as unique). Number will represent the number of times the prim was clicked.
Now what we are going to do is set up our PHP script. What will happen is that every time the prim is clicked, it will send a request to this PHP script, which will then update the database. Here is an example of what the PHP script should look like for this example.
<?php
$db = mysql_connect("localhost", "db_username", "your_password") or die ("<html><script language='JavaScript'>alert('Unable to connect to database! Please try again later.')</script></html>");
mysql_select_db("SL",$db);
$name = $_GET['name']; //$_GET takes variables that are passed from the url (see the LSL example)
$usertable = "stats";
$update = "INSERT INTO $usertable SET name = '$name', number = 1 ON DUPLICATE KEY UPDATE number = number + 1";
$result = mysql_query($update);
?>
And now for the LSL script that will send the request to the PHP page:
- You have a web server and a place that this database/web script can go.
- You have a database and don't need help setting one up
- You have at least very basic knowledge of PHP and writing MySQL requests.
That being said, let's get started. The first thing you will need is to set up your database and know what you are going to store. For this example let's say you want to insert the name of an avatar into a database whenever the object is touched, and keep a running tab of how many times they have touched it.
Assume you have a database called "SL" with a table called "stats". Stats has two columns, "name" and "number". Name will be the name of the avatar (for this example it would need to be set as unique). Number will represent the number of times the prim was clicked.
Now what we are going to do is set up our PHP script. What will happen is that every time the prim is clicked, it will send a request to this PHP script, which will then update the database. Here is an example of what the PHP script should look like for this example.
<?php
$db = mysql_connect("localhost", "db_username", "your_password") or die ("<html><script language='JavaScript'>alert('Unable to connect to database! Please try again later.')</script></html>");
mysql_select_db("SL",$db);
$name = $_GET['name']; //$_GET takes variables that are passed from the url (see the LSL example)
$usertable = "stats";
$update = "INSERT INTO $usertable SET name = '$name', number = 1 ON DUPLICATE KEY UPDATE number = number + 1";
$result = mysql_query($update);
?>
And now for the LSL script that will send the request to the PHP page:
string owner_name;key owner_name_query;default
{state_entry()
{
}
touch_start(integer total_number)
{
owner_name_query = llRequestAgentData(llGetOwner(), DATA_NAME);
}
dataserver(key queryid, string data){
if (owner_name_query == queryid){owner_name = data;llHTTPRequest("http://www.yoursite.com/yourphppage.php?name=" + owner_name, [], "");
}
}}
Let's take a look at the URL in the llHTTPRequest function. http://www.yoursite.com/yourphppage.php?name=" + owner_name. Remember the $_GET['name'] part of the PHP script? Well this is where that variable is taking data from. ?name= denotes a variable that can be passed to PHP using a URL. If you want to pass more variables, you can string them along with ampersands like this: ?name=Joe_Shmo&id=123456&status=living
Well I hope that is enough to get you started loading things into databases. Next time we can talk about how to get data back out of the database.
Well I hope that is enough to get you started loading things into databases. Next time we can talk about how to get data back out of the database.
Labels:
dataserver,
llGetOwner,
llHTTPRequest,
llRequestAgentData,
PHP
Instructions
If you have a question you would like to see answered here, feel free to ask it in the comment section of any post, or email it to:
nucularsecrets@gmail.com
Any question is fair game, so don't be shy!
nucularsecrets@gmail.com
Any question is fair game, so don't be shy!
Featured
- OpenSim (1)
- Outline (1)
- Sculpties in Blender (1)
Followers
Contributors
Friends
Index
- PHP (1)
- changed (2)
- click and drag (1)
- dataserver (2)
- link_message (1)
- llAllowInventoryDrop (1)
- llAvatarOnSitTarget (1)
- llDetectedKey (2)
- llDetectedName (1)
- llDetectedTouchPos (1)
- llDetectedTouchUV (1)
- llGetOwner (2)
- llGetScriptName (1)
- llHTTPRequest (1)
- llListen (1)
- llParticleSystem (1)
- llRegionSay (1)
- llRemoveInventory (1)
- llRequestAgentData (2)
- llResetScript (1)
- llSay (3)
- llSetLinkPrimitiveParamsfast (2)
- llSetObjectName (1)
- llSetPos (1)
- llSetTimerEvent (1)
- llSitTarget (1)
- particles (1)
- timer (1)
- touch (1)
Blog Archive
-
►
2010
(18)
- ► Nov 21 - Nov 28 (1)
- ► Sep 19 - Sep 26 (1)
- ► Aug 15 - Aug 22 (1)
- ► Aug 8 - Aug 15 (1)
- ► Aug 1 - Aug 8 (1)
- ► Jul 25 - Aug 1 (1)
- ► Jul 4 - Jul 11 (1)
- ► Jun 13 - Jun 20 (1)
- ► May 23 - May 30 (3)
- ► May 16 - May 23 (5)
- ► May 2 - May 9 (2)
Copyright 2010 Nucular Secrets . Powered by Blogger
Blogger Templates created by Deluxe Templates Wordpress by thebookish