Section 2 – Basic Counter Program
This tutorial covers:
button press events
increasing local variables
The first program we will make is very simple but will show us some of
the basic building blocks we need to get our heads around. We will
create a simple counter program, the program will hold a number that we
can increment or decrement using the left and right button, when the
number gets over 5 we will make the program say a message.
we need to create a project. Use to lt key to go to the top menu where
we can scroll through File, Edit and Run using the arrow keys. Press
down on the File option and select New Project. This will then ask you
if you are sure, press enter on the "Yes" option.
Tab until you
reach the tree view, where you can select a location on your computer to
save your project.
Then tab until you are asked for a file name.
Give your project a name, such as "Counter" then tab to the save button
and hit enter.
This will create a folder and the project file
will be inside it, this is needed because all of the game audio must be
kept within the same folder as the project file, we will be deal more
with audio in the next tutorial.
Now we have a new project, tab until we have the game object tree
selected, this holds a list of all the game objects we create and can
store them in folders for easier organisation. There will already be one
folder in the list already which will be the root folder called “game
objects” and should already be the focused item when the tree is
selected since it is the only item,
if not tab through the controls until “tree view” is selected, which is
the game object tree. When the game object tree is selected press
shift+F10 to bring the the game object tree drop down menu. Use the up
and down arrows to cycle through the menu options and select “add game
This will open another windows that we can use to create our new game
object. The first field highlighted for us to edit in the window is the
objects name. Enter a name foe the object of your choice, such as
“controller”. Tab through the rest of the game objects properties until
you get to the variables button. Once the variables button is selected
This will open a new window that lists all local variables associated
with this object. A local variable is a number that is stored in the
game object itself. We can give the variable a name for reference and
then assign it with a value that can be altered or check on through out
the game as it is played as long as the object exists. Global variables
are a bit different, they are assigned to the game itself so can never
be destroyed. When we open the variables window for our game object the
first thing that will be selected is the list of variables which will be
empty. Tab until you find the “add” button and hit enter.
This will open a new window for us to enter our new variable name and
value. The first text field highlighted will be the name. Enter a
suitable name for our counter variable, such as “counter”, and then tab
to the value text field and enter 0, so the variable will start at 0
when this game object is created during runtime.
Tab to the submit button and hit enter, now we go back to the variable
editor window for our game object and can see the new variable we
created is now in the game objects local variable list. When tabbed onto
the list use the up and down arrow keys to highlight a available and
then tab away from the list to the edit or remove buttons to edit or
remove the highlighted variable. Use the “cancel” button to leave the
variable editor and return to the “New Game Object” window, where we can
continue creating our game object.
Now we can tab through the New Game Object window until we reach the
event combo box list. Use the arrow keys until we find the creation
event, which should already be the one selected since it is at the top
of the list. Once we have verified we have the creation event selected
in the list then we can tab to the add action button to add actions to
Since our plan is to use the left and right press events to play text to
speech, we will first need to buffer the text to speech into one of the
TTS channels before we can tell the press events to play one
of the Channels.
Tab to the add action button and hit enter to bring up the “new action”
The first options highlighted is a list of radio buttons which decide
what object the action applies to,which means it is possible for one
game object to make other game objects perform actions, for our example
however we just need to ensure the “Self” option is selected then tab to
the next part. The next combo box is a filter, which will only show us
relevant actions, for simplicity lets leave this how it is and tab past
it. The next combo box is the actual action we want to use.
We need to load a TTS message into TTS Channel 0, which means we need to
scroll down using the arrow keys until we find “Set TTS Channel”. This
will make 2 more text fields appear that we can then tab to. The first
is the actual message we want to store and the next is the TTS channel
we want to store it in, which in our case is 0, and the message can be
anything, for example it could simply say “our variable is now above 5”.
Once we have done this we can tab to the submit button and create the
If you want the TTS to say the value of a global variable (doesn't work
for local variables) input the global variables name and it will then
render the variables value in the TTS channel.
Now we are back to the new game object window we can add the actions
into the left pressed event to subtract our local variable, and then add
actions to the right pressed event to increase our local variable.
Tab back to the event combo box and find left pressed. Once this is
selected we can again tab to and hit enter on the “add action” button.
Again ensure the “Self” radio button is selected in the first section
and then go to the action list and select “subtract local variables”.
The next text field you will tab to is called “variable” which is where
you enter the name of the variable you want to alter. I called mine
“counter” so I would enter that into the text field. Please remember it
is case sensitive so ensure you write it exactly how you did the the
local variable editor. After entering the name you will tab to the next
option to enter the “value”. This is how much we would like to decrease
the value by. Enter the number 1 and tab to the submit button. This has
now added the subtract local variable action to our left pressed event.
Every button on the Sonus has three events. The press, release and hold
events. Press events are triggered when a button that wasn't pressed
gets pressed, and release is fired when a button that was pressed
becomes unpressed. Hold events are fired while ever the button is down.
Now for the right pressed event. In this event we will increase the
local variable by 1 but also check if the variable is over 5, and if it
is we will say our pre-rendered message we stored in TTS channel 0.
Select the right pressed event like we did for the left pressed event
and add a new action. This time select the “add local variable”, enter
the variables name like we did before and again enter a value of 1 so we
are increasing the variable by 1 every time the right button is pressed.
No we have the variable being increased with every press we must now
check the variable each press to see if it has become greater than 5.
Add a new action (again make sure it is performing the action on itself)
and select “condition begin”. When “condition begin” is select we will
then tab into the “condition settings” next and the first thing to be
selected will be the “Variable” combo box, which will have an “L”
When using the condition begin there are 3 things that need specifying:
the variable we are checking
the variable we are checking it against, know as the check variable
the operator, this specifies if we are checking the variable is
larger,smaller or equal to the check var.
the variable combo box that we will have selected when first tabbing
into the “condition settings” is the variables type. We specify whether
it is a Local variable, a global variable or a constant value. The Col
option is also available but we will explore it in another tutorial.
For now as long as the “L” option is selected we can then tab to the
text field to enter the name of the local variable we want to check.
This is where I will enter “counter”. So far we have specified we want
to check a local variable with the name “counter”.
He next option we tab to is the operator. We want to ensure > is
selected meaning we are checking the “counter” variable is greater than
the check variable that we haven't yet specified.
The possible options for the operator are:
== which check they are equal
>= which checks if the variable is greater or equal
> which checks if the variable is greater
< which checks if the variable is less than
<= which checks if the variable is less or equal to
NOT == which is the last option and checks if the variable is not equal
Lastly we tab to the check variable. Again we must select the variable
type from the combobox first. This time however we do not want to have
the “L” option selected, since we are not checking if the “counter”
variable is greater than another local variable, instead we want to
select the “C” option because we are checking if the “counter” variable
is greater than a constant number of 5. So selected “C” from the drop
down list and then tab to the text field afterwards and enter the number
5. From all the parameters we have now entered into the action we can
tell that the condition will check the local variable “counter” and see
if it is grater than the number 5.
We can now tab to the submit button and add the action to our right
The condition begin action should have been added to the bottom of the
event actions list, if it isn't it can be moved using the move action
buttons with the action highlighted. Any action that is between a
condition begin and a condition end action will not be fired unless the
condition is met.
Now lets add our TTS action after the condition begin. Add a new action
and select the “Play TTS Channel” action. Tab to the TTS Channel text
field to input which channel you want it to play, which is our case is
channel 0 since that is the one we set up on the creation event. Hit
submit and ensure the action is added below the condition begin action.
After ward we must add a condition end action, which does not require
any parameters to be filled in, simple add a new action, select
condition end and click submit.
Our button right press event should now have 4 action that it will fire
in order from top to bottom. First it will increase the local variable
“counter” by 1, then it will check if “counter” is above 5. if it is it
will play our TTS channel 0. Remember a condition begin action only
effect the actions after it and the action before a condition end
action. By using condition begins and condition ends we can segment
which actions we want to fired depending on condition.
We can now submit our new Game Object and it will be added to our game
object tree. Tab to the tree and select the new object with the arrow
keys. When an object in the tree is highlighted all of its properties
are accessible by tabbing away from the tree, so don't worry about
making a mistake, all game object are editable. The last thing that must
be done is to assign an Init Object. This tells the sonus which is the
first game object that needs to be created during runtime. Select our
new game object in the tree and use Shift + F10 to bring up a drop down
menu and select “Set As Init Object”. This will now make our new object
the initial loaded object.
You can now test the game by using the “run” tool in the G D E. We can
access this by going to the menu strip at the top of the program using
the “alt” key on our keyboard. This will take us to the file list where
we can create a new project, save or load one. Press the right arrow key
to go to the edit list where we can look at global variables, check what
our init object is set to or set our debug save directory. All of these
will be covered in greater details in future tutorials. Press right one
more time and we will select the “run” option. In run mode the G D E
will essentially turn into a Sonus console and play the game in order
for you to test it. When in run mode you can use the W A S and D keys as
Up down left and right, and the 1, 2 ,3,4 and 5 keys act as the other