text
stringlengths
0
897
This time, before you exit the editor, try hitting the Save button (second button from the left), or pressing Control-S. Because this program has not been saved before, the editor will pop up a little box asking you where to save it.
{width:"50%"}
![Code editor Save dialog.](SaveDialog.png)
Type `keyboardDash` (with or without a `.ms` suffix), and hit Return/Enter or click Save. The program will be saved, and the program path appears in the toolbar at the top of the screen. Now exit with Control-W (or click the Close button).
First, if you like, use the `dir` and `view` commands to verify that your program really was saved to disk. So now you know *two* ways of saving a program: using the `save` command in the REPL, or using the Save button in the editor. Both do the same thing.
Finally, run your program, and alternately press the comma and period keys as fast as you can to race to the finish line. How fast can you do it? (My record is about 2.25 seconds.) Find some other people and challenge them to a race!
## More Key Methods
Sometimes you want to get a key from the user, only if they've pressed one; if they haven't, then you want to continue on with the program. There are two ways to do that. The first is to call `key.get` only if `key.available` is true. Or if you don't care what the key is, you can call `key.clear` to clear it out.
{caption:"Reaction test."}
```miniscript
print "Press any key to stop the count."
print "See if you can stop on exactly 50! Get ready..."
wait
print "GO!"
for i in range(1, 100)
if key.available then break
print i
wait 0.05
end for
key.clear
diff = abs(i - 50)
print "You stopped " + diff + " away from 50."
if diff < 5 then print "Amazing!"
```
Save this program as "reactionTest", then try it a few times. Notice how we're checking `key.available` within the loop, and when one is available (i.e. the user has pressed a key), we `break` out of the loop. Then we use `key.clear` to clear out the keyboard buffer. In fact, try taking that out, and see what happen...
{i:"keyboard buffer"}
The second way to detect key presses without waiting for them is to use `key.pressed`. This function is quite different from the other key functions we've looked at so far. The `key.available`, `key.get`, and `key.clear` functions all deal with the keyboard *buffer*, the set of printable characters (plus a few editin...
The `key.pressed` function is different. It reports on the status (pressed or not pressed) of individual, physical keys on the keyboard. That includes the left and right shift keys, the alt keys, the function keys, and so on. It also includes the printable keys like letters and numbers, but not the shifted version o...
To illustrate, here's a program that counts up only while the left Shift key is held.
{caption:"Demonstration of key.pressed."}
```miniscript
print "Hold left shift to count up. Press Esc to quit."
x = 0
while not key.pressed("escape")
if key.pressed("left shift") then
x = x + 1
print x
end if
end while
key.clear
```
We're actually using `key.pressed` twice in this program: once to break out of the infinite loop with the Escape key, and once to increment the count whenever the left shift key is held. Notice how fast that count goes up!
If you're interested in making games, or even interactive simulations, you'll probably be using `key.pressed` a lot. It lets you detect the keys as soon as they're pressed, for as long as they're pressed. It can even detect multiple keys at once, which is handy if you're using them to control a character running and ...
What are these magic strings that you use with `key.pressed` to specify the key? Well, you'll find them on the Mini Micro Cheat Sheet, as well as in the `key.keyNames` list (although that list is so long, it won't fit on one screen!). But you should also be aware of the `inputCheck` demo in the `/sys/demo` directory.
{i:"`/sys/demo`,`inputCheck`"}
```terminal
]cd "/sys/demo"
]load "inputCheck"
]run
```
When you run this, mash any keys or combinations of keys on your keyboard or game controller, and the corresponding key or axis names will appear on the screen.
We haven't covered axes yet, but it's not too hard: `key.axis` returns a value from -1 to 1 for analog axes, like joystick inputs. Mini Micro also gives you a Horizontal and a Vertical axis usable with the arrow keys and the WASD keys. You can tell axis names from key names because axis names are capitalized, while k...
## More on Files
You just changed to the `/sys/demo` directory. How do you get back to your files? The same question would apply after you quit Mini Micro and relaunch it again later. You'll soon get comfortable navigating your files, but for now just do:
```terminal
]cd
]cd "learnToCode"
```
and then follow this with a `dir` to make sure you see your saved files. Remember that the first `cd` above takes you to `/usr/`, your home directory on the user disk. But you could have done it instead in a one-liner:
```terminal
]cd "/usr/learnToCode"
```
Because the path in this case starts with a slash, it is an *absolute* path, and will work no matter where you are. Without an initial slash, it's a *relative* path, and starts in your current directory.
## Minidisk Files and Folders
For the last topic of this chapter, we're going to dig a little more into how your files are actually stored in the host operating system. This section applies to desktop computers — Windows, Mac, and Linux. If you're running Mini Micro on a tablet or phone, you can safely skip to the end.
{i:"disk slot;minidisk file;disk file"}
Mini Micro has two ways of storing its files. First is a "minidisk file", or just a "disk file" within the context of Mini Micro. Click on the top disk slot below the screen. A menu should pop up that looks like this:
{width:"70%"}
![Disk slot menu.](DiskSlotMenu.png)
{i:"`/usr`"}