Users browsing this thread: 1 Guest(s)
The Coder's Resource: SmallBasic
#13
Sorry for being so late!

[Image: 002.png]

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
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 Smile


Messages In This Thread
The Coder's Resource: SmallBasic - by Sengir - 08-10-2012, 04:39 PM
RE: The Coder's Resource: SmallBasic - by Britt - 08-10-2012, 07:02 PM
RE: The Coder's Resource: SmallBasic - by puggsoy - 08-11-2012, 05:08 AM
RE: The Coder's Resource: SmallBasic - by Sengir - 08-11-2012, 04:16 PM
RE: The Coder's Resource: SmallBasic - by Gors - 08-13-2012, 08:05 AM
RE: The Coder's Resource: SmallBasic - by Shinbs - 08-13-2012, 08:17 AM
RE: The Coder's Resource: SmallBasic - by Sengir - 08-13-2012, 05:22 PM
RE: The Coder's Resource: SmallBasic - by Gors - 08-14-2012, 09:49 AM
RE: The Coder's Resource: SmallBasic - by Gors - 08-14-2012, 01:31 PM
RE: The Coder's Resource: SmallBasic - by Sengir - 08-21-2012, 07:44 PM
RE: The Coder's Resource: SmallBasic - by Gors - 08-28-2012, 02:11 PM
RE: The Coder's Resource: SmallBasic - by Gors - 08-28-2012, 08:32 PM
RE: The Coder's Resource: SmallBasic - by Hoeloe - 08-30-2012, 02:09 PM
RE: The Coder's Resource: SmallBasic - by Gors - 08-30-2012, 02:44 PM
RE: The Coder's Resource: SmallBasic - by Gors - 08-30-2012, 03:45 PM
RE: The Coder's Resource: SmallBasic - by Zadaben - 08-30-2012, 05:26 PM
RE: The Coder's Resource: SmallBasic - by Kami - 08-30-2012, 05:36 PM
RE: The Coder's Resource: SmallBasic - by Guy - 08-30-2012, 07:40 PM
RE: The Coder's Resource: SmallBasic - by Gors - 09-18-2012, 02:45 PM
RE: The Coder's Resource: SmallBasic - by Kami - 09-18-2012, 03:15 PM
RE: The Coder's Resource: SmallBasic - by Sengir - 09-18-2012, 04:33 PM

Forum Jump: