Yesterday we went over how to download Mini Micro and get it running. Today let's start learning how to use it!
Day 2 Goal: Learn Enough Commands to Run the Demos!
Programming a computer is like doing magic. When Hermione wants to levitate a feather, she has to say the magic words — wingardium leviosa — in exactly the right way, and then indicate what to lift and how much using her wand.
Coding is similar, but instead of spells, we invoke commands (or "functions") by typing them. But you have to type them exactly right — with correct capitalization, punctuation, and spelling — or they won't work.
Today we're going to learn the following commands:
- pwd (print working directory): shows "where" in the file system you are
- cd (change directory): moves you to a different place in the file system
- dir (directory): list all the files in the current working directory
- load: loads a program into memory
- run: runs the currently loaded program
- edit: views (and allows you to change) the current program
So what's this about a file system? Well, Mini Micro, like any computer, has disks that contain files and folders. You're probably used to navigating files and folders using the Finder (on Mac) or File Explorer (Windows). But Mini Micro is a command-line system, like Unix or DOS. So you navigate files and folders using the pwd
and cd
commands.
Start by entering: pwd
This prints the current working directory, which initially is /usr/
. That means you're on the user disk, which is where all your own files will be stored. But there's nothing interesting there yet. We want to move over to the system disk, and in particular, to the "demo" folder, which is where all the fun stuff is. So:
Enter: cd "/sys/demo"
Be sure to type this exactly as shown, with the quotation marks and slashes. Mini Micro does this command silently, without printing any response. How do you know it worked? Well, let's check:
Again enter: pwd
Now it should print /sys/demo
, showing that you have successfully changed the working directory to the demo
folder on the sys
disk.
Now enter: dir
This command lists all the files in the current directory. You should see a bunch here, from "acey-deucey.ms" to "typing.ms". The ".ms" on the end stands for "MiniScript" — these are MiniScript programs!
Enter: load "acey-deucey"
This loads the acey-deucey.ms program into memory. Notice that you don't have to include ".ms" in the command; load
is smart enough to add that for you if you leave it off, as we did here. If you entered it correctly, you should see something like
121 lines loaded from acey-deucey.ms
This is telling you that the program was loaded, and how long it is. Now let's have some fun!
run
This magic word runs the current program. In this case, that's acey-deucey, which you just loaded. This is a little card/betting game, where you bet that a third card will fall between the first two. You start out with $100. Can you get up to $500? It's not easy!
When you've played enough, enter Q to quit (or, the game will quit automatically if you run out of money).
Now for the real magic. You've run programs before; we all use programs all day. But have you ever changed a program? Let's do that now.
- Enter:
edit
This opens the code editor with the current program. It'll look something like this:
There is a lot of stuff here you won't understand yet. That's OK! You can scroll through (using your scroll wheel or track pad, or by dragging the scrollbar on the right) and sort of get the big picture. Let's just make one small change for today. Find line 24, where it says
money = 100
This sets how much money you start with. Let's cheat a bit! Change that line to
money = 490
Now press the Save & Exit button, and then enter run
again. The game starts over. But this time, after your initial $2 ante, you have $488 left to spend! You changed the program! (I bet you can get over $500 now!)
From here, there are lots of things you could try. Edit the program again, and see what else you can change. (Don't worry about messing anything up — your changes at this point are not permanent.) Or go back to step 4 (dir
), then load and run a different program. The current version (0.2) of Mini Micro has 14 demos here, every one quite different. Work your way through them all, and be sure to at least look at the source code, and maybe even try to change something. Remember, it's OK if you don't understand most of what you see, or if most of your experiments don't work — in a few weeks, you'll understand it all!
Click here for Day 3!