Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

scripting - plea for help!

psimagus Hax
Registered User
Join date: 3 Jul 2007
Posts: 73
05-11-2008 10:03
I'm quite new to LSL (though I've done a bit of VB and javascript programming before,) and I'm trying to make a sort of answering machine/comments box which allows people to record messages that are added to a list, and then play them back individually (it also stores the posters' names in a parallel list).

It hovertexts the details fine, and has buttons for "first", "last" (those both work fine,) "previous" and "next" to playback entries in the message queue, but I've hit what seems an intractable problem with "previous" and "next". They will loop back to the other end of the queue as intended (eg: when there are 6 messages in the list and the current message is 1, 'previous' goes to 6, and when the current message is 6, 'next' goes to 1,) but they're not working within the range of the messages - "next" from message 1 is 1 again, previous from 6 is 6 :(

Could any more experienced scripter (and that's pretty much everyone!) point me where the problem is? Because I've been just going in circles with it for hours (it's probably one tiny thing I've misinterpreted from the Wiki tutorial or scripting reference.) I'd be eternally grateful!

I apologise in advance for what is doubtless rather inelegant and clunky newbie coding generally :)



integer position;
integer totalnumber;
string avname;
list messageList = [" "]; // list containing messages, each definable by 'position'
list avList = [" "]; // which should match the 'position' of each name in this list
// since they're incremented in the same code block
default
{
state_entry()
{
llListen( 3, "", avname, "" );
llListen( 9, "", NULL_KEY, "" );
integer totalnumber = (llGetListLength(messageList) - 1);
llSetText((string)totalnumber + " messages recorded", <1.0,1.0,1.0>, 0.5);
}

// messages submitted on channel 3
// button prims communicate on channel 9

listen( integer channel, string name, key id, string message )
{
if (channel == 9) {
string messageName = llList2String(avList, position);


if ((string)message == "first";) { // this button works fine
integer totalnumber = (llGetListLength(messageList) - 1);
integer position = 1;
llSetText("No. " + (string)position + " of " + (string)totalnumber, <1.0,1.0,1.0>, 0.5);
string specMessage = llList2String(messageList, position);
llSay (0, specMessage + " - (" + messageName + ";)";);
}


else if ((string)message == "previous";) {
integer totalnumber = (llGetListLength(messageList) - 1);
if (position = 1) position = totalnumber; //loop to last message
else position = position - 1; //xxx broken

string specMessage = llList2String(messageList, position);
llSetText("No. " + (string)position + " of " + (string)totalnumber, <1.0,1.0,1.0>, 0.5);
llSay (0, specMessage + " - (" + messageName + ";)";);
}


else if ((string)message == "next";) {
integer totalnumber = (llGetListLength(messageList) - 1);
if (position = totalnumber) position = 1; //loop to first message
else position = position + 1; // xxx broken

string specMessage = llList2String(messageList, position);
llSetText("No. " + (string)position + " of " + (string)totalnumber, <1.0,1.0,1.0>, 0.5);
llSay (0, specMessage + " - (" + messageName + ";)";);
}



else if ((string)message == "last";) { // this button works fine
string messageName = llList2String(avList, position);
integer totalnumber = (llGetListLength(messageList) - 1);
position = totalnumber;
llSetText("No. " + (string)position + " of " + (string)totalnumber, <1.0,1.0,1.0>, 0.5);
string specMessage = llList2String(messageList, position);
llSay (0, specMessage + " - (" + messageName + ";)";);
}
}



else if (channel == 3) { // this seems to work fine
string messageName = llKey2Name(id);
avList = avList + messageName;
llSay( 0, "Thankyou, " + (string)messageName + ", your message has been saved." );
messageList = messageList + [message];
integer totalnumber = (llGetListLength(messageList) - 1);
position = totalnumber;
llSetText("No. " + (string)position + " of " + (string)totalnumber, <1.0,1.0,1.0>, 0.5);
}
}


touch_start(integer total_number)
{
// string specMessage = llList2String(messageList, position);
// llSay (0, (string)messageList);
// llSay (0, (string)specMessage);

}
}
Renee Roundfield
Registered User
Join date: 10 Mar 2006
Posts: 278
05-11-2008 10:09
I think it's that you have = in your if statements rather than ==.
Xhawkx Holden
Registered User
Join date: 1 Nov 2006
Posts: 86
05-11-2008 10:14
Renee is correct...

if (position = 1) position

should be

if (position == 1) position


if (position = totalnumber) position = 1; //loop to first message

should be

if (position == totalnumber) position = 1; //loop to first message
psimagus Hax
Registered User
Join date: 3 Jul 2007
Posts: 73
05-11-2008 11:23
From: Xhawkx Holden
Renee is correct...

if (position = 1) position

should be

if (position == 1) position


if (position = totalnumber) position = 1; //loop to first message

should be

if (position == totalnumber) position = 1; //loop to first message


aah, I thought I'd tried that (I've been turning in circles, fine-tuning bits like that for some time,) but I'll give it a go.


edit: Or at least, I'll give it a go as soon as SL stops borking whenever I try to open a script (endless "loading..."+"Unable to load script - please try again" ATM) :(

And now the whole SL login has gone down like a Vegas hooker at the sight of a fat wallet. Again!
Jeez - I *SO* don't want to turn this thread into another "LL are ****s" one, but the disparity between the few percent of "down time" quoted in the metrics, and the huge majority of "browned-out" (and utterly unusable, but still paid for through the nose,) time I experience (it seems especially when I'm trying to work on scripts,) is really getting my goat. I seem to spend DAYS doing what ought to have taken minutes!


--
Wittgenstein once said "imagine this butterfly, just as it is - only ugly."
I say, imagine this company, just as it is - only competent."
psimagus Hax
Registered User
Join date: 3 Jul 2007
Posts: 73
05-11-2008 12:40
SL's back up, and THANK YOU! It works! I knew it would be something really small - it's just there are just always a lot more really small things, to check and that can go wrong, than big ones in any given volume of code :)