Table of Contents

ChangeLog

17 April 2013

  • Switched to use key-value_pairs and removed the list in order to make the ebook consume less memory.

Shortnote

This texture cycler is able to turn pages forwards and backwards depending on the coordinate where the primitive it resides in is touched.

The primitive that the script resides in is placed in the screen itself as can be seen in the illustration above. The screen is divided in half so that llDetectedTouchST reports:

  • y=0 on the right-most side of the screen.
  • y=.5 in the middle of the screen.
  • y=1 on the left-most side of the screen.

Thus any touch on the screen so that y>.5 will be considered a backwards page turn and any touch so that y<.5 will be considered a forwards turn.

Setup

  • Drop the textures into the screen primitive.
  • Open the screen primitive containing the textures and set its description to: page=0.
  • Create a new script in the screen primitive with the contents below.

Code

This script was tested and works on OpenSim version 0.7.4!

forwards_and_backwards_cycler.lsl
///////////////////////////////////////////////////////////////////////////
//  Copyright (C) Wizardry and Steamworks 2013 - License: GNU GPLv3      //
//  Please see: http://www.gnu.org/licenses/gpl.html for legal details,  //
//  rights of fair usage, the disclaimer and warranty conditions.        //
///////////////////////////////////////////////////////////////////////////
 
///////////////////////////////////////////////////////////////////////////
//    Copyright (C) 2013 Wizardry and Steamworks - License: GNU GPLv3    //
///////////////////////////////////////////////////////////////////////////
string wasKeyValueGet(string var, string kvp) {
    list dVars = llParseString2List(kvp, ["&"], []);
    do {
        list data = llParseString2List(llList2String(dVars, 0), ["="], []);
        string k = llList2String(data, 0);
        if(k != var) jump continue;
        return llList2String(data, 1);
@continue;
        dVars = llDeleteSubList(dVars, 0, 0);
    } while(llGetListLength(dVars));
    return "";
}
 
///////////////////////////////////////////////////////////////////////////
//    Copyright (C) 2013 Wizardry and Steamworks - License: GNU GPLv3    //
///////////////////////////////////////////////////////////////////////////
string wasKeyValueSet(string var, string val, string kvp) {
    list dVars = llParseString2List(kvp, ["&"], []);
    if(llGetListLength(dVars) == 0) return var + "=" + val;
    list result = [];
    do {
        list data = llParseString2List(llList2String(dVars, 0), ["="], []);
        string k = llList2String(data, 0);
        if(k == "") jump continue;
        if(k == var && val == "") jump continue;
        if(k == var) {
            result += k + "=" + val;
            val = "";
            jump continue;
        }
        string v = llList2String(data, 1);
        if(v == "") jump continue;
        result += k + "=" + v;
@continue;
        dVars = llDeleteSubList(dVars, 0, 0);
    } while(llGetListLength(dVars));
    if(val != "") result += var + "=" + val;
    return llDumpList2String(result, "&");
}
 
default {
    touch_start(integer num) {
        integer page = (integer)wasKeyValueGet("page", llGetObjectDesc());
        vector p = llDetectedTouchST(0);
        if(p.y > .5) jump back;
        if(page+1 > llGetInventoryNumber(INVENTORY_TEXTURE)-1) return;
        llSetTexture(llGetInventoryName(INVENTORY_TEXTURE, ++page), 0);
        llSetObjectDesc(wasKeyValueSet("page", (string)page, llGetObjectDesc()));
        return;
@back;
        if(page-1 < 0) return;
        llSetTexture(llGetInventoryName(INVENTORY_TEXTURE, --page), 0);
        llSetObjectDesc(wasKeyValueSet("page", (string)page, llGetObjectDesc()));
    }
}

secondlife/texture_book/forwards_and_backwards_cycler.txt ยท Last modified: 2022/11/24 07:46 by 127.0.0.1

Access website using Tor Access website using i2p Wizardry and Steamworks PGP Key


For the contact, copyright, license, warranty and privacy terms for the usage of this website please see the contact, license, privacy, copyright.