Wednesday, 21 August 2013

Project ‘Coding Oledium’ – Part 4 and 5



I thought I’d bring both of these together, parts 4 and 5 of the adventured in scripting Oledium up with VBScript. The main focus of the next two videos is getting some input from the user and deciding how we’ll react to that, what functions will be called based on how we evaluate the input from the user.


YouTube Channel: [WATCH, RATE, SUBSCRIBE]

In VBScript we have the items we’d expect to see in other scripting and coding languages, JavaScript, Ruby, etc. Just they’re obviously in VBScript style; an InputBox to get input from the user, Function to work through a series of commands and come out with a result and Case statements to evaluated an input and decide what to do based on it.

sPlayerAction = Inputbox(“What would you like to do?”)

In our game, we’ll often be asking the player ‘What do you want to do?’, so we’ll set up an InputBox to get that information. Asking them what they want to do of course means we’re defining what valid actions there are. On our Mind Map design we had actions such as; Attack, Flee, Rest, Search and so on. These will need to be Functions, so we’ll add them to the ad_method_lib.vbs file. For now we can declare them, but no implement them.

By declare them we mean just put in place holders, something that shows us it’s there and needs completing later, for example;

Function PlayerAttack()
                MsgBox “Not yet implemented”
End Function

In this way, we can call it and nothing nasty will happen, nothing useful either, but one step at a time. As a design principle it’s easier to build on a framework than try and write perfect and complete code first time!


The next main item to add is a Select statement. In my mind these are just regular Case statements as I’ve used them in other scripting languages and which always feel like If statements to me, but are somewhat different.  Here’s the basic template:

Select Case sPlayerAction
                Case “Attack”
                                Do some stuff
                Case “Flee”
                                Do some other stuff
End Select

With the above in place we have the basic framework ready to build out the functions and start seeing something interesting happen.


YouTube Channel: [WATCH, RATE, SUBSCRIBE]


There is a key next step though. We need to add a way to loop over asking what the player wants to do. Right now you make one choice and the game ends. We need a global If type statement

If sPlayerHealth > 0 Then
                Keep asking them what they want to do
ElseIf sPlayerHealth =< 0 Then
               MsgBox "Oops.. you're a bit dead!"
End If

We’ll implement that in Part 6, then elaborate the functions a little so the fun can begin!

Mark

YouTube Channel: [WATCH, RATE, SUBSCRIBE]



0 comments: