C#
Below is an extract from one of the units in my current course, it contains snippets from
creating a procedural program in C#.
If statements
The above screenshot shows the first if statement inside of the
NumberValidation procedure which checks to see if the reference number is
above or equal to 100. If it is then it continues to the next if statement.
In the above screenshot, it shows the second if statement inside of the
NumberValidation procedure which checks to see if the reference number is
below or equal to 1000. If it is then NumValid is set to true.
In the above screenshot, it shows the help section, the if statement
checking whether the user enters ‘Yes’ into the console after it asks if they
want help. If they do not enter ‘Yes’ then the program continues.
The above screenshot shows the If statement, for if the reference
number is valid. If it is not valid it goes back through the main while loop
again. If it is valid it continues onto its following section.
Loops
Loops are a form of Iteration used in programming so that the same code
can be repeated via a parameter. I have used this in my design with a while
loop, the reason I did this is so the program can run repeatedly until the
user wants it to not repeat. Here is an example of iteration I have written in
Pseudocode:
As shown above is a while loop containing the majority of the program, I
have used this while loop so that the program will continue to repeat while
the variable HasNumber is equal to true, if I want the program cycle to end I
set HasNumber to false.
procedures
Procedures are sets of coded instructions that tell a computer how to run a
program or a mathematical calculation. Depending on the programming
language this may be called a subroutine or function. The following
screenshot shows the procedure I used to check if the reference number is
valid. This procedure is also a function as in some programming languages
it is made apparent that functions specifically return values compared to
procedures that do not return values.
Parameter Passing
Below I have shown Parameter Passing, parameter passing means that
variables are passed between different parameters. The purpose of using
parameter passing in this scenario was to have the Int16 reference number
go into the procedure and then have the boolean NumValid come out of the
procedure.
variable declaration
Variable declaration is declaring a variable and its data type. This is useful
because there is a set amount of data set aside for the variable to hold as
well as knowing what type of data that is.
Inside of NumberValidation is one of the variables I declared. NumValid is
the name of this variable and holds whether the reference number is valid or
not, this is then sent back to the main program. This variable is a bool(i.e
boolean).
Inside of the main program is the variable HasNumber. This is the variable I
used for the while loop to repeat the program and I named it HasNumber
because the user would need to repeat the program if they still had a
number to enter into it. This variable is a bool(i.e boolean).
Inside of the main program again is the variable called ReferenceNumber
and logically, it holds the reference number entered by the user. This
variable is an Int16 because it is smaller than Int or Int32 for memory
reasons and suits its purpose of holding a whole number in the range of 100
to 1000.
Unreal (C++)
Below is an extract from one of the units in my current course, it contains snippets from
Unreal blueprints, which is a visual way of displaying C++ in the Unreal Engine.
Blueprints
Inside Unreal, you can use blueprints to make coding much easier and faster, I will
show the blueprints below where I used Iteration, selections, and multiple data types
as well as explain each one.
Iteration
In my game I used iteration many times to loop animations in my word, some of
these examples are the light crystals around the map hovering.
Here is the blueprint I used for all of my iterations which I called repeating
animations, there are 4 different light crystals with repeating animations on the left,
and then on the right there is a branch that only lets the chicken hover animation
play and repeat once a crate has opened, allowing the chicken to hover out of the
crate. I made this iteration by simply adding a delay onto the end of 0 seconds which
feeds back into itself.
Selection
In my game, I mainly used selection when it came to having locks on doors or
requirements for things to happen.
Here is the blueprint for the Gold Door in my level, on the top row you can see
where the variable hotkey is changed to true and that is then linked to an if
statement on the door checking the variable. the true response leads to then opening
the door, this is the most used selection in my game.
The Data Types I Used
In my game, the data types I used were predominantly Boolean, Float and Integer. In
the following three sections, I will explain the main way I used each of them.
Boolean
A boolean is either True or False and is used for things that can be on or off, or in this
case, locked or unlocked.
In these blueprints, you can see the ‘Got Key’ boolean and the ‘Got Copper Key’
boolean. These are set up so that when the player walks their actor into the trigger it
will set the boolean variable of ‘Got Key’ and ‘Got Copper Key’ to true for the
corresponding trigger. Later on in the blueprint; the row below, it checks the boolean
variable and then opens the door if it is true.
Float
Floats are variables that hold decimal numbers, this is different from integers; which
hold whole numbers.
In the screenshots below you can see my use of two float variables, ‘Current Health’
and ‘Max Health’. These variables begin with 100 in both of them and health is
deducted from current health on events like spikes triggered when the player takes
damage. In the lower screenshot, it shows that current and max health is taken and
divided to find the percentage which is then displayed in the health bar on the hud.
String
A string is a data type that holds text
numbers and special characters, it is for
when you want something to be held and
understood by a user, like a message to the
player for example. It is a string of different
characters.
In the screenshot to the right I am
displaying my string variables, this is for
the narrator which describes what happens
in the game. The current event is the event
that is taking place in real-time in my game
as this is set based on what the player is
doing, every time a new event happens this
process occurs where all of the events are
overwritten by the previous, the oldest is removed and the newest is added and then
the process is reset for the next occurrence.
Integer
An integer is a data type that holds whole numbers, you can see that I have a
function here that is taking a float multiplying it by 100, and then changing it to an
integer then to text, and then outputting it. This is because I wanted the health of my
game to display 0 to 100 rather than 0 to 1 and I didn't want health to hold decimals
so I had it be changed to an integer for that sake. A progress bar works with a
number 0 to 1 so I multiplied it by 100 and rounded it.