In part 5 of our multi-part game audio programming series, Brennan shows us how to randomize footstep sounds within a game. We’ve included a list of programming terms used in this video below, to help you follow along.
Array: An array is just one type of data structure, or container. You can think of an array somewhat like a filing cabinet. The array is one drawer in the cabinet that you can put files in. An array can hold data and give you access to different data depending on where in the array you are looking. Notice that the physical filing cabinet cannot change size. You can only fit a certain number of files in it. You can get larger or smaller filing cabinets, but once you have it, that’s how big it will ever be. Arrays are similar. When you declare an array you have to give it a size. While the program is running you cannot change the size of the array. You can add and remove files from it, but you cannot change how many files will fit in it. There are instances where it would be extremely useful to be able to change the size, and you would have to use a different data structure. An array consists of elements. Elements are like folders that hold your information. They are labeled with an index, starting with index 0 being the first folder in your cabinet. You can search for a specific folder and access the information inside of it.
Int: An int, or integer, is a data type that represents a 64 bit number. For the most part you can think of it as a whole number. You want to be careful when deciding if you need to use an int or a float. Ints do not have decimal points, so doing certain kinds of math on them is not possible. You can add and subtract ints together without a problem. But, once you start trying to do multiplication or division, you may have to cast the int as a float is the result would give you a decimal point. Ints are ideal for counting how many things you have, or how many times you have done a certain task.
Raycast: For now, it is sufficient to describe a raycast as a line that is being shot out from one point in the world to another. You can think of it like a laser pointer, but we can control the distance that it extends to. When the raycast hits something, it will give us a bunch of useful information about the object that we hit, such as what material it is made of, how big it is, where it's located, etc.
Switch Statement: A switch is a convenience so that we don’t have to write a bunch of messy if statements. The principle is the same, we are going to do certain things under certain conditions, and completely different things in other conditions. It looks a lot nicer though and is easier to read. Rather than having “if, else if, else if, else”, it would simply read “case 0, case 1, case 2, case 3”. Of course, these cases don’t have to be numbered in this way, so you could have something that looks like “case IAmOnDirt, case IAmOnWater, case IAmOnWood, case IAmOnStone” where the cases are using booleans that you set up to change elsewhere in the code.