Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

dynamic dialog page efficiency

Alicia Sautereau
if (!social) hide;
Join date: 20 Feb 2007
Posts: 3,125
01-08-2008 10:05
As i needed a dynamic dialog page creation with "<<" "exit" ">>" if the string total is larger then 11 (have an exit buttong), i`ve created this hander as there was nothing in the wiki

befor wanting to release it as a code snippet for others to use, i thought to see if it can be improved for efficiency
the memory usage is pritty low after going from list storage to parsing strings, lemme know what you think or where there`s room for optimization or some reordering for easy reading for the final post befor sharing it on the wiki (or where ever)



string dialog_text(string a, integer i)
{
string tmp = "";
if (count_total <= 11)
{
dialog_count = count_total + 1;
}
while (i < dialog_count)
{
integer z = i - 1;
tmp += parse(land_text, z);
i++;
}
return tmp;
}

list dialog_menu(string a, integer i)
{
list tmp = [];
if (count_total <= 11)
{
dialog_count = count_total + 1;
}
while (i < dialog_count)
{
tmp += (string)i;
i++;
}

if (count_total <= 11)
{
tmp += ["exit"];
} else {
tmp += ["<<"]+["exit"]+[">>"];
}
tmp = order_buttons(tmp);
return tmp;
}

string parse(string a, integer b)
{
list a = llParseString2List(a, ["|"],[]);
string cmd = llList2String(a, b);
return cmd;
}

integer i = 1;
integer dialog_page = 1;
integer dialog_count = 10;
integer count;
integer count_total = 0;

string myString; // items seperated by "|", 1|2|3|4|etc
string myText; // items seperated by "|", a|b|c|d|etc

default
{
state_entry()
{
llListen(dChannel, "", "", "";);
}

link_message(integer sender_num, integer num, string str, key id)
{
proc = str;
if (parse(proc,0) == "start";)
{
llDialog(usrNow,dialog_text(myText,i), dialog_menu(dialog_text,i), channel);
}
}

listen(integer channel, string name, key id, string mes)
{
if (mes == "<<";)
{
if (dialog_page == 1)
{
dialog_page = 1 + llCeil(count_total/9);
dialog_count = count_total + 1;
i = 1 + (llCeil(count_total/9) * 9);
} else {
dialog_page = dialog_page - 1;
dialog_count = 1 + (dialog_page * 9);
i = i - 9;
}
llSetTimerEvent(60);
llDialog(usrNow,dialog_text("",i), dialog_menu(land_text,i), channel);
}
else if (mes == ">>";)
{
if (dialog_page <= llCeil(count_total/9))
{
if (dialog_page == llFloor(count_total/9))
{
dialog_page = dialog_page + 1;
dialog_count = count_total + 1;
i = i + 9;
} else {
dialog_page = dialog_page + 1;
dialog_count = dialog_count + 9;
i = i + 9;
}
} else {
dialog_page = 1;
dialog_count = 10;
i = 1;
}
llSetTimerEvent(60);
llDialog(usrNow,dialog_text("",i), dialog_menu(myText,i), channel);
}
else if (mes == "exit";)
{
llSetTimerEvent(1);
}
else
{
integer z = (integer)mes - 1;
if (parse(myList, z) != "";)
{
llSay(0, "myString is: "+ parse(myList, z));
//do stuff here or LinkedMessage to a slave script
llSetTimerEvent(60);
} else {
llSay(0, "No such option.";);
llSetTimerEvent(1);
}
}
}



i make my text and button string by stroring it from multiple LinkedMessages and when getting a "done" message, execute the first dialog in the link_message so it might look abit strange
also must add that the count_total i get from the webserver with a check but that`s easilly done with llStringLength() :)

all i can say that for some reason it works flawlesly with just a handfull of options or +30 (test succeeded with 100 text entries and 100 options using only 11.02kb memory total(+some code) :p ) options, hope not much fixing is requierd :)
_____________________
Seagel Neville
Far East User
Join date: 2 Jan 2005
Posts: 1,476
01-11-2008 00:57
If you consider that the max button's numbers are nine and alwyas add "<<" "exit" ">>" when the page is created, you can save the list's memory, can't you?

llDialog(usrNow,dialog_text(myText,i), ["<<", "exit", ">>"] + dialog_menu(dialog_text,i), channel);
_____________________
:) Seagel Neville :)
Alicia Sautereau
if (!social) hide;
Join date: 20 Feb 2007
Posts: 3,125
01-11-2008 08:45
thought of that aswell at the start but came to the conclusion that if setting a hardcoded max of 9 buttons, you allways get the << exit >> buttons even if there are no next pages
wanted to keep the dialog clean as much as i could so if there are only 11 options (12 with exit), you only get that and no extra buttons

thinking ahead to my next project, this function is nice to have, but when done, rewrite it as a linkedmessage "module" and add the ability to have sub-sub menu`s to make it really usefull and user friendly

as it is, it`s usable and can works great to generate HUGE lists with auto << exit >> to the amount of options, managed to stuff in 143 options with just 2 strings befor running out of memory (this was just a test to see if it works when packed to the limits) :)
_____________________