Time for action – Interacting with the user
Now, we're going to create an application that takes your name as a parameter, greets you, and displays the number of characters in your name.
- Copy the following code in a file named
Main.hx
class Main { public function new() { } public static function main() { var name = neko.Sys.args()[0]; trace("Hello " + name); trace("Your name is " + Std.string(name.length) + " characters long."); } }
- Open a terminal; go to the directory where you saved
Main.hx
and type thehaxe
–main Main
-neko characterCounter.n
command. - Type the command (this is an example with my first name):
neko characterCounter.n Benjamin
- You will see the following output:
Main.hx:12: Hello Benjamin
Main.hx:13: Your name is 8 characters long. ...
Get haXe 2 now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.