How To Program #2 - Your First Program

Root / Submissions / [.]

All right, no more discussion about computers and state and whatever! Let's get started on our first program. Now remember what I said in the beginning: it's going to take a long time. This means we're going to start small, and you might feel like these programs are useless. But it's important to start from the beginning, because we're going to keep building on what we know in each lesson. It's not just a bunch of disconnected topics; everything in programming is built on something else. The simple commands you learn here will be used in all your programs (or at least most). Next tutorial (part 3)

How to start editing a program

Just like your computer, SmileBASIC works with folders. We're going to make a folder to store everything we do, so first, get to the main menu of SmileBASIC. It should say TOP MENU at the top. Click on Manage Projects/Files at the bottom. This will let you create a folder for our projects. Click Add Project Folder. You can name it whatever you like, just make sure you'll remember which one it is. Go through the dialogs to create the folder, then when it asks you "Do you want to set this project as the active project?", you definitely want to say YES. It's not the end of the world if you don't; setting the active project folder just tells SmileBASIC what to load when we start editing. If you made a mistake, get back to the menu with the Add Project Folder option, then click the Change Active Project option. Look around for the folder you just created and select it. Now that you have a place to work, go back to the TOP MENU. Click Create Programs with SmileBASIC. You should be brought to a black screen with a keyboard. This is our editor, command, and output window! The black window is where you can run simple commands outside your program. This is where we will save, load, and run our programs. Commands are run by typing out the command (just like in a program). You can also test out programming commands here. Furthermore, some output from your program can go here. For now, let's ignore the black screen and look at the touch screen. The buttons on top are shortcuts for different commands you can run on the black screen. If you look at the bottom of the touch screen, there's a DIRECT and an EDIT button. DIRECT will take you back to this black screen, and it's called DIRECT because you can run commands directly and immediately without having to load a program. If you've ever seen those old terminal computers where people had to type everything, this is basically it. EDIT brings up the code editor. You can edit up to 4 files at a time; if you notice, there are 3 small numbered buttons next to the EDIT button. We're only going to work with one file for now, so stick to using the EDIT button only. You can go back to the main menu with the TOP MENU button. If you click the SMILE button, it'll load up a special tool for creating game assets. We're not going to use this, so don't worry about it. If you accidentally press it, you can hold START to exit it. This also works in your own programs. SELECT takes screenshots. If there's a bunch of stuff on the black screen, you can type ACLS (on the black screen, not the editor) and press enter on the keyboard to clear the screen. This is the "clear everything" command. Now, press the EDIT button to bring up the code editor so we can begin! If you're in the editor, you should see a kind of dark gray empty screen with numbers on the bottom.

Simple Output

A SmileBASIC program has many places to output. Right now, we're going to output to the "Console", which is that black screen you keep seeing in DIRECT mode. It's the easiest place to output stuff because it's always there and the commands are simple. Let's output a simple phrase:
PRINT "This is my program!"
We're going to use the PRINT programming command to OUTPUT stuff to the console (the black screen). Phrases that aren't commands need to go within double quotes. We'll talk more about phrases later; for now, just know that you need to surround phrases with double quotes. Remember from the previous tutorial: a program does nothing until you tell the computer to run it. Right now, we've just typed words on a screen. Click DIRECT to get back to the console, then type in:
You can also just press the RUN button on the touchscreen. Now press enter to run the RUN command. This will run your program. You should see:
This is my program!
Cool, we got to see our output! You just told the computer to do something! All that other crap is just informational; the RUN is still there because it was a command you typed, then your output showed up because you ran your program, then SmileBASIC told us everything was OK. The [YOURFOLDER] should say the folder you're working in; it's just there as a friendly reminder. Notice that it didn't output the double quotes. They were only there to tell SmileBASIC that it was a phrase; think of them as start and end markers for phrases. OK, let's try this. Go back to edit mode. You should still see your PRINT statement. Let's add another one:
PRINT "This is my program!"
PRINT "And now I've written more text!"
Press DIRECT mode, type in RUN again, and press enter. Now you should see all the old output plus:
This is my program!
And now I've written more text!
I'm sure you get it at this point. Your program has two commands to output stuff, and when you run it, you see your two outputs. For now, your program will run commands in order from top to bottom. Empty lines don't mean anything, so don't worry about that.


If you notice, we're just typing crap into an editor, then typing RUN, and somehow the system knows that you wanted to run the code in the editor. This is fine, but the code in the editor isn't saved yet, and maybe we want to run a different file. Go back to the console (the black screen) and type SAVE"PROGRAM1". This will save the program in the editor into a file called PROGRAM1. You can verify this by running the command FILES in the console: it will show you all the files in the folder (it should just be the one) and how much space you have. Cool, now we can clear out the editor for a new file. Just like any other text editor, you can load, save, clear out the editor. Type NEW in the console to clear out the editor. Click EDIT and you'll see that the editor is empty again. If you want to load your old file, just type LOAD"PROGRAM1" in the console. Yes, everything here is run with commands that you have to type in. It's part of the old-school experience!


This one was kind of short because it was more of a "How to use SmileBASIC" than anything else (and that's pretty boring). SmileBASIC lets you work with folders and files. You have to pick a folder to work in so the editor has a place to work. The main SmileBASIC system is a Console and an Editor. The Console is a black window which is one of the basic areas of output for a program, as well as a place to run commands directly. The editor lets you write a program. The PRINT command is an output command which outputs to the console. You must RUN the program in order for it to do anything. You can SAVE the file in the editor, clear out the editor with NEW, and LOAD a file back into the editor. Everything is done in the folder you set. Next tutorial (part 3)

As a FYI, you can hold L/R and two buttons will be on the touch screen's top corner: SAVE and LOAD. Can be quicker to use those, I think.

Replying to:Perska
As a FYI, you can hold L/R and two buttons will be on the touch screen's top corner: SAVE and LOAD. Can be quicker to use those, I think.
Cool! These tutorials are already so long though that I don't want to put out any extra information.

this is useful :)

Replying to:swimgaming
this is useful :)
Thank you!


It's not just a bunch of disconnected topics; everything in programming is built on something else.
Great. Like this?

Please update the Informaion about "START" and "SELECT" to the Last Version 3.6.: START (hold on) = exit SELECT = saving sreenshots to SD-card

Replying to:S_DE_Solutions
Please update the Informaion about "START" and "SELECT" to the Last Version 3.6.: START (hold on) = exit SELECT = saving sreenshots to SD-card
Thank you