Bot-Babes/Boys

 

Create A Flying Pet: Transcript 2

Page history last edited by mariahartog@... 2 yrs ago

 

Create A Flying Pet: Transcript 2

 

art Grayson: and we left it were I said that on the Wiki, was the solution to the problem

Catfart Grayson: of putting lots of data items into a string

Catfart Grayson: So lets see how that works

Catfart Grayson: just a sec, I need to get a note card out

Catfart Grayson: hehe, dont worry I go pretty slowly

Catfart Grayson: OK, so here is the code that is going to put all our data int one string

Catfart Grayson: first we create a list and put all our data items into that list

Catfart Grayson: Here Ive put a string "MOVE" which is going to be our message type

Catfart Grayson: after that Im going to put the speed, and then the target location

Catfart Grayson: and then some flag

Catfart Grayson: :)

Elle Pollack: Where in the Wiki was this again?

Catfart Grayson: the point is each of these items are different formats, vectors, integers and floats

Catfart Grayson: Elle, you can reach it from the support section of the SL website

Elle Pollack: I know where the wiki is, I just forgot which part :)

Catfart Grayson: All the work is done by the function llDumpList2String(), which does what its says

Catfart Grayson: ele, the examples I think it was in

Candide LeMay: elle http://secondlife.com/badgeo/wakka.php?wakka=ExampleArgumentMultiplexing

Elle Pollack: Got it

Brianna Lioncourt: will you be handing out copies of your notes to us?

Catfart Grayson: you give llDump... a list, and a string and it converts the list into a string

Catfart Grayson: Briana yes

Catfart Grayson: so after the second line here

Catfart Grayson: the string data contains the string of information

Catfart Grayson: you can see at the bottom of the slide

Catfart Grayson: llDump... converts each data item

Catfart Grayson: into a string and puts the string -=- inbetween everyone

Catfart Grayson: now we can send that string out in the link message

Catfart Grayson: if everyone is happy with that, we can look at how we get it out the other end

You: ok

Catfart Grayson: can I just check, these slides should be rezzinfg really fast for ppl now?

Azazel Czukor: its all good

onionpencil Musashi: i'm fine

Elle Pollack: No problem here

Catfart Grayson: oh, and you will get a copy of the slies at the end

Brianna Lioncourt: yes, but I still dont understand

neand Fleming: yes, fine

You: yup

Catfart Grayson: OK, so llMessageLink sends a link message out

Catfart Grayson: and link_mesage is the event

Catfart Grayson: that is triggered when a link message is received

Catfart Grayson: as you can see here, four variables are set when it is called

Catfart Grayson: sender_num is the link number of the prim

Catfart Grayson: that the script that sent the link message was in

Catfart Grayson: lol, that came out right but horrible

onionpencil Musashi: lol

Catfart Grayson: however, for this project, we dont need it :)

Catfart Grayson: next is the integer num and this will be the same value as in the link message we sent

Catfart Grayson: then a str which contains all our data and finally the key that was also in the mesage

Catfart Grayson: you remember that we are not using the key either

Catfart Grayson: And this is how we decode our link message and extract the data

Catfart Grayson: remember that we are going to use num as the channel or comapny id? In my case it is always 150

Catfart Grayson: so the first thing we do is check to see if num is 150, if it is

Catfart Grayson: I know its one of my messages

Catfart Grayson: now we now to extract the data

Catfart Grayson: and llParseStringKeepNulls() does the opposite

Catfart Grayson: of llDumpList2String

Catfart Grayson: shove the string and the separator string in one end

Catfart Grayson: and out of the other comes a list containing each data item

Catfart Grayson: But, we have lost the data format

Catfart Grayson: they are all strings

Catfart Grayson: once we have our list called Cmd here

Catfart Grayson: we can look at the first data item, item 0

Catfart Grayson: if it is equal to MOVE, we know we have a movment order

Catfart Grayson: and now we can actually get our data

Blueman Steele: what does the command it looks for look like

Blueman Steele: in chat

Catfart Grayson: put the first data item in a integer called speed, the second in a vector

Catfart Grayson: Blueman whch bit?

Ariel Monde: I understand the move part, but i am not sure why we need llParseStringKeepNulls... what s the purpose of it for this project ?

Blueman Steele: like. what do I say to the object

Blueman Steele: MOVE ??

Catfart Grayson: Blueman these are not listens

Catfart Grayson: these are link messages traveliing between scripts in the same object

Blueman Steele: so this is parsing from the orignal grab

onionpencil Musashi: blue these are things pet 'decides' for itself

Brianna Lioncourt: is it possilbe to find a script already done we could use?

Blueman Steele: OH!

Catfart Grayson: Ariel, what we are doing here is showing how to get all the informationw e need from a link message

Catfart Grayson: it will be usd to tell the movement script where to move to

Brianna Lioncourt: So far, this is realy beyond me I'm afriad

Catfart Grayson: LOL, sorry its not going to be that easy

Catfart Grayson: did I mention this weeks homework?

Ariel Monde: so this script share string data between prims in a same object ?

Elle Pollack: Ariel: Because we had to send all the commants from the brain script to the movement script in one string, we need llParseString to break it back up into its parts

Catfart Grayson: Brianna, stick with it for the moment, we can talk afterwards

Catfart Grayson: Ariel yes

Ariel Monde: ah thank you Elle :)

onionpencil Musashi: it's a little over my head too but i'm really interested so i'm trying to learn

Catfart Grayson: OK, so the last three commands here are taking the information from the list Cmd and putting it into individual

Catfart Grayson: data itmes

Catfart Grayson: but, because the list contains strings

Catfart Grayson: each one has to be typecast into the correct foramt

Catfart Grayson: thats the (integer) and (vector)

Catfart Grayson: everyone happy with those commands?

You: ok

neand Fleming: yes

Catfart Grayson: now this isnt the actual code we are going to use its just an example

Catfart Grayson: time to look at the actual structure of the brain script

Catfart Grayson: At its simplest level we only need 2 events

Catfart Grayson: state_entry and link_message

Catfart Grayson: a state_entry is going to pick somewhere to move to and then tell the movement script to go there

Catfart Grayson: and link message is going to wait for the movement script to say that its reached the target

Catfart Grayson: then its going to pick somewhere to go to and tell the

Catfart Grayson: movement script to go there

Catfart Grayson: and so on and so on

Catfart Grayson: there are also two user defined functions that we need

Catfart Grayson: OK so state_entry

Catfart Grayson: as you can see it does two things, it calls a function called get_new_pos

Catfart Grayson: get_new_pos is going to return a vector which

Catfart Grayson: we are going to keep for a sec

Catfart Grayson: and then we are going to put that vector into a function called move_to_position

Catfart Grayson: and move to postion is going to set up and send the link message

Candide LeMay: you mean select_new_position

Catfart Grayson: select_new_position picks a new target to move to

Catfart Grayson: move_to_position sends a link message out with that target in

Catfart Grayson: you could do those two lines in one

Catfart Grayson: move_to_position(select_new_position());

Candide LeMay: no i just mean you said get_new_pos

Catfart Grayson: ah yes sorry

Catfart Grayson: hehe got to watch my terms :)

Catfart Grayson: looking at the link message event

Catfart Grayson: first thing we do is check the channel number

Catfart Grayson: if its correct

Catfart Grayson: pfft extra work for you

Catfart Grayson: if its correct we are going to check the first item in the list

Catfart Grayson: if it says ATPOS, we know its from the movement script

Catfart Grayson: (Which we hanvt written yet)

Catfart Grayson: so since we have reached the target we select a new target and send the pet on its way again

Catfart Grayson: and it just keeps doing that

Catfart Grayson: pick a traget wait for a mesage pick a target wait...

Catfart Grayson: later on we will add other events

Catfart Grayson: ok lets take a look at theose two user functions

Catfart Grayson: This function does a lot of work, its job is to pick the next target to move to

Catfart Grayson: changin how this function works will make a big impact on the behaviour of your pet

Catfart Grayson: now in the class we are just going to pick a random position, but it doesnt have to be

Catfart Grayson: you could change this for instance to read the next

Catfart Grayson: landmark in the inventory

Catfart Grayson: OK, first thing Ive declared a global variable at the top

Catfart Grayson: now that should be right at the top of your code, and being global it will be availalbe

Catfart Grayson: to all bits of this script

Catfart Grayson: the move range is the maximum distance your pet will move away from its current position

Catfart Grayson: so here Ive set it to three

Catfart Grayson: that means the pet will move no further than 3 meters in each direction

Catfart Grayson: its nother variable you are going to want to fiddle with to get

Catfart Grayson: something that looks good for you

onionpencil Musashi: just as a silly question is there a max practical range?

Catfart Grayson: yes, the lenght of a sim

Catfart Grayson: objects like people have trouble moving acoss sim bounaries

Catfart Grayson: OK so how are we going to get the new target, we are going to calculate an offset vector

Catfart Grayson: fourth line down I declare the vector then each of its three components is set using llFrand

Catfart Grayson: Ill go through the offeset.y line in details

Catfart Grayson: offeset is a vector

Catfart Grayson: offset.y is the y component of the vector

Catfart Grayson: so if the vector is <1,2,3>

Catfart Grayson: then offset.y equals 2

Candide LeMay: err aren't you missing some parens there, or the one at the end should not be there

Catfart Grayson: you can read each component of a vector or set them using this method

Catfart Grayson: hehe maybe, these slides were a bit rushed in places

Catfart Grayson: err.... I meant congratulations on

Catfart Grayson: spotting the deliberate error

onionpencil Musashi: lol he was ....testing you.. that's it

TxKatie Curie: lol

Catfart Grayson: Ok so the line offset.y is setting the y component of offset

Catfart Grayson: lLFrand is set here to give a number between 0 and 6

Catfart Grayson: (Twince move_range)

Catfart Grayson: and then we deduct move_range

Catfart Grayson: so offset.y becomes a value between -3 and +3

Catfart Grayson: same with offset.x

onionpencil Musashi: cool!

Catfart Grayson: Now Ive treated z slightly differently

Catfart Grayson: z is the up down

Catfart Grayson: think about how birds and things fly

Catfart Grayson: airplanes insencts

Catfart Grayson: they all move further in the x y palne

onionpencil Musashi: mostly across

Catfart Grayson: compared with up and down

Catfart Grayson: so Im only going to have half the values for the z axis

Catfart Grayson: the upshot is we end up with a box twice the move range long

Catfart Grayson: and the same wdth and move range high

Catfart Grayson: with the pet in the center of that

Catfart Grayson: it will move somewhere in the box

Catfart Grayson: the last thing to do is to convert our offset into sim coordinates

Catfart Grayson: adding the offeset to the gets current position will do that

Catfart Grayson: so if the pet is at 20,20

Catfart Grayson: we choose a random move of 2,-1

Catfart Grayson: we actually want to move to 22,19

Catfart Grayson: so the last thing this fucntion does is return the new target vector

Elle Pollack: what does "return" mean?

Catfart Grayson: we are going to come back to this function

Enjah Mysterio is offline

Catfart Grayson: ele return means that the function returns that value to the scrip

onionpencil Musashi: the answer it comes up with

Catfart Grayson: see the line vector next_pos = select_new_position()

Catfart Grayson: select_new_position is the function we have just been lookig at

Catfart Grayson: it returns a new target vector and we put it into

Catfart Grayson: the vector next_pos

Catfart Grayson: did that make sence?

Ariel Monde: yes

Gino Medici: yep

neand Fleming: it did

Catfart Grayson: Ok, we now have a new target and the next thing we do is send it to the function move_to_position

Catfart Grayson: hopefuly you will recognise some of this from previous sides

Catfart Grayson: Setting up a few global variables again

Catfart Grayson: speed is fairy obvious

Catfart Grayson: target_range is how near the pet is going to get to the target

Catfart Grayson: before it decides its reached it

Catfart Grayson: I'll go into that more in the movement script

Catfart Grayson: both of these are things

Catfart Grayson: you are going to want to change and experiment with

Catfart Grayson: then the move_to_positon function its self

Catfart Grayson: which take a pameter of a vector

Catfart Grayson: and which is going to be our next target

Catfart Grayson: put all the data items into a list

Catfart Grayson: and then send them in a link message via llDumpList22String as we did before

Catfart Grayson: job done

Catfart Grayson: everyone happy with that?

Ariel Monde: yes

Catfart Grayson: your homework

Catfart Grayson: write a brain script

Catfart Grayson: lets take a look at the layout again

Catfart Grayson: three global variables at the top

Gino Medici: Cat, are you going to give us the slides at the end of the class?

Catfart Grayson: a function that is going to take a vector and spit out a link message

Catfart Grayson: a funtion that is going to return a random position

Catfart Grayson: then the states

Catfart Grayson: state entry pick a target and then send a move message

Catfart Grayson: link mesage, wait for a ATPOS mesage then move somewhere else

Catfart Grayson: now Ive added another event

Catfart Grayson: on_rez

Catfart Grayson: which should be the same as your state_entry event

Catfart Grayson: you need that to stop problems when you take your pet into your inventory

Catfart Grayson: imagine that your in the top left corner of the sim

onionpencil Musashi: ah.

Blueman Steele: so state_entry only runs once then?

Catfart Grayson: the pet moves a little way, you take it into your inventory and move

Catfart Grayson: to the bottom right

Catfart Grayson: Blueman, yes state_entry runs the first time

Catfart Grayson: a script enters that state

Blueman Steele: but doesn't reset each rezzing?

Catfart Grayson: Blueman no!

Catfart Grayson: if you take a script into your inventory

Catfart Grayson: when you take it out

Catfart Grayson: it starts running in exactly the same

Blueman Steele: I see... so a memory of sorts

Catfart Grayson: state

Catfart Grayson: the 'prgrmme ointeer' is sotored as well

Catfart Grayson: Im going to give you a script caled test harness

Catfart Grayson: a test harness is used to help test scripts where you

Catfart Grayson: have things missing, we dont have a movement script yet

Catfart Grayson: so the test harness is going to pretend to be the movement script

onionpencil Musashi: cool

Catfart Grayson: it will listen for the correct link message and if it hears it it will telll you what it "hears

Catfart Grayson: it will then wait a few second and then send an ATPOS message back to your brain script

Catfart Grayson: So thats your task, you will have a copy of the slides in a second

onionpencil Musashi: groovy

Catfart Grayson: so you will hve pictures of allt he code, plus my deliberate errors

neand Fleming: lol

Catfart Grayson: Thats the end of this session, in a moment I will sort out the trnascript then you can take the slides

Catfart Grayson: next week will will start looking at the movement script itself

Rhiannon Chatnoir: thank you

Catfart Grayson: thankyou all for attending

Ariel Monde: will we have the transcript from last week class when we discuss some of session 2 ?

Brianna Lioncourt: Yes, thanks!

Catfart Grayson: yes

 

 

Back To The Create A Flying Pet Home Page

Back To The Script Library

 

Comments (0)

You don't have permission to comment on this page.