In this tutorial, I won't bother you with long-winded introductions. Our goal will be to render the words "Hello world!" on the screen as quickly and succinctly as possible. When you run "Agenoria.exe", the engine by default tries to compile and execute the Lua script located in "Scripts/main.lua". Therefore, we need to create our own plain text file and save it in the "Scripts/" directory of the engine under the name "main.lua". Next time you click on "Agenoria.exe" the script will be executed automatically. The engine can run script files through the command line as well.
Everything is great so far, except that our sprite is completely blank. To write some text on it, we're going to create a new font object. After creating a new font object, we make a call to its "load_system" method. This allows us to use a font that is already installed on the user's operating system. Notice that it is also possible to load True Type fonts directly from file. Once the font has been loaded, we apply it to the sprite's canvas and write the words "Hello world!"
display:create ( "My Window", 800, 600, 32, true ) my_sprite = Sprite ( ) display.viewport:add_child ( my_sprite ) my_font = Font ( ) my_font:load_system ( "Arial", 18 ) my_sprite.canvas:set_font ( my_font ) my_sprite.canvas:write ( "Hello world!" )
That's everything required for our "Hello world!" application. In just 7 lines of code, we have done what would have taken considerably more effort in a C/C++ environment. To be fair, there are certain things that we did not account for. In particular, the "create" and "load_system" functions could have failed due to invalid parameters or possible hardware issues. Ideally, your script should check the return values of those functions and notify the end user of what went wrong.