GCcubed – MemoCube: Script Breakdown


The following is a brief chronology of the main game scripts within MemoCube. It is in no way meant to be a complete event listing as this would be all but impossible. The aim of this breakdown is to give any future programmer a helping hand understanding the sequence of events that leads from the initial pressing of the start button, to the game over screen at the end. The events and actions are listed by Handler name, Scriptname and number and then a description of the event that takes place.


Handler on mouseup me Scriptname b_ChangeColour Script No. 10

This is a behavior script attached to the start button in the top center of the stage. When clicked this script calls the handler gChangeColour and sets gSubmitter to true. gStartButton is set to 1 so as to prevent the start button being active throughout the game even though it fades out in the next script.

Handler on gChangeColour me Scriptname m_initialise Script No. 1

This handler is contained within a movie script. It starts off by randomly picking a number between one and six. It then uses the getAt command to retrieve a colour held within a predefined linear list, gColourList, as a string. This string is then entered at the start of the main game list, gSimonList, using the addAt command and the variable gCount is given a value relative to the number of items currently in the gSimonList.
Just before gAnimation is changed to 1 the cube is returned to its correct position of 0, 0, 0 on the x, y and z axis respectively. This is done to ensure that when the animation is started the cube is facing the camera and has stopped moving.
gAnimation is set to 1.

Handler on exitFrame Scriptname exitFrame Script No. 3

Due to the fact that all actions in this script are within an exitFrame handler, they are constantly checking for events to take place. If gAnimation equals 1 and the gCounter does not equal 30, which is the amount of time each animation takes to be performed, gCounter is set to increment by 1 every frame. The next line checks that gCounter is between 0 and 30 and that gCount is greater than 0, meaning there is at least 1 item in gSimonList. If these requirements are met the command getAt is used to retrieve an item in the list at the position equal to the number of items in the list (gCount), i.e. the last one. The value returned by this command is held in getItem as a string such as “Orange” or “Blue”. If no value is returned the cube is set to return to its previous bobbing state and await user input, i.e. the submission of a sequence.
The score counter is activated here and is based around the number of items in gSimonList, giving a fair representation as to how the player is performing.
The next event to take place is, again, due to the fact that this script is within an exitframe. One of the initial 36 if statements is triggered as soon as the variable, getItem is given a value. For this example lets say it is Orange. When the statement is run, it check to see what colour has been selected, Orange in this case, but also at what face of the cube is the camera facing. If the co-ordinates equal 0, 0, 300 along the x, y and z axis it means the camera is currently facing Blue. This sets gBlueToOrange to equal 1. This will now call the handler, rotateOrangeFromBlue. It will continue to call this handler every frame until the variable gBlueToOrange equals 0 again as it did at the beginning of the movie.

Handler on rotateOrangeFromBlue Scriptname m_animation Script No. 2

Firstly this handler calls another handler gSound1 which plays the sound member “CameraSoundSweep1”. This is the robotic sound of the camera rotating around the cube.
The next statement rotates the camera along the x and y axis until it is in the position 0, -300, 0 along the x, y, z axis at a speed equal to the value of gSpeed. In truth, what actually happens is that the camera does not rotate at all. It actually moves in a straight, diagonal line whilst always ‘targeting’ the cube so as to constantly keep pointing towards it. This gives the impression of rotation.
When the camera position is at -260 degrees on the y axis, the handler gSound3 is called. This is the sound that is meant to signify the camera locking into place. It is triggered at 40 degrees before the final camera position as this is the ideal point in order to syncronise the sound with the event.
As soon as the camera position reaches its target location of 0, -300, 0 on the x, y, z axis, gBlueToOrange is set back to zero. This causes the statement on the exitFrame to cease calling the rotateOrangeFromBlue handler and the animation stops.
gCount is set to equal gCount minus 1 so that for the next event, the item in gSimonList that is called on the exitFrame and stored in the variable getItem, will be the one before the colour just animated. If there are items left in the list that haven’t yet been animated, the process is repeated until all animations have taken place. Once the list has been exhausted of items, the handler gRotateModel is called and gSubmitted is set to equal 1. This will simply enable the user to input their answer. In effect it re-activates the buttons.

Handler on gRotateModel Scriptname m_animation Script No. 2

The first part of this script simply sets the cube to rotate along the x and z axis anticlockwise to the value of gSpeed.
The if statement in the second half of this script, uses a simple switch, gBobin, to make the cube bob up and down. When the position of the cube is less than +5 and gBobin is equal to 1, the cube moves up. As soon as the position equals 5 the switch gBobin changes to 0 and because the requirements of the second if statement are met the cube moves down instead. When the cube hits -5 the switch is reversed again and the process is repeated indefinitely.


Handler USER ACTION Scriptname n/a Script No. n/a

The user clicks on one of the six buttons to give their response. For this example the button clicked will be orange.

Handler on mouseUp me Scriptname b_buttonOrange Script No. 4

As the user clicks on one of the six buttons, the handler gClicked is sent the value of that button, the string “Orange”, as an argument. It is in this script that the aforementioned gSubmitter and gSubmitted variables come in to play. Providing both of these are true or 1 the argument is sent.

Handler on gClicked Scriptname m_initialise Script No. 1

When the handler gClicked receives the argument in the form of a string from one of the buttons, it populates the list, gUserList. This keeps happening until the number of items in gUserList equals the number of items in gSimonList. Once they are equal, the handler gSubmit is called.

Handler on gSubmit Scriptname m_initialise Script No. 1

On gSubmit, the if statement checks to see if the contents of gUserList match exactly, the contents of gSimonList. If they do, the items in gUserList are deleted and gCounter is set back to 0. The number of items in gSimonList is assigned to the variable gCount and the handler gChangeColour is called which once again adds another colour to the list and as such the sequence of colours gets longer.
If the two lists don’t match exactly, the music stops, the “GameOver” audio is triggered the playback head is sent to the game over screen and the handler gameOver is called.

Handler on gameOver Scriptname m_showScore Script No. 7

This script is here simply for the benefit of the score table. It takes gScore, providing it is more than 0, and divides it by 13. It then divides the gScoreCounter by 60 to return the time in seconds that you have been playing. This result is taken away from the result of the previous division to result in your final gScore. The reason for this equation is that firstly we didn’t want it to be too obvious how the scoring worked. Secondly we didn’t want people who weren’t too good at it get 0 all the time and thirdly we didn’t want people who were excellent at the game getting thousands of points as this could potentially ruin the score board layout if numbers start scrolling across the textfield.