Scripting Tutorial-07

From Osgrid Wiki
Jump to: navigation, search

Scripting Lesson #7 - Held August 25th, 2018 at Sandbox Plaza by Fu Barr

/*
    Data - some examples
 
    (c)2018 Fu Barr @OSgrid
*/
 
// Data types: integer, float, key, string, vector (rotation)
integer DEBUG = TRUE;
 
float   seconds = 5.0;
key     uuid;
 
string  name;
vector  colour = <1, 1, 1>;   // <r, g, b>
 
// Data structure: list
list    config;
 
default {
 
    on_rez(integer r){ 
 
        llResetScript(); // Health and Safety regulations demand this.
    }
 
    state_entry() {
 
        llOwnerSay("running: " + llGetScriptName());
 
        // 0. now that we're running, get some relevant data
        uuid = llGetOwner();
        name = llGetDisplayName(uuid);
 
        //state data_dump;
    }
}
 
state data_dump {
 
    state_entry() {
 
        if(DEBUG) {
 
            string msg1  = "integer: "  + (string) DEBUG;
                   msg1 += ", float: "  + (string) seconds;
                   msg1 += ", uuid: "   + uuid;
                   msg1 += ", name: "   + name;
                   msg1 += ", colour: " + (string) colour;
 
            string msg2 = "integer: "  + (string) DEBUG
                        + ", float: "  + (string) seconds
                        + ", uuid: "   + uuid
                        + ", name: "   + name
                        + ", colour: " + (string) colour;
 
            llOwnerSay("msg1: " + msg1);
            llOwnerSay("msg2: " + msg2);
        }
 
        //state list_dump;
    }
}
 
state list_dump {
 
    state_entry() {
 
        // 0. Copy the data values from above into the empty list and show them
        config = [DEBUG, seconds, uuid, name, colour];  
 
        string dump = llDumpList2String(config, ", ");
 
        llOwnerSay("list dump: " + dump);
 
        //state list_operations;
    }
}
 
state list_operations {
 
    state_entry() {
 
        // 0. setup loop variables and loop through list
        integer i = 0;
        integer list_end = llGetListLength(config);
 
        while (i < list_end) {
 
            llOwnerSay("list at index(" + (string) i + ") " + llList2String(config, i));
 
            i++;
        }
 
        // 1. copy original data into new list and add more data to end of new list
        list config2 = config;
 
        config2 += "another string";
        config2 += 3.14;
 
        i = 0; 
        list_end = llGetListLength(config2);
 
        while (i < list_end) {
 
            llOwnerSay("list at index(" + (string) i + ") " + llList2String(config2, i));
 
            i++;
        }
 
        // 2. retrieve item at index(2) and replace with new data
        key item = llList2Key(config2, 2);
 
        config2 = llListReplaceList(config2, [llGetKey(), llGetTexture(0)], 2, 2);
 
        i = 0; 
        list_end = llGetListLength(config2);
 
        while (i < list_end) {
 
            llOwnerSay("list at index(" + (string) i + ") " + llList2String(config2, i));
 
            i++;
        }
 
        // 3. re-insert old item 2 at position 4
        config2 = llListInsertList(config2, item, 4);
 
        i = 0; 
        list_end = llGetListLength(config2);
 
        while (i < list_end) {
 
            llOwnerSay("list at index(" + (string) i + ") " + llList2String(config2, i));
 
            i++;
        }
 
        //state map;
    }
}
 
state map {
 
    state_entry() {
 
        /* 
            A map is a classic datastructure where data values are 'mapped' on to named keys. 
 
            Values can be anything, keys need to be unique. 
 
            Typically, a map looks like this:
 
            key1 = valueX
            key2 = valueY
            key3 = ValueZ
            ...
        */
 
        // 0. Add a 2nd list of setting names to setup the keys for the existing config data list,
        //    then loop the two lists to show the mapping.
        list settings = ["DEBUG", "seconds", "uuid", "name", "colour"];
 
        integer i = 0; 
        integer list_end = llGetListLength(settings);
 
        while (i < list_end) {
 
            llOwnerSay("map key:value pair " + llList2String(settings, i) + ":" + llList2String(config, i));
 
            i++;
        }
 
        // 1. Find index of a particular setting and then print its current value
        string setting = "colour";
 
        i = llListFindList(settings, [setting]);
 
        llOwnerSay("map lookup result: " + setting + ":" + llList2String(config, i));
 
        // 2. Now for something different: setting up a single strided list to use as the map.
        list strided_list = [];
 
        i = 0;
 
        while(i < list_end) {
 
            strided_list += llList2String(settings, i);
            strided_list += llList2List(config, i, i);
 
            i++;
        }
 
        llOwnerSay("map strided list: " + llDumpList2String(strided_list, ", "));
 
        // 3. pick a key:value pair from the new strided list-based map
        llOwnerSay("map strided list lookup result: " + setting + ":" + 
                    llList2String(strided_list, llListFindList(strided_list, [setting]) + 1)
                  );
    }
}
[11:31]  Fu Barr: hey ari :)
[11:31]  Arielle Popstar: Hi  Fu  Hi Albertr
[11:32]  Arielle Popstar: brb  putting  coffee  on
[11:33]  Fu Barr gave you fus_scripting_2018.
[11:33]  Fu Barr: me go get something to drink too
[11:33]  Fu Barr: brb
[11:34]  Fu Barr: back
[11:35]  Fu Barr: welcome jeff :)
[11:35]  Arielle Popstar: weba
[11:35]  Fu Barr: :)
[11:35]  Jeff Hall: hey Fu:)
[11:35]  Fu Barr: we'll give it a few more minutes and we'll get going
[11:36]  Fu Barr: hey there paela :)
[11:36]  Fu Barr: welcome :)
[11:37]  Lucy Rosadisharon: hello
[11:37]  Lucy Rosadisharon [it→en]: hello
[11:37]  Fu Barr: hey lucy - welcome :)
[11:37]  Lucy Rosadisharon: ty for tp
[11:37]  Lucy Rosadisharon [it→en]: ty for tp
[11:37]  Fu Barr: hey total :)
[11:37]  Total Sorbet: hi!
[11:37]  Fu Barr: love the handstand sit anim!
[11:37]  Total Sorbet: lol i didnt know i did that
[11:38]  Fu Barr: heheh - v cool!
[11:38]  Fu Barr: show off!
[11:38]  Fu Barr: :)
[11:38]  Total Sorbet: :p
[11:38]  Arielle Popstar: thx  Jefff :)
[11:38]  Fu Barr: welcome verna :)
[11:39]  Fu Barr: right well i guess we should get started.
[11:39]  Fu Barr: welcome koni
[11:39]  Koni Lanzius: thank you, professor :)
[11:39]  Fu Barr: so this week i've slightly changed my presentation - ii was going to do the fun collision portal with blinking lights and included batteries...
[11:40]  Fu Barr: but I realize that I really need to talk about data first. so the portal thingy will be done next week :)
[11:40]  Fu Barr: so - without further ado... please take a copy of this 'tube' and rez a copy near you
[11:40]  Fu Barr: open the script inside and we'll get started.
[11:40]  Mirror Amorasi is Offline
[11:41]  Data tube: running: Fu's data examples v0.1
[11:41]  Jeff Hall: no copy FU
[11:41]  Arielle Popstar: Buy
[11:41]  Fu Barr: opps stoppid me - let me fix
[11:41]  Fu Barr: perms seem ok to me...
[11:41]  Data tube: running: Fu's data examples v0.1
[11:41]  Jeff Hall: nope
[11:41]  Fu Barr: els eme drop script on your head and just drop into a prim
[11:42]  Koni Lanzius: welcome Snoots
[11:42]  Snoots Dwagon: Need voice?
[11:42]  Snoots Dwagon: Or is ext?
[11:42]  Snoots Dwagon: text
[11:42]  Koni Lanzius: take a copy of Fu's tube please
[11:42]  Koni Lanzius: and rez it
[11:42]  paela argus: txt
[11:42]  Fu Barr: text - with lots of typonese for extra crunch!
[11:42]  Snoots Dwagon: I gotta TUBE!  :d
[11:42]  Verna Avril: no buy in the menu
[11:42]  Fu Barr: okay - who _hasnt_ got a cpy of the script so far?
[11:43]  Snoots Dwagon: mE
[11:43]  Fu Barr: is _in_ the tube :)
[11:43]  Snoots Dwagon: Oh okay
[11:43]  Snoots Dwagon: Got it. :D
[11:43]  Fu Barr: *chuckle*
[11:43]  Verna Avril: < me
[11:43]  paela argus: clic right take a copy verna
[11:43]  Fu Barr: stick that in a simple prim verna :)
[11:43]  Object: Script running
[11:43]  Fu Barr: okay so this week we're going to talk about 'data
[11:44]  Verna Avril: no copy on menu
[11:44]  Wizard Atazoth: Greetings, Snoots
[11:44]  Wizard Atazoth: Greetings, verna
[11:44]  Fu Barr: i realised it's all well and good speaking about all the life-cycle and the states and the events etc.
[11:44]  Snoots Dwagon: Hi da Wiz!
[11:44]  Fu Barr: all important
[11:44]  Wizard Atazoth: ^_^
[11:44]  Fu Barr: but you need to have a good handle on actual data too.
[11:44]  Verna Avril: Hey Wiz and all   ty for the tp
[11:44]  BrokeDoll Key: Winding...
[11:44]  BrokeDoll Key: Thank you for winding me.
[11:44]  Fu Barr: LSL/OSSL provides you with a large amount of ways to hang yourself, or cut your fingers - as you prefer - with regards to data.
[11:45]  Fu Barr: time we had a looksey at some of it.
[11:45]  Verna Avril: i will make a tube
[11:45]  Fu Barr: please look at the top of the script.. lines 7 to 16
[11:46]  Fu Barr: the first bit should be familiar to all - these are examples of the common data types you see in just aout every script out there
[11:46]  Fu Barr: I've left one data type out of our discussion - the rotation
[11:46]  Fu Barr: it's far too complicated for this set of classes.
[11:47]  Fu Barr: it has to do with doing 3D math and rotating stuff in 3D.
[11:47]  Fu Barr: but if you're not doing any of that stuff... well you don't need it. and if you are... chances are you don't need this introductory class...
[11:47]  Fu Barr: in line 16
[11:47]  Fu Barr: we see the use of 'list'
[11:48]  Fu Barr: list is also a built-in thing that LSL/OSSLp provides... but it's not a 'primitive' data type... it's a basic data structure
[11:48]  Fu Barr: the difference between type and structure is that types for the most part hold ONE single value of a certain type.
[11:49]  Fu Barr: and structures can hold more than one unit of data
[11:49]  Fu Barr: of course they can also be empty
[11:49]  Fu Barr: so far so good?
[11:49]  Fu Barr: it seems so
[11:49]  Fu Barr: remember - interrupt me when you have something to ask or if you're bored.
[11:50]  Fu Barr: now, look at lines 30 - 31
[11:50]  Fu Barr: in the default state there, I fill the two variables with data
[11:50]  Fu Barr: the other variables are filled with data earlier up top
[11:51]  Fu Barr: but these two.. until the script actually runs... I can't fill them with sensible data. or rather I can, but I've chosen not to
[11:51]  Fu Barr: by filling them in the default state_entry event handler... I can use some 'live' data. I don't need to 'hard code' it into the script.
[11:52]  Fu Barr: you guys didn't have to fill in a notecard or modify the script with your names...
[11:52]  Fu Barr: the script figures it out itself.
[11:52]  Fu Barr: but that can only happen once it's up and running.
[11:52]  Fu Barr: so that's why it's done in the start of the default state.
[11:52]  Fu Barr: now...
[11:52]  Fu Barr: line 33
[11:53]  Fu Barr: you see there that I've commented out the command to jump to the next state
[11:53]  Fu Barr: please remove the // and save the script - it will run to the next state and you'll see stuff on your chat
[11:53]  Fu Barr: if all went well
//Removing '//' slashes Line 33 Results:
 
Object: running: New Script
Object: msg1: integer: 1, float: 5.000000, uuid: ae1968e2-2bf0-4e33-a487-ab54f6ab39b7, name: albertlr Landar, colour: <1.000000, 1.000000, 1.000000>
Object: msg2: integer: 1, float: 5.000000, uuid: ae1968e2-2bf0-4e33-a487-ab54f6ab39b7, name: albertlr Landar, colour: <1.000000, 1.000000, 1.000000>
[11:54]  Fu Barr: the script now moves to the 'data_dump' state
[11:54]  Fu Barr: and you should have seen the 5 variables and their data displayed
[11:54]  Fu Barr: and in two messages
[11:54]  Snoots Dwagon: did yes
[11:54]  Fu Barr: I've added the two messages here - to show you that you can skin a cat in various ways
[11:55]  Fu Barr: look carefully at the code in the new state...
[11:55]  Fu Barr: msg1 is created by adding strings to the variable...
[11:55]  Fu Barr: msg2 is created by adding all the strings in ONE go, but I've used line breaks to make it easier to read.
[11:56]  Fu Barr: it doesn't matter technically.
[11:56]  Fu Barr: but you will discover as you develop your own style... that you prefer one way over the other
[11:56]  Fu Barr: it's also a good way to show that scripts can do the same thing... or try and solve the same problem but they can look really differnt
[11:57]  Fu Barr: this is one example of coding style.. we'll see another example later on
[11:57]  Fu Barr: now - it should be pretty obvious what the script does so far.
[11:57]  Fu Barr: any questions?
[11:57]  paela argus: meow
[11:57]  Fu Barr: please note...
[11:57]  Arielle Popstar: its  not  obvious  to  me
[11:57]  Arielle Popstar: whats  it  do?
[11:58]  Fu Barr: okay - ari - where does it hurt?
[11:58]  Arielle Popstar: lol
[11:58]  Verna Avril: < got it so far
[11:58]  Fu Barr: well the script so far has declared a few variables... filled them with some data and shown you the data
[11:58]  Koni Lanzius: ty sweetie
[11:58]  Fu Barr: nothing else.
[11:58]  Fu Barr: :)
[11:59]  Arielle Popstar: ok
[11:59]  Fu Barr: :)
[11:59]  Arielle Popstar: its  not  going  to  rock  my  world  yet?
[11:59]  Fu Barr: the note I was going to ads.. was...
[11:59]  Fu Barr: nope
[11:59]  Arielle Popstar: ok
[11:59]  Fu Barr: this is bout 'innards' this is about code plumbing
[11:59]  Fu Barr: not the sexy bits
[11:59]  Fu Barr: but it's very important to get straight
[11:59]  Fu Barr: next week when we pull it all together
[12:00]  Fu Barr: then it'll be sexy. but this stuff has to be shown on its own else you get confused with all the other pyrotechnics going on
[12:00]  Fu Barr: one thing to note.. is the LACK of QUOTES round the variable names
[12:01]  Fu Barr: if you add quotes, single or double... then the script engine see them as strings
[12:01]  Fu Barr: not as variable names
[12:01]  Fu Barr: also the (string) bits on lines 43 44 47 49 50 and 53
[12:02]  Fu Barr: those are needed to force the variable to cough up 'strings' and not integers or floats...
[12:02]  Fu Barr: the variable keeps the data and the type inside of it...but you can only add strings to strings... not numbers... so you need for 'coerce' or 'cast' the non-string stuff into strings.
[12:03]  Fu Barr: it's very easy if you don't think about it too much - lol
[12:03]  Fu Barr: you can only add strings to strings
[12:03]  Fu Barr: so if the variable contains a non-string well you have the cast it to string by adding (string) in front of it.
[12:03]  Fu Barr: it's just one of those things in LSL
[12:04]  Fu Barr: in other languages you don't have this issue
[12:04]  BOB-omb Key!: Winding da bomb...........
[12:04]  Fu Barr: but in LSL you do. All you can do is be aware of it,
[12:04]  BOB-omb Key!: Thank you for winding me... and for taking full responsibility for the things I blow up!
[12:04]  Fu Barr: okay - time to move to the next state...
[12:04]  Fu Barr: remove the // from the state statement on line 59 and save
[12:05]  Fu Barr: you should see more stuff fly past now
[12:05]  Data tube: running: Fu's data examples v0.1
//Removing '//' slashes Line 59 Results:
 
Object: running: New Script
Object: msg1: integer: 1, float: 5.000000, uuid: ae1968e2-2bf0-4e33-a487-ab54f6ab39b7, name: albertlr Landar, colour: <1.000000, 1.000000, 1.000000>
Object: msg2: integer: 1, float: 5.000000, uuid: ae1968e2-2bf0-4e33-a487-ab54f6ab39b7, name: albertlr Landar, colour: <1.000000, 1.000000, 1.000000>
Object: list dump: 1, 5.000000, ae1968e2-2bf0-4e33-a487-ab54f6ab39b7, albertlr Landar, <1.000000, 1.000000, 1.000000>
[12:05]  Fu Barr: list_dump is a very short state. not a lot of code... but it does some important stuff.
[12:06]  Fu Barr: what it does is it takes the contents of all the variables and sticks in a a list. it's like taking zip locks worth stuff inside and then putting it in a bag.
[12:06]  Fu Barr: but there' one MAJOR difference with Real Life
[12:07]  Fu Barr: the list COPIES the content in the variable into itself
[12:07]  Fu Barr: the data in the variable stays there
[12:07]  Fu Barr: and a copy is inserted into the list
[12:07]  Fu Barr: this is very important to understand
[12:08]  Fu Barr: in computer science it's called copy-by-value
[12:08]  Fu Barr: so in the end there are TWO copies of the data in memory
[12:08]  Fu Barr: one in the variable one in the list
[12:08]  Fu Barr: if you change the variable.... it does not affect the copy in the list
[12:09]  Fu Barr: if you change the copy in the list... it does not affect the copying the variable
[12:09]  Fu Barr: the are separate.
[12:09]  Fu Barr: have I repeated this enough times? *chuckle*
[12:09]  Verna Avril: kk
[12:09]  Fu Barr: so that's what the line 68 does.
[12:10]  Fu Barr: you use square brackets to say, the stuff in here has to be copied into the list
[12:10]  Fu Barr: [ data, data, data, ]
[12:10]  Fu Barr: and the list will keep the ORDER of the items
[12:10]  Fu Barr: order in the list is important
[12:11]  Fu Barr: because the only way to get something back out of the list is by knowing the item number
[12:11]  Fu Barr: as we shall see later, you can ask the script engine to give you item 4 in list MyList
[12:11]  Fu Barr: or item 5 or 17 or what have you
[12:12]  Fu Barr: it's like getting your coat back after a theatre show
[12:12]  Fu Barr: no number no coat
[12:13]  Fu Barr: the stuff on lines 70 and 72 - that's just blabla - it just runs though the list and dumps the data as strings into a variable and that variable gets dumped to your screen
[12:13]  Fu Barr: it's just to let you guys show that stuff actually happened in line 68
[12:13]  Fu Barr: now there's something you should notice...
[12:14]  Fu Barr: a real difference between the output of msg1 and msg2 and the list dump...
[12:14]  Fu Barr: who can see it?
[12:14]  Fu Barr: look back in your chat history - if i haven't confused you all or put you to sleep
[12:15]  Fu Barr: there's something extra added to each item in the msg1 abnd msg2 output
[12:15]  Fu Barr: okay - I'll give the answer...
[12:15]  Fu Barr: msg1 and msg2 somehow add the NAME of the variable
[12:15]  Fu Barr: to the output
[12:16]  Fu Barr: llDUmpList2String... it doesn't
[12:16]  Fu Barr: it just adds comma's and that's it
[12:16]  Fu Barr: the list has NO IDEA what the name is of the data inside of it
[12:16]  Fu Barr: it just contains the data
[12:16]  Fu Barr: I'm sorry to keep on banging on about this.
[12:17]  Fu Barr: it's a thankless task to bore you like this - but somebody's got to do it :)
[12:17]  Fu Barr: taking one for the team I am here.
[12:17]  albertlr Landar: well we appreciate the walk through
[12:17]  Fu Barr: right. on we go
[12:18]  Fu Barr: remove the // from line 74 and save - you'll see a LOT of stuff go past - take a minute to look at it.
[12:18]  Data tube: running: Fu's data examples v0.1
//Removing '//' slashes Line 74 Results:
 
Object: running: New Script
Object: msg1: integer: 1, float: 5.000000, uuid: ae1968e2-2bf0-4e33-a487-ab54f6ab39b7, name: albertlr Landar, colour: <1.000000, 1.000000, 1.000000>
Object: msg2: integer: 1, float: 5.000000, uuid: ae1968e2-2bf0-4e33-a487-ab54f6ab39b7, name: albertlr Landar, colour: <1.000000, 1.000000, 1.000000>
Object: list dump: 1, 5.000000, ae1968e2-2bf0-4e33-a487-ab54f6ab39b7, albertlr Landar, <1.000000, 1.000000, 1.000000>
Object: list at index(0) 1
Object: list at index(1) 5.000000
Object: list at index(2) ae1968e2-2bf0-4e33-a487-ab54f6ab39b7
Object: list at index(3) albertlr Landar
Object: list at index(4) <1.000000, 1.000000, 1.000000>
Object: list at index(0) 1
Object: list at index(1) 5.000000
Object: list at index(2) ae1968e2-2bf0-4e33-a487-ab54f6ab39b7
Object: list at index(3) albertlr Landar
Object: list at index(4) <1.000000, 1.000000, 1.000000>
Object: list at index(5) another string
Object: list at index(6) 3.140000
Object: list at index(0) 1
Object: list at index(1) 5.000000
Object: list at index(2) 2197d689-a021-4ed4-bc9b-01418a81d70c
Object: list at index(3) 89556747-24cb-43ed-920b-47caed15465f
Object: list at index(4) albertlr Landar
Object: list at index(5) <1.000000, 1.000000, 1.000000>
Object: list at index(6) another string
Object: list at index(7) 3.140000
Object: list at index(0) 1
Object: list at index(1) 5.000000
Object: list at index(2) 2197d689-a021-4ed4-bc9b-01418a81d70c
Object: list at index(3) 89556747-24cb-43ed-920b-47caed15465f
Object: list at index(4) ae1968e2-2bf0-4e33-a487-ab54f6ab39b7
Object: list at index(5) albertlr Landar
Object: list at index(6) <1.000000, 1.000000, 1.000000>
Object: list at index(7) another string
Object: list at index(8) 3.140000
[12:18]  Fu Barr: this state shows some of the basic things you can do with the data in a list
[12:18]  Arielle Popstar: where  do i  see  this  stuff  go  past
[12:18]  Verna Avril: on the screen? nothing has moved
[12:19]  Fu Barr: in your 'chat'
[12:19]  Verna Avril: nothing in chat
[12:19]  Arielle Popstar: just  said  script  saved
[12:19]  Verna Avril: yes
[12:19]  Fu Barr: you need to remove the // on line 74 and the ones before that too... one 59 and 33
[12:20]  Fu Barr: anybody else having the same issue?
[12:20]  Arielle Popstar: yees,  did  that
[12:20]  Verna Avril: yes did that
[12:20]  Fu Barr: hmm, strange
[12:20]  Fu Barr: have others seen the list stuff fly past
[12:20]  Fu Barr: just checking
[12:20]  Fu Barr: nobody?
[12:20]  Arielle Popstar: they asleep  :)
[12:20]  Fu Barr: sigh.
[12:21]  Fu Barr: lemme 2x check
[12:21]  Verna Avril: i opened this script from the inventory when it was given to me  // should  have put it in a prim? then open?
[12:21]  Fu Barr: yeah - you need to put it in a prim...
[12:21]  Arielle Popstar: oh
[12:21]  Fu Barr: I just ran it and it seems to work fine.
[12:22]  Total Sorbet: yes works
[12:22]  Verna Avril: the tube? or another  box?
[12:22]  Fu Barr: box tube - anything makes no difference
[12:22]  Object: Script running
[12:22]  Data tube: running: Fu's data examples v0.1
[12:23]  Fu Barr: remove the default script and put in mine :)
[12:23]  Arielle Popstar: ok  now  i  see
[12:23]  Fu Barr: phew...
[12:23]  Data tube: running: Fu's data examples v0.1
[12:23]  Fu Barr: much relieved
[12:23]  Fu Barr: :)
[12:23]  Arielle Popstar: was  thinking  this  was  all  invisible
[12:23]  Total Sorbet: yay
[12:23]  Total Sorbet: :D
[12:23]  Fu Barr: has a drink of water
[12:23]  Verna Avril: yes it worked
[12:23]  Fu Barr: okay - so now that we're all on the same-ish page...
[12:24]  Fu Barr: you can see all that stuff running past on your chat screen
[12:24]  Fu Barr: have a look at is... it should look 'similar' but it's the output of several list related functions...
[12:24]  Fu Barr: let have a looksey in the code and then you can trace the output later in your own time
[12:25]  Fu Barr: so...
[12:25]  Verna Avril: yes it read my name from the owner of the prim
[12:25]  Fu Barr: on lines 82-92 - the state now figures out how long the list is.. and then starts walking through each 'index' each position or data item in the list
[12:25]  Fu Barr: it's a computer
[12:26]  Fu Barr: so it's very good at doing stupid things
[12:26]  Fu Barr: so walking past each item in a long or short list - that's something it's very good at
[12:26]  Fu Barr: so we only have 5 items in the list at the moment
[12:26]  Fu Barr: and what the while koop does is visit every one of then IN ORDER
[12:27]  Fu Barr: each time it visits an item... it increases the counter by 1
[12:27]  Fu Barr: that counter is held by variable 'i'
[12:27]  Fu Barr: and each time it visits a data item... it tells you what the data item is
[12:28]  Fu Barr: that's the llOwnerSays part
[12:28]  Fu Barr: that's in section 0
[12:28]  Fu Barr: in section 1, we do something fun with the data
[12:28]  Fu Barr: we copy all the original data in the list to a NEW list
[12:28]  Fu Barr: why?
[12:29]  Arielle Popstar: new  info/
[12:29]  Arielle Popstar: ?
[12:29]  Fu Barr: because we're going to manipulate the list add stuff, remove stuff... and in the next state we want the original 5 data items back
[12:29]  Fu Barr: the simplest way of making sure you get your old data back unchanged... is to do all the changes on a copy.
[12:30]  Verna Avril: kk
[12:30]  Fu Barr: so that's what we do... we copy the data.
[12:30]  Fu Barr: so: config2 = config
[12:30]  Fu Barr: and then in lines 96 and 97 we add stuff to the new list... now called config2
[12:30]  Fu Barr: keep in mind we now have THREE copies of most of this data
[12:30]  Fu Barr: in the original variables
[12:31]  Fu Barr: in the original list config
[12:31]  Fu Barr: and now in the list config2
[12:31]  Fu Barr: but by line 97, only config2 has the extra data items
[12:32]  Fu Barr: lines 99 to 107 are boilerplate... boring... they just dump the contents of config2 to the screen
[12:32]  Fu Barr: lets look at 110
[12:32]  Fu Barr: this is interesting
[12:32]  Fu Barr: remember how i said the only way to get to a data item is through its index or 'number'
[12:32]  Fu Barr: well, this is a prime example
[12:33]  Fu Barr: llList2Key will take a list and an index and return the data in that position as a 'key' data type
[12:33]  Fu Barr: there's llList2Integer and llList2String and llList2Float.. etc. etc.
[12:33]  Fu Barr: you get the idea.
[12:34]  Fu Barr: now in 112
[12:34]  Fu Barr: i do something 'dangerous'
[12:34]  Fu Barr: i REPLACE part of the list with something else
[12:34]  Fu Barr: gone. forever
[12:35]  Fu Barr: so if i wanted the data back... i need to make sure... i had a copy made first
[12:35]  Fu Barr: which is what i did in line 110
[12:35]  Fu Barr: look carefully at line 122
[12:35]  Fu Barr: it say...
[12:35]  Fu Barr: [llGetKey(), llGetTexture(0)]
[12:35]  Fu Barr: see those square brackets...
[12:36]  Fu Barr: remember what we said about square brackets and lists...
[12:36]  Fu Barr: so what I'm doing here..is I'm replacing data item 2 in my list with a list of two other items...
[12:36]  Fu Barr: that's what the function is saying
[12:37]  Fu Barr: replace in config2, from position 2 to 2 the data with [llGetKey(), llGetTexture(0)]
[12:37]  Fu Barr: so item 2 gets removed and two items get added
[12:37]  Fu Barr: so the list gets longer
[12:37]  Fu Barr: and the other data items get NEW NUMBERS
[12:38]  Fu Barr: in your own time... look through the log in chat and you'll see it happen
[12:38]  Fu Barr: now on to line 124
[12:38]  Total Sorbet: um line 124 is empty for me
[12:39]  Fu Barr: the data that I rescued from index 2 before i did the replacing... I now put back into the list I'm at:
[12:39]  Fu Barr:  3. re-insert old item 2 at position 4
[12:39]  Fu Barr: and the code is:
[12:39]  Fu Barr: config2 = llListInsertList(config2, item, 4);
[12:39]  Total Sorbet: 120
[12:39]  Total Sorbet: got it
[12:39]  Total Sorbet: :)
[12:40]  Fu Barr: so just for those who are starting to feel the ice crack beneath their feet
[12:40]  Fu Barr: I'll go slow in explaining config2 = llListInsertList(config2, item, 4);
[12:41]  Fu Barr: what i want to do is insert the data I saved back into the list. the data I save is in a variable i created called 'item'
[12:41]  Fu Barr: the llListInsertList function... needs to know three things to do its job
[12:41]  Fu Barr: it needs to know which list to insert into.
[12:41]  Fu Barr: it needs to know what to insert
[12:42]  Fu Barr: and it needs to know at which position in the list to insert
[12:42]  Fu Barr: that exactly what this line does:
[12:42]  Fu Barr: config2 = llListInsertList(config2, item, 4);
[12:42]  Fu Barr: config2 should now become whatever the result is of the llListInsertList() function
[12:43]  Fu Barr: I can't explain it clearer than that - i;m sorry :(
[12:43]  Total Sorbet: mmn llListInsertList() is like pushing your way into the bus queue...
[12:43]  Fu Barr: now yes
[12:43]  Fu Barr: exactly
[12:43]  Total Sorbet: those towards end of list get pushed further away from start of list and make room for your new item(s)
[12:44]  Fu Barr: exactly
[12:44]  Fu Barr: and if you come with a friend and both push in line... the people move back 2 positions
[12:44]  Fu Barr: etc.
[12:45]  Fu Barr: anyhow - i hope if you run the script a few times and you compare the output in chat with the code... By the Power of Greyskull - you will hopefully understand!
[12:45]  Fu Barr: now we come to the part where the more advanced scripters might find something interesting too...
[12:46]  Fu Barr: the list data structure is the only 'built-in' one the LSL gives you
[12:46]  Fu Barr: but there are many very useful data structures out there.. and they can be used to sort and store data relevant to all sorts of things you are trying to solve
[12:47]  Fu Barr: I'm going to introduce one such structure
[12:47]  Fu Barr: it's called a 'map'
[12:47]  Fu Barr: and it's super useful all over the place.
[12:47]  Fu Barr: what a map does is it fixes the issue of a list that you can only pick data from it by its NUMBER
[12:48]  Fu Barr: with a map you can pick data from a list by a NAME
[12:48]  Fu Barr: which for most humans is the better way to do it
[12:48]  Fu Barr: the idea is you have a 2nd list that's the same length as the first list...
[12:48]  Fu Barr: and in the second list.. you keep the names of the data in the first list
[12:49]  Fu Barr: as long as the index - the positions - of the name in list 2 and the data in list 1 stay synchronized... you're good to go
[12:49]  Fu Barr: lets' look at the code...
[12:49]  Fu Barr: uncomment 137 (//state map)
[12:49]  Fu Barr: save and look at the chat results
//Removing "//" slashes Line 137 Results:
 
Object: running: New Script
Object: msg1: integer: 1, float: 5.000000, uuid: ae1968e2-2bf0-4e33-a487-ab54f6ab39b7, name: albertlr Landar, colour: <1.000000, 1.000000, 1.000000>
Object: msg2: integer: 1, float: 5.000000, uuid: ae1968e2-2bf0-4e33-a487-ab54f6ab39b7, name: albertlr Landar, colour: <1.000000, 1.000000, 1.000000>
Object: list dump: 1, 5.000000, ae1968e2-2bf0-4e33-a487-ab54f6ab39b7, albertlr Landar, <1.000000, 1.000000, 1.000000>
Object: list at index(0) 1
Object: list at index(1) 5.000000
Object: list at index(2) ae1968e2-2bf0-4e33-a487-ab54f6ab39b7
Object: list at index(3) albertlr Landar
Object: list at index(4) <1.000000, 1.000000, 1.000000>
Object: list at index(0) 1
Object: list at index(1) 5.000000
Object: list at index(2) ae1968e2-2bf0-4e33-a487-ab54f6ab39b7
Object: list at index(3) albertlr Landar
Object: list at index(4) <1.000000, 1.000000, 1.000000>
Object: list at index(5) another string
Object: list at index(6) 3.140000
Object: list at index(0) 1
Object: list at index(1) 5.000000
Object: list at index(2) 2197d689-a021-4ed4-bc9b-01418a81d70c
Object: list at index(3) 89556747-24cb-43ed-920b-47caed15465f
Object: list at index(4) albertlr Landar
Object: list at index(5) <1.000000, 1.000000, 1.000000>
Object: list at index(6) another string
Object: list at index(7) 3.140000
Object: list at index(0) 1
Object: list at index(1) 5.000000
Object: list at index(2) 2197d689-a021-4ed4-bc9b-01418a81d70c
Object: list at index(3) 89556747-24cb-43ed-920b-47caed15465f
Object: list at index(4) ae1968e2-2bf0-4e33-a487-ab54f6ab39b7
Object: list at index(5) albertlr Landar
Object: list at index(6) <1.000000, 1.000000, 1.000000>
Object: list at index(7) another string
Object: list at index(8) 3.140000
Object: map key:value pair DEBUG:1
Object: map key:value pair seconds:5.000000
Object: map key:value pair uuid:ae1968e2-2bf0-4e33-a487-ab54f6ab39b7
Object: map key:value pair name:albertlr Landar
Object: map key:value pair colour:<1.000000, 1.000000, 1.000000>
Object: map lookup result: colour:<1.000000, 1.000000, 1.000000>
Object: map strided list: DEBUG, 1, seconds, 5.000000, uuid, ae1968e2-2bf0-4e33-a487-ab54f6ab39b7, name, albertlr Landar, colour, <1.000000, 1.000000, 1.000000>
Object: map strided list lookup result: colour:<1.000000, 1.000000, 1.000000>
[12:50]  Total Sorbet: line 132 for me
[12:50]  Data tube: running: Fu's data examples v0.1
[12:50]  Fu Barr: it should tell you exactly what's going on.. but let's look in the code and wrap up the lesson :)
[12:50]  Fu Barr: line 160... it says: list settings = ["DEBUG", "seconds", "uuid", "name", "colour"];
[12:50]  Fu Barr: notice the QUOTES
[12:51]  Fu Barr: these are strings, not variables
[12:51]  Fu Barr: but they are the right order for the data in the 'config' list we filled above
[12:52]  Fu Barr: now in line 173 i set: string setting = "colour";
[12:52]  Fu Barr: I'm looking for the setting called colour
[12:52]  Fu Barr: i search for the index of that item in the settings list... line 175
[12:52]  Fu Barr: i stick it in variable i
[12:53]  Fu Barr: then i use that number to find the value in config - line 177
[12:53]  Fu Barr: we'll see next week (if i haven't frightened you all away) how we use this stuff all the time - but in an easier 'black box' way.
[12:54]  Verna Avril: ty
[12:54]  Fu Barr: so to recap - to find a data item in a list by its name... we use a second list to hold only names
[12:54]  Fu Barr: the lists are kept in sync so if i find name at position 3 i know the data will be at position 3 in the other list
[12:55]  Fu Barr: dassit. simple really :)
[12:55]  Fu Barr: the final part lines 179 - 198
[12:55]  Fu Barr: is a way to do this using only ONE list.
[12:55]  Fu Barr: it's a bit like weaving the two lists together
[12:56]  Fu Barr: it's called a 'strided list' and I leave it as an exercise to those who are interested to figure out. feel free to IM me for questions
[12:56]  Fu Barr: dassit.
[12:56]  Fu Barr: please fight a bit with the code
[12:56]  albertlr Landar: Now you can use notecards to store data, and then retrieve it also is that not so Fu?
[12:57]  Fu Barr: read it a few times... it might be a bit much to take in in one go - but it's really important to any scripting you might want to undertake
[12:57]  Total Sorbet: ty fu will do
[12:57]  Fu Barr: yes that's true - but you still need lists to manipulate data and do so many things in scripting.
[12:57]  paela argus is Online
[12:57]  Fu Barr: you simple cannot do any serious scripting without lists
[12:58]  Fu Barr: so that's why I decided to spend a whole lesson talking about them
[12:58]  Total Sorbet: yup they kinda handy :p
[12:59]  albertlr Landar: Thanks for the explanations on how its handled
[12:59]  Fu Barr: I hope it made sense and wasn't more confusing than explanatory
[12:59]  Fu Barr: i'll go round and wake people up now i guess
[12:59]  Total Sorbet: lols!
[12:59]  Fu Barr: dont forget to delete your tubes
[12:59]  albertlr Landar: well we will have the chat and script posted over in the wiki, for everyone to go over it again.
[13:00]  Verna Avril: i picked up my tube and it was still saving the script is that ok if it stops the run in local when picked up too soon?
[13:00]  Fu Barr: all good - nothing will break :)
[13:00]  Verna Avril: ty
[13:00]  Fu Barr: thanks for coming!
[13:00]  Verna Avril: ty
[13:00]  Total Sorbet: ty for the lesson
[13:01]  Fu Barr: lol - ty total.... you just being nice we know :)
[13:01]  Arielle Popstar: ok  thx  Fu
[13:01]  Fu Barr: yvw ari - hope it made stuff clearer...
[13:02]  Arielle Popstar: i  will  have  to  reread  a  couple  times  but  enough  clues  i  think  i will  get  it
[13:03]  Total Sorbet: k gotta scoot...thanks again fu
[13:04]  Fu Barr: ciao!
[13:04]  Wizard Atazoth: ty tc all ^_^
[13:05]  Fu Barr: right - well i guess i will call it a day then too
[13:05]  Fu Barr: thanks for joining in again - next week i promise - lots of more fun stuff
[13:06]  Arielle Popstar: i  posted  about  the  lesson  today and  got  a response https://plus.google.com/116809510439349492491/posts/eAFjTxgYf4i
[13:07]  Fu Barr: bye all :)
[13:07]  Arielle Popstar: the  numbers  dropping  a  little  but  ten it  is  summer  and  a  long  weekend  in the  UK  right?
[13:07]  albertlr Landar: Bye all
[13:07]  Arielle Popstar: tc  albert