Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Give all Notes and Object Counter

Katanya Mistral
The Lonely Tigress
Join date: 6 Oct 2005
Posts: 87
04-13-2006 11:43
Could anyone tell me what I need to add to a script that allows itesm to be chosen via menu in order to add a "get all" function and perhaps a counter (i.e. 1-8 of 25) in the actual menu interface? I don't know how giving things in folders works, haven't quite figured it out yet. This is only for notecards at the moment.
Thanks so much for any and all help =)
_____________________
Visit my website: Katanya.net
My SL site: Kitty's SL Adventures
SteveR Whiplash
teh Monkeh
Join date: 24 Sep 2004
Posts: 173
04-13-2006 13:48
I'm not sure what you mean by "menu." Are you talking about the blue dialog boxes, or is this a floaty text menu, or something else?

Need a little more info on how your project is setup.

This will give all notecards in the object to whoever touches it in a folder called Notecards.

CODE

touch_start(integer num_detected){
integer numNotecards = llGetInventoryNumber(INVENTORY_NOTECARD);
if (numNotecards > 0){
list notecards;
integer x;
for (x = 0; x < numNotecards; x++){
notecards += [llGetInventoryName(INVENTORY_NOTECARD, x)];
}
llGiveInventoryList(llDetectedKey(0), "Notecards", notecards);
}
}


[edit] Oopsy, forgot the brackets around llGetInventoryName..
_____________________
Katanya Mistral
The Lonely Tigress
Join date: 6 Oct 2005
Posts: 87
04-13-2006 20:50
Yes Steve, that's what I meant, the blue dialog boxes that appear in the top left of your screen. The script I currently have lists the notecards and allows you to choose them via the buttons in the dialog.
_____________________
Visit my website: Katanya.net
My SL site: Kitty's SL Adventures
SteveR Whiplash
teh Monkeh
Join date: 24 Sep 2004
Posts: 173
04-13-2006 23:01
So... I went a little crazy and just did an entire script. I'll likely be putting it to use myself, so it's not wasted effort. :D

CODE

// Notecard Vendor
// SteveR Whiplash

string dialogtext = "Choose a notecard.";
string folder = "Notecards";

//---NO-TOUCHY-----------------------------------------
key user = NULL_KEY;
list notecards;
integer start;
integer numnotecards;
integer listenchan;
integer listenhandle;
float timeout;

LoadNotecards(){
notecards = [];
numnotecards = llGetInventoryNumber(INVENTORY_NOTECARD);
integer x;
for (x = 0; x < numnotecards; x++){
notecards += [llGetSubString(llGetInventoryName(INVENTORY_NOTECARD, x), 0, 23)];
}
}

Dialog(){
list buttons = ["Back...", "Get All", "More..."] + llList2List(notecards, start, start + 8);
string count = "\n" + (string)(start + 1) + " - ";
if (start + 9 > numnotecards){
count += (string)numnotecards;
} else {
count += (string)(start + 9);
}
count += " of " + (string)numnotecards;
llDialog(user, dialogtext + count, buttons, listenchan);
llSetTimerEvent(30);
timeout = llGetTime();
}

Reset(){
llListenRemove(listenhandle);
llSetTimerEvent(0);
user = NULL_KEY;
}

default
{
state_entry(){
LoadNotecards();
}

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

touch_start(integer num_detected){
key toucher = llDetectedKey(0);
if (toucher == user || user == NULL_KEY){
user = toucher;
llListenRemove(listenhandle);
listenchan = llFloor(llFrand(9999)) - 99999;
llListen(listenchan, "", user, "");
start = 0;
Dialog();
} else {
llInstantMessage(llDetectedKey(0), "This vendor is currently in use. Please wait 30 seconds for previous session to time out.");
}
}

listen(integer channel, string name, key id, string message){
if (message == "Back..."){
if (start != 0) start -= 9;
Dialog();
} else if (message == "More..."){
if (start + 9 < llGetListLength(notecards)) start += 9;
Dialog();
} else if (message == "Get All"){
list giveall;
integer x;
for (x = 0; x < numnotecards; x++){
giveall += [llGetInventoryName(INVENTORY_NOTECARD, x)];
}
llGiveInventoryList(user, folder, giveall);
Reset();
} else {
integer cardnum = llListFindList(notecards, [message]);
llGiveInventory(user, llGetInventoryName(INVENTORY_NOTECARD, cardnum));
Reset();
}
}

timer(){
timeout = llGetTime() - timeout;
if (timeout > 5){ //check for timer going off too early (BUG)
Reset();
}
}
}
_____________________
Katanya Mistral
The Lonely Tigress
Join date: 6 Oct 2005
Posts: 87
04-14-2006 13:12
Steve, do you know how I make the dialog show the names of the notecards, with the scrollbar functionality, instead of having them on the buttons?
_____________________
Visit my website: Katanya.net
My SL site: Kitty's SL Adventures
SteveR Whiplash
teh Monkeh
Join date: 24 Sep 2004
Posts: 173
04-14-2006 16:13
Ahh! Well if you want the buttons to be numbered it would make more sense to start the script over from scratch with that in mind. But here's a fix that should work for you. It will give a list of the full names (well, up to 24 characters) in the dialog. It lists them in left-right/top-down order as you see them on the buttons.

Replace the Dialog() function from the previous script with this one:

CODE

Dialog(){
list buttons = ["Back...", "Get All", "More..."] + llList2List(notecards, start, start + 8);
string count = "\n" + (string)(start + 1) + " - ";
if (start + 9 > numnotecards){
count += (string)numnotecards;
} else {
count += (string)(start + 9);
}
count += " of " + (string)numnotecards;
string cardlist = "\n";
string cardname;
integer x;
for (x = start + 6; x < start + 9; x++){
cardname = llGetInventoryName(INVENTORY_NOTECARD, x);
if (cardname != "") cardlist += "\n" + cardname;
}
for (x = start + 3; x < start + 6; x++){
cardname = llGetInventoryName(INVENTORY_NOTECARD, x);
if (cardname != "") cardlist += "\n" + cardname;
}
for (x = start; x < start + 3; x++){
cardname = llGetInventoryName(INVENTORY_NOTECARD, x);
if (cardname != "") cardlist += "\n" + cardname;
}
llDialog(user, dialogtext + count + cardlist, buttons, listenchan);
llSetTimerEvent(30);
timeout = llGetTime();
}


Sorry I'm not giving specific "tips" here. This is one of those kinds of projects that you just need to plan out how it will work before you even start it. That's mostly because of the dialog function being an odd beast to work with.
_____________________
Katanya Mistral
The Lonely Tigress
Join date: 6 Oct 2005
Posts: 87
04-15-2006 07:00
Right, I understand. My main purpose in posting was to add to a script I already have. A lot of the functions are still weird to me as I don't know a whole lot about programming and such.
_____________________
Visit my website: Katanya.net
My SL site: Kitty's SL Adventures