Lesson 29: Versions
Backing up your files is very important. Always backup files on a different device (Flash drive, server, etc.) so that if something happens to the device you are working on (hard drive crashes, the device is stolen, etc.), then you have not lost all of your work, and all of the hours you put into developing your game.
Versioning is not quite the same as backing up files. With versioning, you often are saving multiple versions of the same game.
Imagine, you have spent hours upon hours working on the most awesome game ever. Then you modify the code to get a new feature working and BLAM, the game stops working altogether. Worse yet, you can't figure out how to fix the code you added or how to undo what you did.
If you were using versions, then you could always go back to the last working version of your code.
1. Save all of your project files and close them. Then rename the folder that has your project files to include the version number.
2. Make an exact copy of the file in the same location and then rename the folder appropriately.
Now if you make any disasterous mistakes to Version 2, you can always go back to Version 1. As a novice programmer, you should create a new version every time you make significant progress.
Often, you may prefer to use dates instead of a version number to provide additional information. For instance, if you started a version of the game on Jan 20, 2014, You might name the foler "IQ_01_20", or "IQ_2014_01_20" if the project will span multiple years. Following the order of year, month, day and using 0 in front of single digit days and months will ensure that the versions show up in order (if sorted alphabetically).
3. Open the files from the new folder to continue working. Make sure that you are also viewing the new version of index.html file in the browser.
4. Modify the respond() function to call newProblem().
Now newProblem() is called when the page loads, and also every time an answer button is clicked.
5. Modify newProblem() to display the problem with the index that is equal to currentProblem.
Because currentProblem starts out as 0 and then is immediately increased to 1, this code starts with the second problem (index of 1) instead of the first problem (index of 0).
And when currentProblem = 10, the Array elements with index of 10 do not exist. This is because you only assigned values for indexes 0 to 9.
One solution to this problem would be to move currentProblem++ to the bottom of newProblem() so that the value is not incremented until the problem is displayed. This would then show the correct problem, but the problem number would be wrong. You could then add one to the value being displayed for the problem number.
An alternative solution would be to simply subtract 1 from currentProblem for the index values. This makes sense since the index value of each problem is 1 less than the problem number. For instance, problem 1 has an index value 0f 0, and problem 10 has an index value of 9.
6. Subtract 1 from currentProblem to determine the correct index value of the current problem.
Now, the first problem should appear when the Start button is pressed, and each time an answer is selected a new problem should appear.
7. Modify newProblem() to ensure that only 10 problems are shown.
8. This was good progress! Save you files, close them, and then duplicate the most recent version to create a new version. And that is how versioning is done!