The following system shows the ability to call a function remotely that is running in a different prim and be able to return the results from it. The remote calling function can be called whilst executing code.
Think of this as a Server - Client system, in which the Client is asking for things from the Server.
You can get the package (full permissions) from XSL at:
Setting up the system
-------------------------
The scripts are ready to go, and contains demo functions to get you started.
It is RECOMMENDED that you change the Web UUID into the Server and Client scripts.
- Rez the Server prim on the ground.
- The Server prim will take a few seconds to set itself up.
- Either rez the Client prim on the ground, or attach the client prim to your HUD.
- Touch the Client prim.
- You will get a whole load of messages.
- Go to another sim, and click on the Client prim again.
Changing the Web UUID
----------------------------
- Go to the Grid URL Persister website -
- Click on the "Random UUID" link.
- Copy the new UUID.
- In SL, open the Server and Client scripts.
- There is a global variable at the top called "g_strWebUUID".
- Paste the UUID value you got from the website.
- Save the scripts, and you will be ready to go.
How does it work?
---------------------
When the Server prim is rezzed, it registers a HTTP-In URL on the Grid Persister website by using the Web UUID specified in the script.
When the Client prim is touched, it calls the Remote Function which sends a Link Message to the Web script. The calling script suspends itself, ie: Not Running. The web script processes the link message, and sends a message to the Server HTTP-In URL. If the web script encounters that the HTTP-In URL is missing or is invalid, it sends a message to the Grid URL Persister website for the latest HTTP-In URL. Once it has got it, it resends the data to the Server prim again.
The Server prim processes the message that is sent from the client, and calls the required function. The Server prim responds with the answer from the function.
The Client prim picks on the result from the Server prim. It then sets the Calling script back to running again. The calling script runs a loop to check the Object Description field of the prim. The web script then goes into a loop and sends any data via the Object Description. The calling script processes the data from the Object Description, and sets a message that it is ready again. The web script checks for any messages, and sends any additional data. If all the data is complete, the Web script sets a "finished" message. Once the Calling script picks up that message it returns the result.
What can it be used for?
----------------------------
- Creating a library of LSL functions to aid programming.
This may help people write scripts more quickly if there is a library system in place.
- Item Giver system from a central location.
Example: A Notecard giver system, in which you could have dozens of dispensers which can call the server to send the notecard to the user.
- Ability to process data in another sim.
- An interactive gaming system in which a HUD can communicate with the Server to find out about other players.
Problems
-----------
Execution of the Remote Function will take longer than normal code execution.
If the sim where the Server is kept is laggy, results will take time, or may even time out.
Licensing
-----------
The code is released to the public domain. You are free to use and adapt it for own needs.
If you are going to use it for a commercial application, send me an IM of its intended use as I would be interested to hear how it would help.
Feedback
-----------
If you have any comments, suggestions, etc. either IM me, or reply to this post.
Thanks.