Mecha Construction in SL, Lesson 3

[11:51]  Jurgi Harlan: Welcome back
[11:51]  You: Sorry, I crashed most spectacularly
[11:51]  Jurgi Harlan: Sorry, hope it wasn’t the headlights display.
[11:52]  You: I have no idea what it was. Anyway, well done on the headlights. Are they toggleable?
[11:52]  Jurgi Harlan: Not as of yet.
[11:52]  Jurgi Harlan: I’m still looking for the right code to do it.
[11:52]  Jurgi Harlan: But we were going to discuss channel commands next, so I figured that was a good time to hammer that out.
[11:53]  Aestival Cohen is online
[11:53]  Jurgi Harlan: For now, I’m swapping in and out the mod and no-mod chassis.
[11:53]  lilone Sandgrain is online
[11:54]  Jurgi Harlan: But the particle stuff is fine instead, I am nothing if not patient.
[11:54]  You: Perhaps we can cover the primciples of both today.
[11:54]  You: *principles
[11:54]  Jurgi Harlan: That would be great
[11:55]  Jurgi Harlan: Setting up the lesson tools?
[11:56]  Gog Gremlin is online
[11:56]  Jurgi Harlan accepted your inventory offer.
[11:57]  You: Okie doke. The most crucial part of today’s lesson is to get a sense of the different ways that objects can communicate with each other.
[11:58]  Meditate Pillow: Jurgi Harlan, say ‘/1 Hide’ to hide me, or ‘/1 Show’ to make me show. Or just right-click and sit on me to use me.
[11:58]  Jurgi Harlan: Alright
[11:59]  Lars Bismark is offline
[11:59]  You: So, objects in SL have no awareness of each other unless we give them that awareness: letting them collide via the physics engine, having them sense each other, email each other, or chat with each other.
[12:00]  Jurgi Harlan: Alright.
[12:00]  You: Each method has benefits and drawbacks; for our purposes, chatting is the simplest and best suited for our needs.
[12:01]  You: it is almost completely non-secure, but it is quick and reliable enough. =)
[12:01]  Jurgi Harlan: Okay, that would be because it’s faster than email, and we have move flex-room in the signals made, as opposed to physics interactions, which we have to adapt to.
[12:01]  Jurgi Harlan: more flex-room*
[12:02]  Jurgi Harlan: And negative because near anything can chat, and interfere with smooth operation.
[12:02]  You: And sensing can be pretty hard on the server, depending on how it is implemented.
[12:02]  Jurgi Harlan: I’m not familiar with sensing, master. Is that the same system that the visitor counters use?
[12:03]  You: Right. Chat can be lossy especially when you’re flooding the chat buffer with lots of data, so if you’re communicating anything important between objects, it is important to verify.
[12:03]  You: Sensing gives the object “eyes” and allows it to passively gather information about the world around it without interacting.
[12:04]  Jurgi Harlan: Hm. Interesting. I hope that I will be taught that one day.
[12:04]  You: So for example, a popular application of sensors is to restrict the sensing to agents. Typically this shows up with avatar “radars”
[12:04]  Jurgi Harlan: /nods
[12:05]  Jurgi Harlan: Like the visitor counters and security systems.
[12:05]  You: Yes indeed
[12:05]  Jurgi Harlan: Alright. But we won’t be addressing that today…correct?
[12:06]  You: No, we can cover sensors another day when discussing how to make giant mecha avatars able to punt other avatars or step on them.
[12:06]  Jurgi Harlan: OOOH!
[12:06]  You: It is fun indeed.
[12:06]  Jurgi Harlan: I believe it@
[12:07]  You: Anyway, so our situation is as follows: we want to create an upper arm out of particlesthat go from the forearm to the shoulder or vice versa.
[12:08]  Jurgi Harlan: Yes, to create the illusion of a energy-based suspension system to hack the shoulder problem
[12:08]  You: But in order to do that, we need the key of each prim that will be “receiving” (i.e., will be the particle target) the particles.
[12:08]  Lars Bismark is online
[12:08]  Jurgi Harlan: The key of each prim…hm. I do not know how to find that.
[12:08]  You: The practical difficulty is that the key of each prim in an attachment is different every time you put on the avatar or teleport with it on
[12:09]  You: So, we need a robust system that dynamically updates its understanding of the necessary keys every time we teleport or rez.
[12:09]  Jurgi Harlan: Hmm…so hard coding there wouldn’t work. You’ll require variables, and commands to obtain the,
[12:09]  You: Luckily, that’s actually pretty easy.
[12:09]  Jurgi Harlan: them.*
[12:09]  You: Yes, that is a correct understanding.
[12:09]  Jurgi Harlan: Alright.
[12:10]  Failed to place object at specified location.  Please try again.
[12:10]  Jurgi Harlan: How do we go about setting up such a subsystem?
[12:11]  Jurgi Harlan: The shoulder code is locked and unreadable to me.
[12:11]  Jurgi Harlan: As is the forearm code.
[12:12]  You: First, we need to figure out how to get the shoulder and the elbow chatting with each other
[12:12]  Jurgi Harlan accepted your inventory offer.
[12:12]  Jurgi Harlan accepted your inventory offer.
[12:12]  You: Rez each of those near the other
[12:12]  You: Are they readable to you now?
[12:13]  Jurgi Harlan: Alright, thanks to my time at the particle lab, much of this is comprehensible to me
[12:13]  Jurgi Harlan: Yes, sensei.
[12:13]  Jurgi Harlan: Is this your documentation?
[12:14]  You: This particle script is an adaptation of the eminent Eltee Statosky, of Luskwood. Several other free and open particles scripts are out there, including by Jopsy Pendragon and Ama Omega
[12:14]  Memir Quinn is online
[12:15]  Jurgi Harlan: The documentation is well done…and the optional code is useful-looking.
[12:16]  You: This particle script is pretty well-documented, so we won’t spend much time on the particle variables except to say that it is quite well worth your time to simply play around and see what different effects are possible.
[12:16]  Jurgi Harlan: Yes. I will definately be tinkering with this framework later.
[12:16]  You: Today we’re more concerned with inter-script communication.
[12:16]  Jurgi Harlan: Alright
[12:17]  Jurgi Harlan: Is this a lesson building on what we learned from the bullet and the gun?
[12:17]  Fryer Klinger is offline
[12:18]  You: Actually, we will not be covering much of the same ground at all today. The bullet and gun had little in the way of any communication except for the idea of the start_parameter passed from gun to munition at the time of rez
[12:18]  Jurgi Harlan: Alright…I note the followTarget integer is True.
[12:18]  Jurgi Harlan: I would think the root of the work is being funnelled though that
[12:19]  You: Yes, that is a key detail. The entire point of the communication here is to keep that target key up to date
[12:19]  Jurgi Harlan: I see.
[12:20]  You: Scrolling down below the particle engine coding, about 80% of the way down, look for an “init() {” function
[12:20]  Jurgi Harlan: In the region of the Emissive Mask?
[12:20]  Jurgi Harlan: I note that the data requests here are all variables.
[12:21]  You: Further dow– the first line within it is a llListenRemove
[12:21]  Jurgi Harlan: yes, i see it
[12:21]  You: Good! This block of code sets up the listening functionality that is one-half of communication.
[12:22]  Jurgi Harlan: On channel 997?
[12:22]  You: First, we destroy the old listen with llListenRemove, then reestablish it with llListen.
[12:22]  Jurgi Harlan: Ah, so as to not allow conflicts.
[12:22]  You: Yes, it is on a nonzero channel to keep it from spamming us with its simple comm. protocol.
[12:23]  Jurgi Harlan: I see, much like an encoded wireless channel PAN in Shadowrun…
[12:23]  Jurgi Harlan: It’s working of it’s own “signal wavelength” unlikely to be duplicated.
[12:23]  You: Stritcly speaking, it is usually good practice to use a negative channel for chat communications that are strictly script-2-script, since avatars can not directly use negative chat channels.
[12:23]  Jurgi Harlan: After all, who chats in 997?
[12:24]  Jurgi Harlan: Negative channels…gotcha.
[12:24]  You: You are correct, though for clarity’s sake I should note that chatting on a nonzero channel does not at all encrypt the communication; anyone out there can code a simple listen-chat repeater listening on your channel if they know it.
[12:25]  You: However, we have something like four billion chat channels to choose from
[12:25]  You: Still, never ever EVER use chat for ANY communication that should be encrypted in any way.
[12:25]  Jurgi Harlan: I see.
[12:26]  You: But it is perfectly fine for simple tasks like this.
[12:26]  Jurgi Harlan: So not for, say, ATMs and vendors.
[12:26]  You: So, once we init() the script, it is waiting for updated key information distributed on the specified channel
[12:26]  Jessica Qin is offline
[12:27]  You: what do on_rez and state_entry do for us?
[12:27]  Jurgi Harlan: let’s see.
[12:28]  Jurgi Harlan: Reset script…so, on rezzing, the script cleans itself off and reboots.
[12:28]  You: yes, and doing so always triggers state_entry.
[12:29]  Butterfly Wishbringer is online
[12:29]  Jurgi Harlan: It creates a timer…five seconds long…
[12:30]  Jurgi Harlan: And creates a text entry that looks to just be one blank space…which is what the listen is looking for.
[12:30]  You: Well, in this case, the llSetText was used to simply clear out the hovering text over the prim containing the script.
[12:31]  Jurgi Harlan: Oh, alright.
[12:31]  You: Specifying an empty string erases the floating text. =) Next we have the listen() event handler. So, what happens when this script detects any chat on channel 997?
[12:32]  Lars Bismark is offline
[12:32]  Jurgi Harlan: Hm…
[12:32]  Jurgi Harlan: I’m not sure…but I think first, it’s checking to see if the message is blank.
[12:32]  Jurgi Harlan: If not, it’s proceeding
[12:33]  Butterfly Wishbringer is offline
[12:34]  Jurgi Harlan: And it should be then shipping the non-blank response to the Target variable…but I’m not seeing where that happens…
[12:34]  Aestival Cohen is offline
[12:34]  Jurgi Harlan: Wait, is it target=(key)message?
[12:34]  You: Bingo.
[12:35]  You: The other joint has just discovere its own key, and chatted that info to this script on channel 997. So, we cast that string chat data into key format, and assign it to target.
[12:35]  You: Then what?
[12:36]  Jurgi Harlan: So, we’re establishing, for wont of a better term, a wireless connection between the two, which is constantly(every 5 seconds), pinging each other to make sure the set still is aligned.
[12:36]  You: Yes.
[12:36]  Jurgi Harlan: Alright…
[12:37]  You: Then, once we’ve got the updated information, we reinitialize the particle stream with the updated target.
[12:37]  You: However, there are several porblems with this script.
[12:37]  You: *problems
[12:37]  Jurgi Harlan: is that running=true?
[12:37]  You: It is a functional script, but a very sloppy one.
[12:37]  Jurgi Harlan: Or setParticles?
[12:38]  You: SetParticles is necessary to update the particle system’s target; it isn’t enough to simply update the target variable. We must also reboot the particle engine.
[12:38]  You: Recall that I said the key we’re interested in changes each time we rez or teleport. Is that happening every five seconds>?
[12:39]  Jurgi Harlan: Unlikely.
[12:39]  Jurgi Harlan: You’d have to be pretty frenetic to need that much rechecking.
[12:40]  You: True! So perhaps it is wasteful of us to ask the server to go through this whole process twelve times a minute.
[12:40]  Jurgi Harlan: So, is there a trigger that responds to being rezzed?
[12:40]  Jurgi Harlan: With which we can replace that one?
[12:40]  You: on_rez fires every time we rez or teleport, so we can use that as our trigger to kick everything off.
[12:40]  Jurgi Harlan: Ah.
[12:41]  Jurgi Harlan: Since the system life of the stream is infinite, we shouldn’t need to check any more often than that.
[12:41]  You: So, I see two places where we’re being wasteful here. One, the timer doesn’t need to work once it has done its job. Second, the listen handler is no longer useful once we’ve updated the key post-rez
[12:42]  Jurgi Harlan: And resource wastefulness creates sim crashes during your mech wars.
[12:42]  You: ! I spoke too soon. I DID put in a llListenRemove
[12:43]  You: Yes, you are correct. There are lots of poorly coded scripts out there; we shall endeavor to have our work not counted among them. =)
[12:43]  You: SO, armed with the knowledge that llSetTimerEvent(0); will cancel the timer, where do we want to put it?
[12:45]  Jurgi Harlan: Hm.
[12:45]  Jurgi Harlan: Hm
[12:46]  Jurgi Harlan: After a successful run.
[12:46]  You: Yes indeedy!
[12:46]  Jurgi Harlan: Right after the listen remove
[12:46]  You: Perfect.
[12:47]  You: That way once it has completed its task, the script goes passive, waiting for the next rez or teleport
[12:47]  You: And is quite light on the server.
[12:47]  Jurgi Harlan: Yes…but with on rez, why do we need the five second delay?
[12:47]  You: By extension, we are then being good grid citizens.
[12:47]  You: Excellent question.
[12:47]  Jurgi Harlan: Lag?
[12:47]  You: Exactly.
[12:48]  You: We have no guarantee that the OTHER script involved in this communication will be ready as soon as this one is.
[12:48]  You: In my tests way back when, it could be a difference of as much as 3-4 seconds on a slow server.
[12:49]  You: So, we let the script be graceful by waiting for its partner before departing to the dance floor.
[12:49]  Jurgi Harlan: I see
[12:50]  You: Why would the timer event fire off a chat message on channel 999 instead of 997, the cnhannel this script listens on?
[12:50]  Jurgi Harlan: Hm…well, the two joints are listening on 997 and 996.
[12:51]  Jurgi Harlan: I didn’t notice a broadcast on 999
[12:51]  You: Hmm, perhaps I’m looking at a different version of the script. Whoops. Anyway, why use 2 different chat channels, 996 and 997?
[12:52]  Jurgi Harlan: So as not to create a code hiccup and having a joint targeting itself, listening to itself talk.
[12:52]  You: Excellent. This is just one of many ways to sort out communications cleanly.
[12:53]  Jurgi Harlan: Sensei, I apologize, but I have an upcoming appointment.
[12:53]  You: No problem, this is a good stopping point.
[12:53]  Jurgi Harlan: Listening to the Buddhist Lama Bhante Kusaldhamma elsewhere.
[12:54]  Jurgi Harlan: I agree, I have come to understand, and I thank you for another useful lesson

Leave a Reply