Tuesday, 3 September 2013

Project ‘Coding Oledium’ – Part 7

In the last part of Coding Oledium we got down to building out the main methods file and add a Loop to create a flow for the game over the main player actions. However, there was a slight issue in that we had to kill the player in order to quit, assuming the player didn't just quit cleanly using the Quit command.

In this version the Loop is fixed so that the game will end if the player Quits or dies. We haven't yet implemented the Attacking, swipe for swipe by the player and the monster, but we can pretend to have had a fight at this point which is fine. One technique when coding is of course to implement something at a simple level, then go back and elaborate it. A little bit like building something to a substantial degree, then polishing and prettifying it afterwards. We know the code we add won't break the main body of the application / game later - or at least shouldn't do so, but that's another issue related to 'scope', which we can cover at some other point.

The main piece of work in Part 7 is to get the ad_hero_generator.vbs file progressed enough to start writing to an external file, the character-sheet.txt file to be specific. This is what we want producing when the player first starts the game and at the end when they quit. Later on we can look at reading the file contents in so the user doesn't have to start from scratch every time. For now though we just need to create and write the file.


In the main ad_index.vbs file we create a new File System Object, which we use to read in the contents of the other game files. It's the same thing we need to do for creating the Character Sheet and writing to it.

If you remember from this link about the OpenTextFile method (http://msdn.microsoft.com/en-us/library/314cz14s(v=vs.84).aspx) we had a choice to set whether we want to read, write or append to the end. The value of 2 is what we want for writing. Here's two key lines we'll add in the CharacterSheetGeneration function:
oOutputFile = "./Character-Sheet.txt"
and also;
Set sTextOutput = oFSO1.OpenTextFile(oOutputFile, 2, True)

The use of True is to indicate that the file should be created if it doesn't already exist. This is then followed by lines to add text to the Character Sheet, for example:

 sTextOutput.writeline sHeroName

With this we're then able to call the ad_hero_generator.vbs file and call the function at the start of the game. Have a look at the video to see the extra elements around this approach.

Going ahead we still need to create Arrays and Classes. However, Classes in VBScript seem to be a little bit 'interesting' and a somewhat new addition from what I've read. I may do a separate study of them just to be sure they're understood.