<

LESSON 4 - Part 2:  Randomizing Events

Creating The Randomizing Behavior

Open behavior #4108: "Randomize". Keep in mind that we have 4 events to randomize. In order for our script to work, we will need a total of 10 lines in this behavior. The lines we will need are as follows:

  • 1 line for the instruction statement that chooses the events randomly;
  • 2 lines for each of the events (we have 4, so we need to double that making 8); and
  • 1 line for the Standard Exit statement so the object will work correctly. That is to say, every event must be "escaped" or the object will malfunction due to confusion.

Go ahead and add 10 new lines right now.

First we'll create our opening statement. Select #0 (the first line). We want this line to read: Random Number 0-4 into Temporary Storage 2 (stack: 7)

We say 0-4 because we have 4 events we want to randomize, and although this script will only use 0 through 3 (four events), we need an extra empty one in there so that all events will randomize properly. The last one is more or less a "waiting room" so the next event in line can wait its turn until the previous event gets off the stage. Let's create the line. Select it, and fill in the Data box:


Fig. 2.29

Your behavior so far should look like this:


Fig. 2.30

As we move along, pay attention to the returns. Returns are always essential.

Second, we will create our closing statement. Select the last line, #9, and fill in your Data box like this to generate a standard exit script:


Fig. 2.31