Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Need help in making this work reliably

Dellybean North
Registered User
Join date: 8 May 2006
Posts: 321
02-01-2009 19:15
K, this is a server script I made. Most of the time it seems to be working just fine. occasionally however, I've happened along and tried it out and it gives me the message that somebody else is ordering right now and to wait, even though there is no one at all in the vicinity. When this happens I end up having to right click and reset the scripts to get it to operate again. Even waiting for the whole normal timeout span doesn't set it ready to serve again.

I've chopped out some tedious boring menu choices bits (those all work WHEN the thing is working).

CODE


string CONFIG_CARD = "drinksprice";
integer PRICE = 5;
integer NotecardLine;
key QueryID;

integer channel; // channel that we are listening on
integer listener; // internal number representing the listener
key agentKey; // persons key who is using menu
string agentName; // person who is using menu
float timeout = 60; // number of seconds before dialogs time out

string menu = ""; // current menu being displayed to user

// menu buttons ...
list mainButtons = ["ManSize", "LadySize"];
list ManSizeButtons = ["IcedTea", "PomegraKiss", "Coffee", "Martini","Margarita","WhiteWine","Rum Fizz","TeqBomber","RedWine","Beer","MangoSling", "CocoChocSm"];
list LadySizeButtons = ["IcedTea", "PomegraKiss", "Coffee", "Martini","Margarita","WhiteWine","Rum Fizz","TeqBomber","RedWine","Beer","MangoSling", "CocoChocSm"];


init()
{

stopListening();
}
stopListening()
{

if(listener != 0)
{
llListenRemove(listener);
listener = 0;
}


menu = "";

// forget current user
agentKey = NULL_KEY;
agentName = "";
channel = 0;


llSetTimerEvent(0);
}
mainMenuHandler(string message)
{
menu = message;

if(message == "ManSize")
llDialog(agentKey, "What'll you have Sir?", ManSizeButtons, channel);
else if(message == "LadySize")
llDialog(agentKey, "What'll you have Ma'am?", LadySizeButtons, channel);
else
{
llInstantMessage(agentKey, "Unknown menu item - " + message);
stopListening();
return;
}

// extend timeout
llSetTimerEvent(timeout);
}
manMenuHandler(string message)
{
bunch of choices and give inventory stuff in here and this works
}

stopListening();
}
ladyMenuHandler(string message)
{
bunch of choices and give inventory stuff in here and this works.
}

stopListening();
}
unknownMenuHandler(string message)
{
llInstantMessage(agentKey, "Unknown menu item - " + message);
stopListening();
}

default
{
on_rez(integer start_param)
{
init();
llResetScript();
}

changed( integer change )
{
if( change & CHANGED_INVENTORY )
llResetScript();
}

state_entry()
{

llOwnerSay("Initializing…");

if (llGetInventoryType(CONFIG_CARD) == INVENTORY_NOTECARD)
{
NotecardLine = 0;
QueryID = llGetNotecardLine( CONFIG_CARD, NotecardLine );
}
else
{
llOwnerSay("Configuration notecard missing, using defaults.");
state run;
}


}


dataserver( key queryid, string data )

{
list temp;
string name;
string value;

if ( queryid == QueryID )
{
if ( data != EOF )
{
if ( llGetSubString(data, 0, 0) != "#" && llStringTrim(data, STRING_TRIM) != "" )

{

temp = llParseString2List(data, ["="], []);

name = llStringTrim(llToLower(llList2String(temp, 0)), STRING_TRIM);

value = llStringTrim(llList2String(temp, 1), STRING_TRIM);



if ( name == "price" )

{

PRICE = (integer)value;

}

}

NotecardLine++;

QueryID = llGetNotecardLine( CONFIG_CARD, NotecardLine );

}

else
{
state run;
}
}

}



state_exit()
{
llOwnerSay("Drinks Price Set");
}

}



state run
{

touch_start(integer total_number)
{
// someone else using this?
if(listener != 0 && llDetectedKey(0) != agentKey)
{
llInstantMessage(llDetectedKey(0), agentName + " is ordering right now, please wait a moment.");
return;
}

// remember who is using this
agentKey = llDetectedKey(0);
agentName = llDetectedName(0);

// if we are not listening already
if(listener == 0)
{
// set a random channel betweed -4000 and -2000
channel = (integer)(llFrand(2000) - 4000);

// start listening only to the agent on our hidden channel
listener = llListen(channel, agentName, agentKey, "");
llInstantMessage(llDetectedKey(0), agentName + " Please pay " + (string)PRICE + "L");
}

}

money(key id, integer amount)
{
if(llKey2Name(agentKey) == agentName)
{
if(amount == PRICE)
{

llSleep(2);
// menu to default
menu = "";

// show them buttons
llDialog(agentKey, "What size drink can I get you?", mainButtons, channel);

// set timeout
llSetTimerEvent(timeout);
}
}

}

listen(integer channel, string name, key id, string message)
{
// handle results based on menu end-user was viewing
if(menu == "") mainMenuHandler(message);
else if(menu == "ManSize") manMenuHandler(message);
else if(menu == "LadySize") ladyMenuHandler(message);
else unknownMenuHandler(message);
}
timer()
{
// let agent know that we are not listening
llInstantMessage(agentKey, "Your menu has timed out!");

stopListening();

}
}

arton Rotaru
Registered User
Join date: 27 Aug 2007
Posts: 43
02-01-2009 23:44
If somebody touch the object, but don't pay it, the timer() event is not triggered at all. So your listener can't switch back to 0.
Dellybean North
Registered User
Join date: 8 May 2006
Posts: 321
02-02-2009 00:41
gah, shoulda seen that.

So if I put the timer event in the touchstart part instead, should fix, thnks will try that.
Kahiro Watanabe
Registered User
Join date: 28 Sep 2007
Posts: 572
02-02-2009 13:05
Also if i'm not wrong you have two equals lists, use one instead to save memory. Event if it is a little, it's a good programming practice to do that.
_____________________
Jocko Domo japanese goods



[Blog]