Thursday, 9 April 2020

Hello World! 3 Ways

What's the first thing you want to learn to do with LiveCode? A "Hello World!" application of course.
This lesson will show you a variety of ways to say "Hello World!" using LiveCode.

Your first stack

Your first stack
First things first, we need a stack so we can start building our application. Go to the File menu and select New Stack - Default Size(1) We now have a stack containing a single card(2)

Edit mode

Edit mode
Selecting Edit Mode allows you to add controls to the stack, select controls and edit scripts and properties of controls.
In the Tools Palette select Edit Mode.

Adding a field to the stack

Adding a field to the stack
To add a field to the stack we can simply drag it onto our stack from the Tools Palette.

Browse mode

Browse mode
Selecting the Browse tool allows you to interact with the stack in non-editing mode. This tool is used for user actions such as clicking buttons and typing in fields.

Displaying Hello World! in the field

Displaying Hello World! in the field
We can then simply type "Hello World!" into the field.

Opening the Message Box

Opening the Message Box
When you start up LiveCode you should see the Message Box(1). If you cannot see it click the Message Box button in the Menubar(2).

Using the Message Box

Using the Message Box
The Message Box is a command line tool that allows you to try out short scripts and test parts of your program. It provides a convenient output window for debugging and can be used for editing and setting properties. It is one of the more useful components in LiveCode when you are starting out and wanting to try out simple scripts.
to output to the Message Box we simply type
put "Hello World!"
and press return to execute the command and there it is, "Hello World!" is displayed in the Message Box.
To put text into a field we can use almost the same script, we just also specify where to put the text
put "Hello World!" into field 1

Using a dialog box

Using a dialog box
Another option is to use a dialog box to display a message. For this all we need to do is use the answer command. Execute this line in the Message Box
answer "Hello World!"

Using a field and a button

Using a field and a button
If we don't want a field that can be edited manually we can use a label field and a button. Again we just drag them onto our stack from the Tools Palette.

Scripting the button

Scripting the button
Now we want to put "Hello World!" into the field when the button is clicked.
1. Go into Edit mode
2. Select the button and open the Script Editor for the button by clicking the Code button in the Menubar
We can reuse our line of LiveCode from earlier, this time we want it to be executed when the button is clicked. Enter this into the code editor:
on mouseUp
   put "Hello World!" into field 1
end mouseUp
Compile the script by clicking Apply(3), go into Run mode(4) and click the button.