08-21-2012, 07:44 PM
Sorry for being so late!
Key Words and Concepts
Boolean
Conditional
Now that we have an app that takes input, processes it and outputs it to the TextWindow we can move on to the next step, figuring out what the player entered.
Last lesson we had a simple app that had you enter your name and greeted you:
Today we'll be adding onto that and start our first game project. It will be an extremely basic game (similar to Hamurabi for those interested) and we'll be working on it for the next few lessons.
So let's start out with some stuff we know how to do already:
"Wait Sengir, we can add append text without using the Text.Append method??"
Yes you can, just use the plus sign and it will connect strings of text together. It's very handy.
The next thing we will do is learn about booleans. A boolean is pretty much a true-or-false logic type. A common use for boolean logic is when checking if something meets a set of requirements. We can say it like this:
"If tSR becomes world-famous then Sengir will sell his mod-stock and cash out"
This is a conditional. We use conditionals all the time in real life, so why not in code? I'll show you how it's done:
It might look a little daunting but it's really easy to understand if you look at it like that sentence earlier. For example, this code:
could be read as
"If the player's choice was to advertise then increase the number of members by 5 and display some text informing the player."
That's much If Statements right there. I'd like to do Else Statements in this lesson but my plans for next lesson make for a better introduction.
It's pretty much just a "If tSR becomes world-famous then Sengir will sell his mod-stock and cash out else he'll continue working for Dazz happily."
EITHER WAY that concludes this week's lesson
Voluntary "homework" is to, uh, make an app that uses commands? Knock yourself out with whatever, I'd just like to see it
Key Words and Concepts
Boolean
Conditional
Now that we have an app that takes input, processes it and outputs it to the TextWindow we can move on to the next step, figuring out what the player entered.
Last lesson we had a simple app that had you enter your name and greeted you:
Code:
TextWindow.WriteLine("Hello, what's your name?")
sName = TextWindow.Read()
sName = Text.Append("Hello, ",sName)
TextWindow.WriteLine(sName)
Today we'll be adding onto that and start our first game project. It will be an extremely basic game (similar to Hamurabi for those interested) and we'll be working on it for the next few lessons.
So let's start out with some stuff we know how to do already:
Code:
iYear = 2006
iMonth = 1
iActiveMembers = 20
TextWindow.WriteLine("Hey Dazz, you just became the new Head Admin for tSR!")
TextWindow.WriteLine("Here are some monthly tSRc stats for " + iMonth + " " + iYear + ":")
TextWindow.WriteLine("There are " + iActiveMembers + " active members on the forum")
TextWindow.WriteLine("")
TextWindow.WriteLine("Would you like to [advertise], [update] the mainsite or run a forum [event]?")
sChoice = TextWindow.Read()
"Wait Sengir, we can add append text without using the Text.Append method??"
Yes you can, just use the plus sign and it will connect strings of text together. It's very handy.
The next thing we will do is learn about booleans. A boolean is pretty much a true-or-false logic type. A common use for boolean logic is when checking if something meets a set of requirements. We can say it like this:
"If tSR becomes world-famous then Sengir will sell his mod-stock and cash out"
This is a conditional. We use conditionals all the time in real life, so why not in code? I'll show you how it's done:
Code:
iYear = 2006
iMonth = 1
iActiveMembers = 20
TextWindow.WriteLine("Hey Dazz, you just became the new Head Admin for tSR!")
TextWindow.WriteLine("Here are some monthly tSRc stats for " + iMonth + "/" + iYear + ":")
TextWindow.WriteLine("There are " + iActiveMembers + " active members on the forum")
TextWindow.WriteLine("")
TextWindow.WriteLine("Would you like to [advertise], [update] the mainsite or run a forum [event]?")
sChoice = TextWindow.Read()
sChoice = Text.ConvertToLowerCase(sChoice)
If sChoice = "advertise" Then
iActiveMembers = iActiveMembers + 5
TextWindow.WriteLine("You advertise on Facebook and get 5 new members!")
EndIf
If sChoice = "update" Then
iActiveMembers = iActiveMembers + 2
TextWindow.WriteLine("You make an update to the mainsite and 2 rippers joined!")
EndIf
If sChoice = "event" Then
iActiveMembers = iActiveMembers - 3
TextWindow.WriteLine("You let Sengir start a forum event but it drove 3 people away!")
EndIf
iMonth = iMonth + 1
TextWindow.WriteLine("It is "+ iMonth + "/" + iYear + " and you have " + iActiveMembers + " active members on the forum")
It might look a little daunting but it's really easy to understand if you look at it like that sentence earlier. For example, this code:
Code:
If sChoice = "advertise" Then
iActiveMembers = iActiveMembers + 5
TextWindow.WriteLine("You advertise on Facebook and get 5 new members!")
EndIf
"If the player's choice was to advertise then increase the number of members by 5 and display some text informing the player."
That's much If Statements right there. I'd like to do Else Statements in this lesson but my plans for next lesson make for a better introduction.
It's pretty much just a "If tSR becomes world-famous then Sengir will sell his mod-stock and cash out else he'll continue working for Dazz happily."
EITHER WAY that concludes this week's lesson
Voluntary "homework" is to, uh, make an app that uses commands? Knock yourself out with whatever, I'd just like to see it