Week 4 - Arrays & Filehandling Flashcards
Array
A container that can hold multiple variables at once.
However, these values must all be of the same type (Eg: all strings, all ints)
Multidimensional Arrays
Having an array inside of an array.
Dynamic Arrays
Arrays with no set size, meaning you can continue to add values to them.
What are the pros and cons of dynamic arrays?
+ They are more flexible
+ Values can be decided in the index position or be put on the end
- The performance isn’t as good as hard coded because the computer has to calculate the memory needed constantly.
Rubbish Data
Values that we haven’t assigned but take up storage.
Often the case in Ruby, but will often crash programs in C.
Means to ‘append’.
This means to put the value onto the end of the array.
What number do arrays begin indexing from?
0
How do we find the number of items in an array?
Using .length
What is the best practice sequence with file handling?
Open the file, read/write the file, close the file then continue on with other tasks.
What are the cycle methods used in Gosu?
draw(), update() and button_down(id)
What’s an alternative to button_down() in Gosu?
Using the update() cycle
What does my_array[i] = gets mean?
- It means to assign the value of i to the value in the loop.
- When i=0, it will choose the first element in the array.
- When i=1, it will choose the second element in the array
- More notes on “fill an array” part of the lecture notes
How do you open a file to read/write
a_file = File.new(file_name, “r”)
a_file = File.new(file_name, “w”)