
上QQ阅读APP看书,第一时间看更新
Time for action — Monkey's Hello World
Here is a version of the famous Hello World script, done in Monkey. You have to start somewhere. You will learn what the starting point of every Monkey app looks like, the Main()
function, and how to print some text to the browser. Ok, let's go!
- Start with a single line comment that describes the app.
'Monkeys Hello World
- Next is the function header for the
Main()
function, the piece of code that will be called at the start of the app. Every function starts with the keywordFunction
, then its name, followed by opening and closing parentheses.Function Main()
- Now, it's time to print the famous text Hello World. For this, Monkey provides the
Print
command. And don't forget to indent the code through the menu or just by pressing the Tab key once.Print ("Hello World")
- Every function needs to be closed. In Monkey, we do this with the
End
command.End
- Now, save your script. The name and folder are not important.
- Build and run the script by clicking on the tilted rocket in the toolbar.
What just happened?
Drum roll please.... tadaaaa! You have coded your first Monkey script and just ran it inside the browser. If everything is correct, you will have seen a plain (white) background and then the text Hello World printed on it.