Jump to content
JDroo

need some help on this, clear data and read selected notecard?

Recommended Posts

Okay, this script is kinda big and a mess. [wrote by me, so it's pretty much garbo WIP] but it works.

it works.. but i have to reset the script to get it to read the newly selected notecard, and this means it has to rebuild the notecard list, then grab the notecard name i stored in the 2nd child prim of the linkset's description [so it's saved between resets...blah blah] then finally texture using the new data.

I do not want it to work this way. it's slow and bothersome having to wait after each time i select a new texture notecard from the menu.

I've been trying for hours to get it to texture after selecting a notecard, without resetting anything. is there a way to clear the previous dataserver junk collected from the previous card and simply reload a new card?

I want it to be able to reload a new notecard without resting the script.

Please tell me it's possible, and please can someone show me how to do this.

thanx lots in advanced

here is the script:

 

string uuids;
string BLANK = "✭";
integer current_menu;
list NEXT;
integer dialogChannel;
list texture_names;
list texture_uuids;
list scalesx;
list scalesy;
list offsetx;
list offsety;
string current;
integer finished_loading;
integer counter;
integer listenHandle;
integer menu_page;
key rpic;
key lpic;
key fpic;
key bpic;
key tapez;
key printz;
key tfrillz;
key bfrillz;
float srpicx;
float slpicx;
float sfpicx;
float sbpicx;
float stapezx;
float sprintzx;
float stfrillzx;
float sbfrillzx;
float srpicy;
float slpicy;
float sfpicy;
float sbpicy;
float stapezy;
float sprintzy;
float stfrillzy;
float sbfrillzy;
float orpicx;
float olpicx;
float ofpicx;
float obpicx;
float otapezx;
float oprintzx;
float otfrillzx;
float obfrillzx;
float orpicy;
float olpicy;
float ofpicy;
float obpicy;
float otapezy;
float oprintzy;
float otfrillzy;
float obfrillzy;
integer USELAYERS;
integer PICLAYERS;
integer ADDON1;
integer ADDON2;
integer ADDON3;
integer ADDON4;
integer ADDON5;
integer ADDON6;
integer ADDON7;
getLinks() {
  integer total = llGetNumberOfPrims() + 1;
  string name;
  while ((total--) - 1) {
    name = llGetLinkName(total);
    if (name == "USE LAYERS") USELAYERS = total;
    if (name == "PIC LAYERS") PICLAYERS = total;
    if (name == "ADD ON 1") ADDON1 = total;
    if (name == "ADD ON 2") ADDON2 = total;
    if (name == "ADD ON 3") ADDON3 = total;
    if (name == "ADD ON 4") ADDON4 = total;
    if (name == "ADD ON 5") ADDON5 = total;
    if (name == "ADD ON 6") ADDON6 = total;
    if (name == "ADD ON 7") ADDON7 = total;
  }
  name = "";
}
remove_listen_handle() {
  llListenRemove(listenHandle);
}
key line_request_id;
key read_request_id;
integer line_total;
integer line_index;
string read_status;
integer textureCount;
FinishLoading() {
  llListen(dialogChannel, "", "", "");
  Page(0);
  finished_loading = TRUE;
        getLinks();
        llSetLinkPrimitiveParamsFast(PICLAYERS, [PRIM_TEXTURE, 2, rpic, < srpicx, srpicy, 0 > , < orpicx, orpicy, 0 > , 0]); //right cutie
        llSetLinkPrimitiveParamsFast(PICLAYERS, [PRIM_TEXTURE, 3, lpic, < slpicx, slpicy, 0 > , < olpicx, olpicy, 0 > , 0]); //left cutie
        llSetLinkPrimitiveParamsFast(PICLAYERS, [PRIM_TEXTURE, 1, fpic, < sfpicx, sfpicy, 0 > , < ofpicx, ofpicy, 0 > , 0]); //frpnt pic
        llSetLinkPrimitiveParamsFast(PICLAYERS, [PRIM_TEXTURE, 4, bpic, < sbpicx, sbpicy, 0 > , < obpicx, obpicy, 0 > , 0]); //back pic
        llSetLinkPrimitiveParamsFast(LINK_THIS, [PRIM_TEXTURE, 1, printz, < sprintzx, sprintzy, 0 > , < oprintzx, oprintzy, 0 > , 0]); //main print
        llSetLinkPrimitiveParamsFast(LINK_THIS, [PRIM_TEXTURE, 4, tfrillz, < stfrillzx, stfrillzy, 0 > , < otfrillzx, otfrillzy, 0 > , 0]); //top ruffles
        llSetLinkPrimitiveParamsFast(LINK_THIS, [PRIM_TEXTURE, 3, bfrillz, < sbfrillzx, sbfrillzy, 0 > , < obfrillzx, obfrillzy, 0 > , 0]); //bottom ruffles
        llSetLinkPrimitiveParamsFast(LINK_THIS, [PRIM_TEXTURE, 2, tapez, < stapezx, stapezy, 0 > , < otapezx, otapezy, 0 > , 0]); //tapes
          current_menu = 0;
          Menu();
}
GetSongNames() {
  if (llGetInventoryKey(uuids)) line_request_id = llGetNumberOfNotecardLines(uuids);
  else {
    llInstantMessage(llGetOwner(), "Finished loading, a notecard went missing?, choosing random and rebooting.");
    integer randocard = (integer)llFrand(llGetInventoryNumber(INVENTORY_NOTECARD));
    string rando = llGetInventoryName(INVENTORY_NOTECARD,randocard);
    llSetLinkPrimitiveParams(2, [PRIM_DESC, rando]);
    llResetScript();
  }
}
Menu() {
  string text;
  list buttons;
  integer type = 1;
  if (current_menu == 0) {
    text = " ";
    buttons += [BLANK, "[NOTECARD]", BLANK, BLANK, "[EXIT]", BLANK];
  } else if (current_menu == 1) {
    text = "ᴛᴇxᴛᴜʀᴇs\n";
    integer i;
    integer l = llGetListLength(NEXT);
    string name;
    for (i = 0; i < l; i++) {
      name = llList2Key(NEXT, i);
      text += name + "\n";
      buttons += llGetSubString(name, 0, 23);
    }
    buttons += ["[⇐ PREV]", "[BACK]", "[NEXT ⇒]"];
  } else if (current_menu == 4) {
    text = "sᴇʟᴇᴄᴛ ᴛʜᴇ ᴛᴇxᴛᴜʀᴇ NOTECARD ʏᴏᴜ ᴡɪsʜ ᴛᴏ ᴜsᴇ\nɪꜰ ʏᴏᴜ ᴍᴀᴋᴇ ᴀ sᴇʟᴇᴄᴛɪᴏɴ ᴛʜᴇ ᴍᴇɴᴜ ᴡɪʟʟ ᴄʟᴏsᴇ ᴀɴᴅ sᴄʀɪᴘᴛ ᴡɪʟʟ ʀᴇsᴇᴛ.";
    integer count = llGetInventoryNumber(INVENTORY_NOTECARD);
    integer i;
    integer start = menu_page * 9;
    integer end = start + 9;
    for (i = start; i < count && i < end; i++) {
      string num = (string)(i + 1) + " ";
      string name = llGetInventoryName(INVENTORY_NOTECARD, i);
      buttons += name;
    }
    if (menu_page >= 1) {
      buttons += ["[⇐ PREV]"];
    } else {
      buttons += [" "];
    }
    buttons += ["[BACK]"];
    if (menu_page < count / 8) {
      buttons += ["[NEXT ⇒]"];
    } else {
      buttons += [" "];
    }
}
  if (type == 1) {
    buttons = llList2List(buttons, -3, -1) + llList2List(buttons, -6, -4) + llList2List(buttons, -9, -7) + llList2List(buttons, -12, -10);
    llDialog(llGetOwner(), text, buttons, dialogChannel);
}
}
MenuListener(key id, string message) {
  if (llGetOwner() == llGetOwnerKey(id) && message == "menu") {
    Menu();
  } else if (current_menu == 0) {
    if (message == "[NOTECARD]") {
      current_menu = 4;
      Menu();
    } else if (message == "[EXIT]")
    {
      llListenRemove(listenHandle);
      llSetScriptState("[NEZZY TEXTURES]",FALSE);
      llSetScriptState("[NEZZY CORE]",TRUE);
        } 
    else if (message == BLANK) llListenRemove(listenHandle);
  } else if (current_menu == 4) {
    if (message == "[⇐ PREV]") {
      if (menu_page > 0) {
        menu_page--;
      }
      Menu();
    } else if (message == "[BACK]") {
      current_menu = 0;
      Menu();
    } else if (message == "[NEXT ⇒]") {
      integer l = llGetInventoryNumber(INVENTORY_NOTECARD);
      if (menu_page < l) {
        menu_page++;
      }
      Menu();
    } else if (message == " ") {
      Menu();
    } else {
      string NOTECARD = llGetInventoryName(INVENTORY_NOTECARD, (integer) message - 1);
      llSetLinkPrimitiveParams(2, [PRIM_DESC, (string) message]);
      llInstantMessage(llGetOwner(), "Selecting notecard: ''" + (string) message + "'', Rebooting.");
      llResetScript();
    }
  }}
Page(integer p) {
  NEXT = llList2List(texture_names, p * 9, p * 9 + 8);
}
default {
  changed(integer change) {
    if (change & CHANGED_INVENTORY) {
      llInstantMessage(llGetOwner(), "Something has changed... Rebooting.");
      llResetScript();
    }
    if (change & CHANGED_OWNER) {
      llResetScript();
    }
  }
    state_entry() {
      uuids = (string) llGetLinkPrimitiveParams(2, [PRIM_DESC]);
      llRequestPermissions(llGetOwner(), PERMISSION_TRIGGER_ANIMATION);
      finished_loading = FALSE;
      counter = 0;
      GetSongNames();
      dialogChannel = -1 - (integer)("0x" + llGetSubString((string) llGetKey(), -7, -1));
      listenHandle = llListen(dialogChannel, "", llGetOwner(), "");
    }
    dataserver(key requested, string data) {
      if (requested == line_request_id) {
        line_total = (integer) data;
        read_request_id = llGetNotecardLine(uuids, line_index++);
      }
      if (requested != read_request_id) return;
      if ((read_status = data) == EOF) {
        llInstantMessage(llGetOwner(), "Finished Loading.");
        FinishLoading();
        return;
      }
      read_request_id = llGetNotecardLine(uuids, line_index++);
      if (data == "" || llGetSubString(data, 0, 0) == "#") return;
      list sticker_list = llParseString2List(data, ["|"], []);
      texture_uuids += llList2String(sticker_list, 0);
      scalesx += llList2String(sticker_list, 1);
      scalesy += llList2String(sticker_list, 2);
      offsetx += llList2String(sticker_list, 3);
      offsety += llList2String(sticker_list, 4);
      //llOwnerSay((string)data);
      rpic = llList2String(texture_uuids, 0);
      srpicx = llList2Float(scalesx, 0);
      srpicy = llList2Float(scalesy, 0);
      orpicx = llList2Float(offsetx, 0);
      orpicy = llList2Float(offsety, 0);
      lpic = llList2String(texture_uuids, 1);
      slpicx = llList2Float(scalesx, 1);
      slpicy = llList2Float(scalesy, 1);
      olpicx = llList2Float(offsetx, 1);
      olpicy = llList2Float(offsety, 1);
      fpic = llList2String(texture_uuids, 2);
      sfpicx = llList2Float(scalesx, 2);
      sfpicy = llList2Float(scalesy, 2);
      ofpicx = llList2Float(offsetx, 2);
      ofpicy = llList2Float(offsety, 2);
      bpic = llList2String(texture_uuids, 3);
      sbpicx = llList2Float(scalesx, 3);
      sbpicy = llList2Float(scalesy, 3);
      obpicx = llList2Float(offsetx, 3);
      obpicy = llList2Float(offsety, 3);
      printz = llList2String(texture_uuids, 4);
      sprintzx = llList2Float(scalesx, 4);
      sprintzy = llList2Float(scalesy, 4);
      oprintzx = llList2Float(offsetx, 4);
      oprintzy = llList2Float(offsety, 4);
      tfrillz = llList2String(texture_uuids, 5);
      stfrillzx = llList2Float(scalesx, 5);
      stfrillzy = llList2Float(scalesy, 5);
      otfrillzx = llList2Float(offsetx, 5);
      otfrillzy = llList2Float(offsety, 5);
      bfrillz = llList2String(texture_uuids, 6);
      sbfrillzx = llList2Float(scalesx, 6);
      sbfrillzy = llList2Float(scalesy, 6);
      obfrillzx = llList2Float(offsetx, 6);
      obfrillzy = llList2Float(offsety, 6);
      tapez = llList2String(texture_uuids, 7);
      stapezx = llList2Float(scalesx, 7);
      stapezy = llList2Float(scalesy, 7);
      otapezx = llList2Float(offsetx, 7);
      otapezy = llList2Float(offsety, 7);
    }
    touch_start(integer fingers) {
      if (llDetectedKey(0) == llGetOwner()) {
        if (!finished_loading) {
          llPlaySound("bb8bfbcf-64b8-dbe8-73c6-f4d67cd33584", 1);
          llInstantMessage(llGetOwner(), "Still reading notecards, please wait.");
        } else if (llDetectedKey(0) == llGetOwner()) {
          current_menu = 0;
          Menu();
        }
      }
    }
    listen(integer channel, string name, key id, string message) {
      if (channel == dialogChannel) {
        MenuListener(id, message);
      }
    }
  }

 

Share this post


Link to post
Share on other sites

Bit difficult to follow the flow here but .. when you ask to '... to reload a new notecard without resting the script ' I do not see what one has to do with the other. In the call llGetNotecardLine, you pass the name of the notecard and the line you want from that notecard. There is nothing to keep you from changing that each time you call, with no reset needed.

 

To be honest I cannot even see how you ever get into the dataserver event to begin with ... the only llGetNotecardLine calls I see are in said event ...

Share this post


Link to post
Share on other sites

I'm a bit unclear, too, about exactly what's going on here, but as far as I can make out, the script seems to assume multiple notecards, each one containing the details llSetLinkPrimitiveParamsFast needs for whatever the user's choice is, which means the script has to re-read a notecard time a selection is made.

If I'm correct in this -- and I may well not be -- then I would either combine all the notecards into one, containing a strided list with all the choices and their parameters, or, if that's not possible, then read each notecard one, and add the details to a single strided list held in the script's memory.

Either way,  when someone uses the dialogue menu to make a choice, then have the script find the choice in the list and read from it the appropriate parameters  for that choice.

You should need to read the notecard only once, when it's added/edited.   That's what's causing the delays, I think -- re-reading the cards unnecessarily.

  • Like 1

Share this post


Link to post
Share on other sites

@ellestones  that is not the issue. I have no problem with the 0.1 delay, my issue is the delay of having to reset the script and then re read the card before being able to so anything.

I want to be able to change the notecard on the fly, dump previous collected data from the previous card and load in the data of a newly selected card. Is there no way to clear stored data in the memory of the script on the fly?

  • Thanks 1

Share this post


Link to post
Share on other sites
1 hour ago, JDroo said:

@ellestones  that is not the issue. I have no problem with the 0.1 delay, my issue is the delay of having to reset the script and then re read the card before being able to so anything.

I want to be able to change the notecard on the fly, dump previous collected data from the previous card and load in the data of a newly selected card. Is there no way to clear stored data in the memory of the script on the fly?

When the script reads in a new notecard, it simply overwrites the data from the previous card -- no need to waste time first clearing out old data.

If I'm reading this correctly, these notecards must have 8 lines (0 through 7, plus any "#"-flagged comments), each line with a texture UUID, x and y scales, and x and y offsets delimited by "|"s. The problem I'm seeing is that for each line the script assigns a bunch of values for every line, including all the lines it read before and all the ones it has yet to read, so all those (forty) assignments will take place eight times. Assignments are cheap, even with llList2Mumble operations to extract values (some of which may not be stored yet) but all this can't help with the reset delay.

Also, the script is storing the same information in two sets of global variables: first, a set of five lists for those texture UUIDs, scales and offsets, and second forty singleton values into which it has parsed those arrays (over and over again). It's all fitting in script memory, but it's... unusual.

Finally, as others have notec, the logic is atypical, but I think I understand the idea: store the user's most recent selection somewhere it will persist through a reset... and make that reset recovery process the whole way the script applies the user's selection by resetting every time a selection is made. That approach might be kinda difficult to follow, but it's not wrong.

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites
On 11/27/2018 at 7:11 AM, Love Zhaoying said:

Perhaps they meant “resetting” the script.

Yeah sorry, this forum wont let me edit a post after posting it... so the typo must stay as is, sorry bout that. I did in fact mean resetting. XD

  • Like 2

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...