Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Darned dataServer

Othello Witherspoon
Registered User
Join date: 25 Apr 2006
Posts: 6
03-23-2007 22:02
Ok so im trying to make a vend box for a house. I made it eariler today and it was working like a charm then all of a sudden it stopped working. I have been through every ounce of this code and i figure its a problem with the dataServer not reading the file correctly. Just can't figure it out, any help?

CODE



// This is the name of the notecard to read items from
string itemDataNotecard = "House";

// Type of thingy this vendor sells (inventory constant)
integer inventoryType = INVENTORY_OBJECT;

// Keeps track of the currently-displayed item (1-indexed)
integer currentItem = 0;

// These lists are synchronized to simulate a structure for each item's data
list items = [];
list models = [];
list prices = [];
list authors = [];

// Required to read the notecard properly
integer notecardLine;
key currentDataRequest;

// Reads the data from the notecard. Each line in the notecard should be
// formatted as follows:
// Item Name, Model Name, Price, Authors
// string (no commas), string (no commas), integer, pipe-delimited list of keys
// Example:
// Abbotts Float Plane v1.0.1, Abbotts Float Plane Model, 500, key|key
InitializationStep1() {
llSay(0, "Reading item data...");
notecardLine = 0;
currentDataRequest = llGetNotecardLine(itemDataNotecard, notecardLine);
}

// Requests debit permission
InitializationStep2() {
// Request debit permission
llRequestPermissions(llGetOwner(), PERMISSION_DEBIT);
}

// Change currently-displayed item
SetCurrentItem(integer item) {
// determine which item to display
integer itemCount = llGetListLength(items) - 1;
currentItem = item;
if (currentItem == -1) {
currentItem = itemCount;
} else if (currentItem > itemCount) {
currentItem = 0;
}

}
default {
state_entry() {
llSay(0, "Starting up...");

// Read notecard, populate lists
InitializationStep1();
}

run_time_permissions(integer perm) {
if (perm & PERMISSION_DEBIT) {
state vend;
} else {
llSay(0, "You must grant debit permission for me to work properly.");
}
}

dataserver(key query, string data) {
if (query == currentDataRequest) {
currentDataRequest = ""; // Prevent a bug that occurs with dataserver events.
if (data != EOF) {
// Read the current item
list currentList = llCSV2List(data);
string myItemName = llList2String(currentList, 0);
string myModelName = llList2String(currentList, 1);
integer myPrice = llList2Integer(currentList, 2);
string myAuthorsAsString = llList2String(currentList, 3);

items += [myItemName];
models += [myModelName];
prices += [myPrice];
authors += [myAuthorsAsString];

notecardLine++;
// Get the next line
currentDataRequest = llGetNotecardLine(itemDataNotecard, notecardLine);
} else {
// Signal that we are done getting items
InitializationStep2();
}
}
}
}

state vend {
state_entry() {
//llSay(0, "items = " + llDumpList2String(items, ","));
//llSay(0, "models = " + llDumpList2String(models, ","));
//llSay(0, "prices = " + llDumpList2String(prices, ","));
//llSay(0, "authors = " + llDumpList2String(authors, ","));

SetCurrentItem(currentItem);
llSay(0, "House Vendor Online.");
}

// Someone has given me money
money(key agentkey, integer amount) {
string name = llKey2Name(agentkey);
integer currentPrice = llList2Integer(prices, currentItem);
integer sale;
integer i;

if(amount < currentPrice) {
// Not enough money was given. Cancel sale.
llSay(0, name + " you Paid $" + (string)amount + " - thats not enough money for the current item! Refunding $" + (string)amount + "...");
llGiveMoney(agentkey, amount);
sale = FALSE;
}
else if(amount > currentPrice) {
// Too much money was given. Refund the differnce.
integer change = amount - currentPrice;
llSay(0, name + " you Paid $" + (string)amount + " - your change is $" + (string)change + ".");
llGiveMoney(agentkey, change);
sale = TRUE;
} else {
// The proper amount was given.
sale = TRUE;
}

if (sale) {
// Make sure I have the item in inventory before trying to give it.
integer found = FALSE;
//llSay(0, "searching for " + llList2String(items, currentItem));
for (i = 0; i < llGetInventoryNumber(inventoryType); i++) {
if (llGetInventoryName(inventoryType, i) == llList2String(items, currentItem)) {
found = TRUE;
}
}

if (!found) {
// Display error and refund money
llSay(0, "Erm, I am sorry " + name + ", but it seems that I do not have that item to give to you, so I am refunding the purchase price. Please contact my owner about this issue.");
llGiveMoney(agentkey, currentPrice);
} else {
// Complete the sale
llSay(0, "Thank you for your purchase, " + name + "!");
llGiveInventory(agentkey, llList2String(items, currentItem));

llWhisper(0, "Please wait while I perform accounting activities...");

// Distribute money to the object authors
list myAuthors = llParseString2List(llList2String(authors, currentItem), ["|"], []);

if (llGetListLength(myAuthors) > 0) {
integer shareAmount = (integer)llList2Integer(prices, currentItem) / llGetListLength(myAuthors);
// Eliminate my owner from the authors list
for (i = 0; i < llGetListLength(myAuthors); i++) {
llInstantMessage(llList2Key(myAuthors, i), name + " purchased " + llList2String(items, currentItem) + ". Your share is L$" + (string)shareAmount + ".");
if (llList2Key(myAuthors, i) == llGetOwner()) {
myAuthors = llDeleteSubList(myAuthors, i, i);
}
}
// Pay any remaining authors accordingly
if (shareAmount > 0 && llGetListLength(myAuthors) > 0) {
for (i = 0; i < llGetListLength(myAuthors); i++) {
llGiveMoney(llList2Key(myAuthors, i), shareAmount);
}
}
}
llWhisper(0, "Accounting completed. Thanks again, " + name + "!");
}
}
}
}

Sindy Tsure
Will script for shoes
Join date: 18 Sep 2006
Posts: 4,103
03-23-2007 22:23
I confess to being too lazy to go through your script but am curious what you'd get if you took the first 'if' out of your dataserver event. Or, better, if you put an llOwnerSay(data) or something as the first line of the event so you can see exactly where it's choking..
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
03-24-2007 03:12
From: Sindy Tsure
I confess to being too lazy to go through your script but am curious what you'd get if you took the first 'if' out of your dataserver event. Or, better, if you put an llOwnerSay(data) or something as the first line of the event so you can see exactly where it's choking..


The first if is checking that this is the correct dataserver reply.
Add a debug llOwnerSay inside the dataserver event (as Sindy Suggested) to see if anything is getting processed.
Pale Spectre
Registered User
Join date: 2 Sep 2005
Posts: 586
03-24-2007 04:28
One other straw to clutch is the possibility that the Notecard is corrupt. Various posts in the past have arrived at that conclusion. Maybe create a new Notecard with just a couple of lines of data and test to see if that works. If it does you'll need to redo your Notecard.
Othello Witherspoon
Registered User
Join date: 25 Apr 2006
Posts: 6
03-24-2007 09:10
llOwnerSay?? how would i do that
Pale Spectre
Registered User
Join date: 2 Sep 2005
Posts: 586
03-24-2007 09:35
CODE
dataserver(key query, string data) {

llOwnerSay(data); //am I receiving any datasever events?

if (query == currentDataRequest) {
currentDataRequest = ""; // Prevent a bug that occurs with dataserver events.
if (data != EOF) {
// Read the current item
list currentList = llCSV2List(data);
string myItemName = llList2String(currentList, 0);
string myModelName = llList2String(currentList, 1);
integer myPrice = llList2Integer(currentList, 2);
string myAuthorsAsString = llList2String(currentList, 3);

items += [myItemName];
models += [myModelName];
prices += [myPrice];
authors += [myAuthorsAsString];

llOwnerSay((string)notecardLine) + " " + data) // am I processing any dataserver Events?
llOwnerSay("myItemName: " + myItemName);
llOwnerSay("myModelName: " + myModelName);
llOwnerSay("myPrice: " + (string)myPrice);
llOwnerSay("myAuthorsAsString: " + myAuthorsAsString);

notecardLine++;
// Get the next line
currentDataRequest = llGetNotecardLine(itemDataNotecard, notecardLine);
} else {
// Signal that we are done getting items
InitializationStep2();
}
}
}
Sindy Tsure
Will script for shoes
Join date: 18 Sep 2006
Posts: 4,103
03-24-2007 10:07
From: Newgate Ludd
The first if is checking that this is the correct dataserver reply.

Yep but since Othello is reading a single notecard line-by-line and only has one outstanding dataserver request at a time, keeping track of the query key doesn't seem needed.

Or is there a LSL bug lurking there that I haven't run into before? I do see the comment in the code about a bug but I've never run into problems reading notecards..

Maybe..
CODE

dataserver(key query, string data)
{
llOwnerSay ("dataserver got '" + data + "'");

if (query == currentDataRequest)
{
currentDataRequest = ""; // Prevent a bug that occurs with dataserver events.
if (data != EOF)
{
llOwnerSay ("looks good - beginning parsage...");
// Read the current item
list currentList = llCSV2List(data);
string myItemName = llList2String(currentList, 0);
string myModelName = llList2String(currentList, 1);
integer myPrice = llList2Integer(currentList, 2);
string myAuthorsAsString = llList2String(currentList, 3);

items += [myItemName];
models += [myModelName];
prices += [myPrice];
authors += [myAuthorsAsString];

notecardLine++;
// Get the next line
currentDataRequest = llGetNotecardLine(itemDataNotecard, notecardLine);
llOwnerSay ("...data parsed. moving on to line " + (string)notecardLine);
}
else
{
llOwnerSay ("w00t! hit EOF! moving on to step 2...");
// Signal that we are done getting items
InitializationStep2();
}
}
else
{
llOwnerSay ("Ack! query is wrong: " + (string)query + " with data '" + data + "'");
}
}
Othello Witherspoon
Registered User
Join date: 25 Apr 2006
Posts: 6
03-24-2007 12:58
ok so i added the code and this is what it showed....

[12:50] Object: Starting up...
[12:50] Object: Reading item data...
[12:50] Object: dataserver got 'Big Style House, Large Version, 800, Fantasia Moore'
[12:50] Object: looks good - beginning parsage...
[12:50] Object: ...data parsed. moving on to line 1
[12:50] Object: dataserver got '


'
[12:50] Object: w00t! hit EOF! moving on to step 2...


So it looks like the EOF was in fact reached but this message is still coming up.....

Object: Erm, I am sorry Othello Witherspoon, but it seems that I do not have that item to give to you, so I am refunding the purchase price. Please contact my owner about this issue.

Everytime I attempt to pay for the item in question. And I put the item in the box so its certainly there but just not getting from point A to point B
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
03-24-2007 13:56
OK, wild stab in the dark, check for multiple spaces in the object name or some other such subtle mismatch in the notecard description and the actual object name.
Othello Witherspoon
Registered User
Join date: 25 Apr 2006
Posts: 6
03-25-2007 20:45
lmfao is it possible to solve the hardest problem through the easiest means? I think so cause i just did it. the problem was NOT in the script. It was solely in the item. The reason it kept saying the item was NOT there is because the item really was NOT there. I forgot to put both the display and the actual item in the box, which makes me feel really stupid right now argh. Thanks for your help though.
Sindy Tsure
Will script for shoes
Join date: 18 Sep 2006
Posts: 4,103
03-25-2007 21:25
From: Othello Witherspoon
lmfao is it possible to solve the hardest problem through the easiest means?

I bet Occham would say yes. :)

Glad you figured it out!