Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

multiple dataserver queries

Tarak Voss
Meanderer
Join date: 14 Oct 2006
Posts: 330
12-12-2008 01:16
I have about three incidents where I need to make different dataserver queries - I can put the same script in two identical prims yet one will work properly and the other doesn't

For example - in on-rez I need to read a texture name from a notecard - In one instance the script work well and I get it - yet in the other, the string's default value remains.

I am using query keys to identify each - I think it is something to do with the time it takes to answer a dataerver query.

I note in Wiki that it says that queries are not necessarily answered in the position they are placed in the script (my interpretation)

It is fairly - ney! drastically important that I get the query answered before moving on to the next command.

See if this helps:

//===Set Variables================================
//================================================
//......

integer noteline;
// line number on the notecard

key noteQuery;
// identify Dataserver request for notecard line

string textureStore = "rubbish";
//the texture to be preloaded

string noteSheet = "configuration";
// name of notecard with sheet textures

//================================================
//=== noteRead function ==========================
//=== does not work in on_rez ====================
//================================================
//Used to lift texture names from the notecardSheet notecard

noteRead()
{
noteQuery = llGetNotecardLine(noteSheet, noteline);
//Get the contents of a notecard line
}

//......
//......


//================================================
//================================================
//=== States =====================================
//================================================
//================================================
default
{
//================================================
//=== on_rez =====================================
//================================================

on_rez(integer start_param)
{
llSetTexture("Working Cover", ALL_SIDES);
//set a standard texture to the prim (this may vary, different textures same name)


//=====================preload the first content texture ===================tbd=========

noteline = 0;

//noteRead();
//like to do this because need to do the same thing in
//another state, but doesn't work here

noteQuery = llGetNotecardLine(noteSheet, noteline);
// Get the contents of notecard first line

llSetTexture(textureStore, 5);
//preload the texture into the hollow prim face (5)

llWhisper(0,"Texture stored preloading is " + textureStore);
//Test Line - the results are correct here for one of the prims
//but not the other
}

//================================================
//=== touch_start ================================
//================================================

touch_start(integer touch_num)
{
//.......................
}

dataserver(key queryid, string data)//Get the result of the request
{
if (queryid == noteQuery)
// Is the result of the query the a line of the notecard?
{
if (data == EOF)//Is it the end of the Notecard?
{
//Yes it is ..........
}
else
{
// No it is not ......
textureStore = data;
llWhisper(0, "textureStore = " + textureStore);
//This line correctly in both prims
}
}
else
{
if (data == "0";)
{
//......other queries occur here - all work OK
{
}
// ........

}
Pale Spectre
Registered User
Join date: 2 Sep 2005
Posts: 586
12-12-2008 05:08
From: Tarak Voss
I think it is something to do with the time it takes to answer a dataerver query.
Not so much the time as the inherent logic.

The dataserver Event is just that, an event. It is not a procedural function. It does not return a result immediately following the call of llGetNotecardLine. These types of request get sent to the dataserver and your script immediately moves on. At some later (unkown) time they then become dataserver Events in your script. Therefore your script's logic must depend on the dataserver Event and not the llGetNotecardLine request.

Bare Bones:

CODE

key noteQuery;

default
{
on_rez(integer start_param)
{
noteQuery = llGetNotecardLine("configuration", 0);
// You cannot depend on anything coming from the dataserver here
}

dataserver(key queryid, string data)
{
if (queryid == noteQuery)
{
// you have to wait until here
llSetTexture(data, 5);
llWhisper(0,"Texture stored preloading is " + data);
}
}
}
Tarak Voss
Meanderer
Join date: 14 Oct 2006
Posts: 330
12-12-2008 15:33
Thankyou!