I recently started looking for ways to write little fun software on the Nintendo DS and came across Micro Lua DS. I heard about Lua before that and I thought that I should give it a try now.
Micro Lua DS is currently in version 2.0 Beta and can be downloaded and installed on the DS like any other homebrew software.
The download bundles API docs, examples and utilities that let’s you test your lua script on your computer before transferring it to the DS.
Here is Micro Lua DS running on the no$gba emulator:
The syntax is straight forward. Here is the Micro Lua DS Hello World
screen.print(SCREEN_DOWN, 0, 0, "hello world")
In this one liner, you are writing ‘Hello world’ on the top left corner of the bottom screen of your DS screen.
Easy! But when you run it, you won’t notice anything…you’re back to the navigation console. This is because the script is run once on 1 frame and then the program just exits.
The Nintendo DS run about 30 frames per second, so unless you’re pretty fast, your eyes did not catch it.
Let’s add some more code to display Hello world until the user press the “Start” button:
while not Keys.held.Start do Controls.read() startDrawing() screen.print(SCREEN_DOWN, 0, 0, "hello world") stopDrawing() end
Here is what’s happening:
while not Keys.held.Start do
, loops until start is pressed
Controls.read()
, reads any input from the DS (buttons or stylus)
- All your drawing instructions must be between
startDrawing()
andstopDrawing()
With screen
, you can draw lines, rectangles, images, gradients, etc. With a canvas
, you have more flexibility to update certain properties like colors and sizes on the fly.
Here is a simple script that let’s you scribble/draw on the screen with the stylus:
canvas = Canvas.new() function main() while not Keys.held.Start do Controls.read() startDrawing() paint() stopDrawing() end cleanup() end function paint() point = Canvas.newPoint(Stylus.X, Stylus.Y, Color.new(31,31,31)) Canvas.add(canvas, point) Canvas.draw(SCREEN_DOWN, canvas, 0, 0) end function cleanup() Canvas.destroy(canvas) canvas = nil end main()
Here is what it looks like on the emulator:
There is also support for creating animations through sprites and scrollable maps.
Sprites are very easy to implement, I got my first sprite to work under 5 minutes. And I never made a sprite before! Quickly, I was able to write a small application that helps the lonely people that can’t pair program to pair with a ninja.
He guarantees to give you his best advice