10 Steps to Creating Your First MiceOnABeam Script
Monday, March 28, 2011 at 3:55PM I recently completed a section in the online documentation on a simplified development process for creating a script using MiceOnABeam. I thought I'd reproduce a version of it here for readers of the blog.
Step 1: Learn the basics
While MiceOnABeam significantly simplifies your use of LSL and generates much of the scripting code, you should still become familiar with the basic concepts of LSL such as variables, datatypes, functions, flow control statements and events.
If you're not familiar with these please check out wiki.secondlife.com/wiki/Help:Getting_started_with_LSL or review the other introductory tutorials at the LSL Portal (wiki.secondlife.com/wiki/LSL_Portal) or LSL Wiki (www.lslwiki.net/lslwiki/wakka.php?wakka=HomePage).
In addition there are three key MiceOnABeam modeling features that you must become familiar with, namely the State, the Transition and the Choice Point. In many cases these modeling components will be all you need to create your script. Check out Modeling Overview to get up to speed here.
Step 2: Create a new script model
From MiceOnABeam's File menu, select New.... Then enter a name for your new script and click on the OK button. This will create a new State Editor window in which you will design your script model.
Step 3: Design the states for your script
The first step in the design is to break down your script's logic into one or more states. States represent the major modes of your script. Each state represents a point in time where your script is waiting for a specific set of things to happen, called events, in your virtual world. Each event type can be handled in a different way depending on which state your script is in when the event is received. More help on using states and events is provided in the Modeling Overview.
To create a new state select the State icon
in the tool palette and then click within the State Editor at the location where you want the new state to appear. You can then rename, resize and move the state as desired.
Step 4: Specify the events that your script will respond to
To specify an in-world event that your script will respond to, you use a transition which is represented by an arrow line. To create a new transition select the Transition icon
in the tool palette and then click and hold the mouse button within the State Editor on the state in which the event will occur. Then drag the mouse over to the state that you want your script to be in after processing the event (which can be the same or different state).

To assign an event to the transition, you must open the Properties Editor for the transition by right-clicking over it and selecting Edit Properties from the menu. Then choose the desired event from the drop-down list. You can also optionally set a Guard Condition (which must be an LSL expression that returns TRUE or FALSE) to enable or disable the handling of the event.
Don't forget to create an Initial Transition from the Initial Point
to the starting state for your script, otherwise your script won't know which state to start up in, and will simply terminate when run.
Step 5: Specify what should happen when an event occurs
Once an event occurs you will naturally want your script to perform one or more actions to effect changes within your virtual world before moving to the next state and waiting for another event. These actions can be specified in several places in your MiceOnABeam model, such as within the transition itself (Transition Action) or within a state (Entry and Exit Actions).
All action code is entered within the Properties Editor of the corresponding state or transition (right-click over the component to open it's Property Editor). Code can also be entered in global or scoped functions that can be defined.
To enter in action code you have two options:
-
Use the LSL Actions feature to select one of the built-in actions provided in MiceOnABeam, or
-
Insert your own LSL code directly.
After entering in your action code in the Properties Editor select the OK button to close and save your changes.
Note that you can also document your script model by entering in a textual comment for each modeling component. To create a comment right-click over a modeling component and select Edit Comment from the menu. To easily view your comments select the Show Comment icon
in the State Editor's toolbar and then move the mouse cursor over to the components of interest.
Step 6: Save your script model
From MiceOnABeam's File menu, select Save. Then enter a name for the model file and click on the OK button. This will save your model within the MiceOnABeam\Scripts folder of your documents folder.
Step 7: Set your debugging options
Once you've created the first draft of your script model, you'll want to test it out within your virtual world. To help you here MiceOnABeam provides special debugging features to help you. From MiceOnABeam's Tools menu, select Options, and then click on Code Generation. Select one or more of the built-in execution tracing options and then select the OK button.
Step 8: Generate the LSL Script
You then generate the LSL code corresponding to the model by selecting Generate LSL... from the Script menu. A window will open up containing the generated code. You simply select the Copy button to copy the code and then paste it directly into your virtual world's scripting editor.
If you're using Second Life, ensure that the Mono checkbox is selected at the bottom of the SL editor, and then click the Save button. Ensure the Running checkbox is selected, and your MiceOnABeam generated script should now be running.
Step 9: Test & Iterate
Test your script in your virtual world, running through all possible events and situations that your script may encounter. When you need to make a change back in your MiceOnABeam model, make the change and simply press CTRL-g to generate the LSL script and automatically copy it to the system clipboard so that it's ready for pasting into your virtual world's scripting editor.
Note that the latest software development strategies advise that you add functionality to your script in small increments, testing at each iteration. In this way you will always have a working version of your script and can more easily back out a change that hasn't worked out.
Step 10: Optimize & deploy the generated code
After all your testing is completed and you are ready to deploy your new script, select Generate LSL (Optimized)... from the Script menu. This will generate a script for the model without any system-generated comments and as well perform several optimizations in the code. You can also select the Code Generation option to exclude comments that you have entered in the code for a more compact script.
