Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

HELP - problem reading notecard lines

Mat Sinister
Registered User
Join date: 7 Feb 2009
Posts: 14
05-02-2009 06:17
Can't understand why I have to click llDialog window twice to change values.


#################################

string text1;
string text2;
string text3;
key owner;
key creator;
key QueryID;
integer NotecardLine;
string CONFIG_CARD = "Values";
integer listen_id;
integer channel;
key ukey;
list temp;
string name;

init()
{
owner = llGetOwner();
creator = llGetCreator();
channel=llCeil(llFrand(1000000));
listen_id=llListen(channel,"",ukey,"" );
}

menu()
{
llDialog(ukey,"Choose a Value",["Value1","Value2", "Value3"],channel);
}

setVal()
{
llWhisper(0,"Notecardline=" +(string)NotecardLine);
QueryID= llGetNotecardLine(CONFIG_CARD, NotecardLine);
llWhisper(0,(string)owner + " " + (string)creator + " " +text1 +text2 +text3);
menu();
}

default
{
state_entry()
{
init();
}

touch_start (integer total_number)
{
ukey = llDetectedKey(0);
menu();
}

dataserver( key queryid, string data )
{
if (queryid = QueryID)
{
temp = llParseString2List(data, [","], []);
name = llStringTrim(llToLower(llList2String(temp, 0)), STRING_TRIM);
text1= llStringTrim(llToLower(llList2String(temp, 1)), STRING_TRIM);
text2= llStringTrim(llToLower(llList2String(temp, 2)), STRING_TRIM);
text3= llStringTrim(llToLower(llList2String(temp, 3)), STRING_TRIM);
}
}

listen(integer ch, string name, key id, string msg)
{
if (msg=="Value1";)
{
NotecardLine = 0;
setVal();
}
if (msg=="Value2";)
{
NotecardLine = 1;
setVal();
}
if (msg=="Value3";)
{
NotecardLine = 2;
setVal();
}
}
}

#####################################

Notecard sample, rename it "Values":


ahahah,11111111111111111111111,1111111111111111111,111111111111111111111
eheheh,22222222222222222222222222,2222222222222222222222,222222222222222222222222
uhuhuh,33333333333333333333333333,3333333333333333333333,333333333333333333333333
Damet Neumann
Registered User
Join date: 21 Apr 2006
Posts: 140
just from a quick look
05-02-2009 06:35
your not reading the notecard till the first response to the menu you never get to
the setval() till then so it doesnt have the data
Mat Sinister
Registered User
Join date: 7 Feb 2009
Posts: 14
05-02-2009 09:03
Found what was wrong, script don't wait dataserver answers.
Added a timer and now it's ok.

Thanks
Pale Spectre
Registered User
Join date: 2 Sep 2005
Posts: 586
05-02-2009 09:04
dataserver(key queryid, string data) is an Event not a Function, in other words it doesn't happen immediately you execute llGetNotecardLine. It gets queued, just like any other event.

Move the two lines:

llWhisper(0,(string)owner + " " + (string)creator + " " +text1 +text2 +text3);
menu();

...to the end of the dataserver Event Handler.
_____________________
Thex Lecker
Registered User
Join date: 30 Nov 2008
Posts: 2
05-05-2009 07:14
You also have a subtle bug, in that it's listening for ANYONE not just the one who touches. Since you set this in the init():
listen_id=llListen(channel,"",ukey,"" );

And at that point ukey == NULL_KEY. Setting ukey later in the touch() event doesn't update the listener, you'd need to update it at that time, or, better, if(id==ukey) in the listen() event.