Getting Ambitious: Talking to Scripted Objects using XML and LINQ

By xorlabs

We’re starting our first major project, and it will comprise activities in our two major areas of effort. We’ll take some of the latest .NET Framework technology, and use it to augment our SL experience. The work is a continuation of some things we were involved in in the Second Nature 3 sim, in which various scripted objects were created as artificial life in an inter-related ecosystem. There, a series of AI creatures fed on each other, and on some AI plants. In our new Ecopod, we are only going to have a single plant type, and it will be fed upon by a single type of bug. We will start with the plant.

The XorLabs Research Ecopod

The XorLabs Research Ecopod

The plants, and eventually the bugs, will be deployed in the Ecopod. To maintain an ecological balance, the parameters of the bugs and the plants must be at a proper set of values, and that will ultimately be determined by trial and error. An offline .NET application will transmit adjusted values as the number of plants and bugs begin to grow and the balance is observed over the course of time.

As parameter values are adjusted, the latest set will be inserted in a SQL Server database instance running on the same computer as the offline application. The offline application will access the database using LINK to SQL. Then, it will create the corresponding XML-RPC command using LINK to XML, and send it to the plants and bugs within the Ecopod. That’s the general overview, now lets look at some specifics.

A Few Words About LINQ

LINQ is short for “Language Integrated Queries”. It is implemented in the versions of C# and Visual Basic which ship with Visual Studio 2008. Several language extensions have been added to make LINQ work. We’ll be using C# for this. Having bought Visual Studio 2005 just last year, there is little inclination to buy VS2008 this soon. No problem though, since Visual Studio 2008 Express has everything we’ll need, and since it is free, you can’t be the price.

Using LINQ, you can just drop SQL like query strings right in the middle of the C# code. In the pages to come, we won’t try to give a full tutorial on LINQ, but there should be enough code shown to get your curiosity and ambition aroused so that you will go out and learn it for yourself. Of course, any code posted is free for you to use or modify as you like.

Using XML-RPC With Linden Scripting Language

The LSL Wikki has some detailed documentation on how to implement XML-RPC in a scripted object. As you will see, the LSL script must first contact the Linden server to get a channel assignment. Once the channel number is returned, it must be transmitted it to the offline application. Once the offline application has the channel number it can construct the XML command and send it via HTTP to the scripted object. The scripted object can reply using HTTP to send a response to the offline object.

Rather than try to get each and every bug connected to an XML-RPC channel, we’ll have a single object that receives the transmissions from the offline application. The scripts in the plants and bugs will listen on a non-zero chat channel to get the parameter values relayed to their respective scripted objects.

We’re going to introduce what some may consider an unnecessary complication to get the channel number to the offline application. We’d like the offline application to automatically get the channel number without having to have the scripted object acquire it and email it. Then we won’t have to get it from email, and enter it in a text box. Rather, we’ll have the scripted object which performs the SL side of XML-RPC acquire the channel in its on_rez() event handler, then use HTTP to send it to an ASP page on ZenovkaTek.com, with the ASP page inserting it into the SQL Server instance there. Then, the first thing the offline application will do when it starts will be to access the ZenovkaTex.com database with HTTP to get the channel number. This way it’s all automatic and requires no additional action to get the communication link enabled. More on this, and the rest of the XML-RPC part in due course.

The Project In Three Phases

The first phase, and the subject of the first page on the project, will consider the various parameters which will be needed, how they are stored in the SQL Server instance on our offline computer, and how LINQ will access them. Phase II will be involved with using LINQ to XML to create the XML-RPC command and insert the data acquired from the database. In the final phase, we’ll show how to send the XML-RPC command to the scripted object in the XorLabs parcel in SL. Look for the first page in about a week.

Tags: , , ,

Leave a Reply