Hello World

Often the first thing you learn to do in a new language is to display "Hello World", this lesson will show you how to do this in LiveCode.

The mouseUp message

The mouseUp message is sent when the user clicks an object. When the mouseUp message is sent an object it triggers a mouseUp handler.

All message handlers begin with the word on and the name of the message (which is also the handler's name), and all handlers end with the word end and the name of the handler.

An example stack

An example stack

For this example we will create a new main stack from the File Menu.

Adding a button to the stack

Adding a button to the stack

We will the add a button to the stack by dragging it from the Tools Palette(1). Select the button by choosing the edit tool (2) and selecting the button (3).

Then open the Object Inspector from the Object Menu and name the button "Say Hello" (4)

Adding code to the button

Adding code to the button

The mouseUp handler for the button contains only one line

on mouseUp
	answer "Hello World!"
end mouseUp

The answer command displays a dialog box with the text you specify. When you click the button, LiveCode sends a mouseUp message to it. The message triggers the mouseUp handler, which displays a dialog box that says "Hello World!"

Open the script editor for the button by selecting Object Script from the Object menu. Then add the above handler into the button script and try it by clicking the button.

Variations

You can display a message in a variety of ways. For example, in the LiveCode development environment, you can use the Message Box to show a message using the put command.

on mouseUp
	put "Hello World!"
end mouseUp

You can also use the put command to put text into any field object:

on mouseUp
	put "Hello World!" into field "Message"
end mouseUp

 

 

5 Comments

Javier

thanks. i needed this to start. just forgot my turbobasic skills from the 80's.

jack

this is very useful advice as i have just starting using live code thank you for this post

Giovanni

bene, vedo che potrò recuperare le mie conoscenze di Hypercard

well, is similar to Hypercard, it's very nice

Emad Bataineh

I have a question about using LiveCode
Can you share the steps on how to integrate or embed
different media elements ( video, audio and animation clips) in a stack using livecode environment

Heather Laine

Add your comment

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.