Users browsing this thread: 1 Guest(s)
The Coder's Resource: SmallBasic
#1
[Image: SmallBasic.png]

"Don't do this Sengir, you're embarrassing yourself..."

Hello all and welcome to the Coder's Resource: SmallBasic. Every tutorial series prior to this it seems like I've expected a small amount of understanding how programming works, which was in error on my part. That's why I chose SmallBasic as the language for this series; it's a very easy language to learn programming logic with before you move up. This will hopefully be a weekly thing as time permits, posted every Friday.

You can ask questions if you need help! SmallBasic has an easy code-sharing system, just press publish and it will give you a code. Putting that code in the import window will, uh, import the project.

I'll be using this code-sharing method in later tutorials so you can import the lesson's code.

[Image: 001.png]

Key Words and Concepts
Object
Method
Parameter

Downloads
SmallBasic Installer

This will be a very short lesson, mostly just describing how things work.

Upon starting up SmallBasic (from now on shortened to "SB") you will be greeted with a friendly-looking user interface and an empty, welcoming notepad. If you start to type you'll notice that SB gives you a list of objects and methods.

Let's type this out:
Code:
TextWindow.WriteLine("Hello World")

It should be pretty self-explanatory, but let's go over it anyways:

TextWindow is an object that references the Console. As an object it can hold variables (fields for numbers , text or more), methods and even other objects.

One of TextWindow's methods is called WriteLine. Methods are like a list of actions to take. You can define a method in code and later go through those actions. It's very helpful if you have some specific code you would like to run over and over throughout your app.

The parentheses after WriteLine let the computer know that you are running the method, not just referencing it. The text (or in programming terms, "string") in between the parentheses is a parameter. A lot of methods have parameters, they are used to give variables to the method. In this case we are sending (or "passing") "Hello World" to the method, otherwise the compiler wouldn't know what to do and crash the application.


Now that we know how that code works, let's try this:
Code:
sHelloWorld = "Hello World"
TextWindow.WriteLine(sHelloWorld)

Here we are creating a variable that holds our "Hello World" string and passing that as a parameter. Why would we want to do that instead of just passing the string itself? Well, take a look at this:
Code:
sHelloWorld = "Hello World"
TextWindow.WriteLine(sHelloWorld)
sHelloWorld = Text.ConvertToUpperCase(sHelloWorld)
TextWindow.WriteLine(sHelloWorld)

Now you're probably wondering what's going on in line 3. Methods can return certain values after being run (or in programming terms, "called"), which is really helpful. In this case we are giving the ConvertToUpperCase method our variable and it is returning a new value that we are putting back into the variable. It should be noted that whenever a single equal sign is being used to set something the methods on the right side of the equal sign always run first, so using sHelloWorld to set sHelloWorld isn't a paradox!

Now we have one more thing before this lesson is over:
Code:
TextWindow.WriteLine("Hello, what's your name?")
sName = TextWindow.Read()
sName = Text.Append("Hello, ",sName)
TextWindow.WriteLine(sName)

Here we're setting sName in a different way: we're checking what the user has typed. The TextWindow.Read method is an interesting one, it pauses the code until the player presses Enter. So now when a user enters their name the app take the string from the TextWindow, appends a greeting before it and writes it back out to the TextWindow.



That's all for this week, I'm afraid. Next week we shall step into The World of If and Else: Beginning Logic and make some neat applications that actually do things.

For this week's "homework" I'd like to see you guy experiment with the TextWindow and post your creations' sharing codes here
#2
I did it, yay

I guess I'll be looking forward to next time too...
I don't really have an interest in coding, but why not

I hope others follow along too
[Image: sxv5uJR.gif]
Thanked by: Sengir, recme, Zac, Iceman404
#3
I will be following the thread, I need to brush up on my coding.
Thanked by: Sengir
#4
No semicolons on the end of lines.

What sort of sick language is this.


Seriously though, this looks cool. I mean I already code but this is really handy and easy for people who want to learn general programming conventions and logic before moving on to more advanced languages, with semicolons and stuff.
You may have a fresh start any moment you choose, for this thing that we call "failure" is not the falling down, but the staying down. -Mary Pickford
Thanked by: Korby, Sengir
#5
(08-11-2012, 05:08 AM)puggsoy Wrote: No semicolons on the end of lines.

What sort of sick language is this.


Seriously though, this looks cool. I mean I already code but this is really handy and easy for people who want to learn general programming conventions and logic before moving on to more advanced languages, with semicolons and stuff.

I've a long-term plan for this whole thing, eventually ending with XNA. And while this week was a bit lacking in content I've already begun working on the next lesson for Friday
Thanked by: puggsoy, Guy
#6
I'll try this when I'm at home, but can I make a suggestion? While the text explains the actions very well, could you use visual metaphors or graphs to aid explanation? I think it'll make the learning much more enjoyable if you do so; I'll try making an example if I have some time.
Spriter Gors】【Bandcamp】【Twitter】【YouTube】【Tumblr】【Portifolio
If you like my C+C, please rate me up. It helps me know I'm helping!
[Image: deT1vCJ.png]
Thanked by: Virt, StarSock64, Sengir
#7
I honestly don't know shit about coding,and it's something I don't even wanna learn at all for some personal reasons.
But I'm just dropping by to say that it's really cool of you to take your time and explain things like this to TSR.You're a pretty cool guy.
I agree with Gors btw,I believe images would really help the learning proccess.
[Image: 120117_kick.gif]
Thanked by: Sengir
#8
I'll update with pics and better explanations when I get back from school after this week in the dorms. In the meantime I'm writing up the next lesson (albeit without SmallBasic even installed)
Thanked by: Garamonde
#9
practicing at work~
http://smallbasic.com/smallbasic.com/program/?XZM675

http://smallbasic.com/program/?HLZ176 <welp, the spaces got deleted, which messed up my ASCII art. oh well

http://smallbasic.com/program/?PJN900 oh my god

http://smallbasic.com/program/?VLN015

http://smallbasic.com/program/?KTX659
Spriter Gors】【Bandcamp】【Twitter】【YouTube】【Tumblr】【Portifolio
If you like my C+C, please rate me up. It helps me know I'm helping!
[Image: deT1vCJ.png]
#10
Wh-why in the world does that program call you a liar...? That's really freaky and makes no sense... Shocked
[Image: sweet-capn-cakes-deltarune.gif]
Thanked by:
#11
Quote:Milk?
I'm ok with this.
Oh okay.

Code:
Text.ConvertToLowerCase(x)
If x = "milk" Then



Sorry to interrupt and no hard feelings okay

but I do use shift a lot
Thanked by: Gors
#12
it's ok, I'm not used to Writing Like A Loser








(jk ilu Heart)
Spriter Gors】【Bandcamp】【Twitter】【YouTube】【Tumblr】【Portifolio
If you like my C+C, please rate me up. It helps me know I'm helping!
[Image: deT1vCJ.png]
Thanked by: Iceman404
#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
#14
http://smallbasic.com/program/?KGQ218

whipped this up at work, might have bugs and stuff but I couldn't test it often OTL

COLLECT 1000 BOTTLE CAPS TO WIN
Spriter Gors】【Bandcamp】【Twitter】【YouTube】【Tumblr】【Portifolio
If you like my C+C, please rate me up. It helps me know I'm helping!
[Image: deT1vCJ.png]
Thanked by: Previous, Guy, Sengir, Hoeloe, Zadaben
#15
Quote:Do you want to take a [walk], [protect] the collection or [sleep]? >sleep
That piece of shit GORS stole 10 bottle caps from your collection!
Cry

Quote:Steve... Congratulations for protecting the bottle caps... As a reward, I'll present you a thousand bottle caps and kill GORS !

Suddenly, 1,000 bottle caps rained from the sky. You now have a shitton of bottle caps!

In the meantime, GORS died from a heart attack.
Genki ^_^


Serves you right, you petty thief Very Sad
Thanked by: Gors, Guy, Hoeloe, Garamonde, Zadaben


Forum Jump: