Keep Informed

Entries in Globals (1)

Tuesday
Nov082011

MUG Office Hours Transcript January 23rd, 2012

[17:13]  Chef Pilot: Hey boss
[17:14]  Chef Pilot: What's happening?
[17:14]  Antonius: Hey Pilot.
[17:18]  Antonius: I've enhanced your elevator script.
[17:19]  Chef Pilot: Looks like you've done a lot of work to it mate.
[17:20]  Antonius: Well when a customer asked for your elevator script, I took a look & it was a neat concept using physics to move the elevator.
[17:20]  Antonius: So I just built on that to create this one. Did you get the group notice with the link?
[17:21]  Chef Pilot: Ahhhh, yeah...
[17:21]  Chef Pilot: Yes, as a physical object moving, an avi doesn't have to sit on it.
[17:21]  Antonius: Yes exactly! That was what was so neat about it.
[17:33]  Antonius: Ok. So why don't you download the model & open up MOAB so we can review. (Download: http://bit.ly/whEQzz)
[17:35]  Antonius: Let me know when you have it loaded.
[17:46]  Chef Pilot: Stone the crows!!! You've certainly done some work on it!
[17:47]  Antonius: A little. :-) But the basic concept remains.
[17:47]  Antonius: Ready to review?
[17:48]  Chef Pilot: Sure, got it opened up and just looking at the code.
[17:48]  Antonius: Ok. An overview first. (http://screencast.com/t/WQ87qVKDrT2)
[17:49]  Antonius: We start up and take the Initial Transition to the WaitForCall state.
[17:49]  Antonius: Here, we wait for a touch-end event which brings us to the ShowMenu state to display a dialog.
[17:50]  Chef Pilot: yep
[17:50]  Antonius: Note that ShowMenu is one of the built-in components in MOAB.
[17:50]  Antonius: A menu is displayed which displays a selection of floors to choose from.
[17:51]  Chef Pilot: yes
[17:51]  Antonius: From there the listen event brings us to the Choice Point C.
[17:52]  Antonius: If the Reset button was selected we want to re-initialize the elevator. For simplicity, it automatically defines the Ground Floor at the current position.
[17:52]  Antonius: So if you move the elevator platform around, you select Reset to set it at it's new location. (This function of course can be redone in a different way to make a cleaner dialog.)
[17:53]  Antonius: Note that the Reset transition goes to the border.
[17:53]  Antonius: Do you recall what this does Pilot?
[17:54]  Chef Pilot: That takes us outside
[17:54]  Chef Pilot: But we are at the lowest level....
[17:54]  Antonius: Well in this case notice that it is a small shaded circle on the border, meaning that it is not connected to anything outside.
[17:55]  Antonius: We are actually at the highest level, the top state.
[17:55]  Chef Pilot: So that takes us back through init()?
[17:55]  Antonius: Exactly!
[17:55]  Antonius: By George he's got it!
[17:55]  Chef Pilot: Highest level, lol......
[17:59]  Antonius: Ok. So we go back through the Initial Transition to the WaitForCall state.
[17:59]  Chef Pilot: Ah :)
[17:59]  Antonius: If Reset wasn't selected then one of the floor buttons was, so we continue on to the MoveToFloor state.
[18:00]  Chef Pilot: nods
[18:00]  Antonius: Before discussing the code in MoveToFloor, let's look at the State Variables & Functions defined.
[18:01]  Antonius: See the screen or open up the State Variables & Functons editor for the top state. (http://screencast.com/t/6rTkyhJftG1a)
[18:02]  Antonius: There are two variables that need to be configured. FloorNames is a list of strings that contains the names for the buttons.
[18:02]  Chef Pilot: Ah, if I open State variables & functions for moveto floor I get nothing.
[18:03]  Antonius: Open up the state variable editor for the top state
[18:03]  Antonius: FloorHeights is a list of floats that corresponds one-to-one to FloorNames.
[18:03]  Chef Pilot: yep, gottem now.
[18:03]  Antonius: (I could have used a strided list for this, but I wanted to keep things simple.)
[18:04]  Chef Pilot: Kiss principle
[18:05]  Antonius: Yes, especially for an introductory model. So you can see we have four floors plus the ground floor.
[18:05]  Antonius: We also have to put in "Reset" there, though the model could be changed to avoid having to do this and reset the script through some other means.
[18:06]  Chef Pilot: Don't they call the ground floor - first floor?
[18:06]  Antonius: It's most always called Ground, but you're right, then the next floor above should have been called Second.
[18:07]  Antonius: The floor heights are each specfied as the distance from the ground floor along the z-axis.
[18:07]  Chef Pilot: yep
[18:08]  Antonius: The other variables are just housekeeping and don't need to be configured. Although you can set the Speed of the movement to the new floor if desired.
[18:09]  Antonius: Let's take a look at the functions defined there.
[18:09]  Antonius: Init() is called in the Initial Transition as we discussed earlier.
[18:10]  Antonius: It starts by using a MOAB LSL Action to level the platform.
[18:11]  Antonius: It then saves the current position in GroundFloor and assigns the name for the Ground Floor to Floor which is used to set a display title for the elevator (showing the current floor).
[18:11]  Antonius: The movement of the platform is then constrained (straight from your script Pilot)
[18:09]  Chef Pilot: Global variables?
[18:13]  Chef Pilot: Although the variables FloorNames etc are entered in the highest state area, they would be considered globals ? They can be accessed by lower states?
[18:13]  Antonius: Yes.
[18:13]  Chef Pilot: This is where I was coming unstuck.
[18:14]  Chef Pilot: Between global and state variables.
[18:14]  Antonius: At the highest level, the state variables & functions operate exactly like LSL globals; they are accessible to all.
[18:14]  Antonius: When you define a state variable/function for a particular state, it is only accessible to that state and any contained states that it may have.
[18:15]  Chef Pilot: nods
[18:15]  Antonius: We then ensure that MoveToTarget & physics are turned off
[18:16]  Antonius: Next we look at the MoveTo() function (http://screencast.com/t/sJY0xQHH)
[18:17]  Antonius: This function moves the platform to the new floor. It first calls the MoveToTarget() function and then turns physics on for the prim.
[18:18]  Chef Pilot: Shouldn't the physics be changed before the move?
[18:19]  Antonius: This ensures that the movement starts off correctly as there can be a delay before the MoveToTarget takes effect, so if we turn physics on first, we could get some drifting.
[18:19]  Antonius: This trick came from the wiki.
[18:19]  Chef Pilot: But the prim will leave anyone standing on it.
[18:20]  Chef Pilot: Won't it?
[18:20]  Antonius: You need to have physics turned on for MoveToTarget() to work. So it remains pending after calling it until physics has been turned on; that's the trick.
[18:22]  Antonius: Is that ok?
[18:24]  Chef Pilot: Oooohhhhhhhh....
[18:24]  Antonius: It does work. I'll show you shortly.
[18:25]  Chef Pilot: She's jake mate....
[18:25]  Antonius: StopMove() stops the move and turns off physics. (http://screencast.com/t/Sg9PdGfT)
[18:26]  Chef Pilot: No question about that, lol.
[18:26]  Antonius: Ok let's take a look at the code within the MoveToFloor state (http://screencast.com/t/mEf1fcmZ)
[18:27]  Antonius: On entering the state we have to get the floor position to move to.
[18:27]  Antonius: So we first search the FloorNames list find the index of the floor name selected in the menu.
[18:28]  Antonius: Then we index into the FloorHeights list to get the new z-axis value.
[18:28]  Antonius: We add this to EndPosition which was initialized to the GroundFloor height.
[18:29]  Antonius: We then simply call the MoveTo() function with this new EndPosition as a parm.
[18:29]  Antonius: Any questions on this?
[18:29]  Chef Pilot: It is easier when you explain it, lol.
[18:30]  Chef Pilot: I got lost at floorindex
[18:30]  Antonius: ok now?
[18:30]  Chef Pilot: Yeah mate
[18:30]  Antonius: Great!
[18:31]  Antonius: I then added to your script the use of llTarget(),
[18:31]  Antonius: which you can use to find out when you get close to the target specified in llMoveToTarget()
[18:31]  Chef Pilot: Mate you added a sh*load the the initial script, lol.
[18:32]  Chef Pilot: And the original script was in the free script library, lol, it wasn't mine :)
[18:32]  Antonius: Well it inspired me anyways!
[18:33]  Antonius: I also put in the timer as you had in case things go wrong.
[18:33]  Chef Pilot: Yep. can see that.
[18:34]  Antonius: Note that in the Exit Code for the state, we remove the target tracking, move the platform directly to the exact required position, and then stop the timer.
[18:35]  Chef Pilot: yep
[18:35]  Antonius: So going back to the top state, (http://screencast.com/t/WQ87qVKDrT2) you can see the at_target transition leaving the MoveToFloor state.
[18:36]  Chef Pilot: It is unbelievable mate.
[18:36]  Antonius: When the platform gets close to the destination (I set it to 0.1 meter), the at_target event gets sent.
[18:37]  Antonius: The Exit Action code of MoveToFloor gets executed, we lock into the right floor position and then we move back to the WaitForCall state.
[18:38]  Chef Pilot: tnum.....
[18:38]  Chef Pilot: I gotta find tnum....
[18:39]  Antonius: tnum is the argument name for the llTarget() handle
[18:39]  Antonius: The handle was saved in TargetHandle in the Entry Action code of the MoveToFloor state.
[18:40]  Antonius: So for completness we verify in the at_target transition that we are responding to the right llTarget() request.
[18:41]  Antonius: We put that test in the Guard Condition of the at_target transition.
[18:41]  Antonius: That's all there is to it.
[18:45]  Antonius: Meet me outside. Let's try it out.
[18:46]  Chef Pilot: We're here....
[18:46]  Antonius: Here's the elevator. Try it out.
[18:47]  Chef Pilot: Good stuff!
[18:48]  Antonius: I really like it. It accelerates/decelerates nicely.
[18:48]  Chef Pilot: Yeah!! Is really good!! Well done!
[18:47]  Chef Pilot: What about weight?
[18:48]  Antonius: Yes. I haven't tested all of that out yet, so there could still be some gotchya's.
[18:50]  Antonius: A little bouncy. lol
[18:51]  Chef Pilot: I'm smooth, but I'm using an ao.
...
[19:06]  Chef Pilot: Well I gotta go for tucker mate :)
[19:07]  Antonius: Have a good one!