Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit 7d2a7f5

Browse files
authored
Merge pull request #1614 from livecode/interactive_tutorial-hello_world
Interactive tutorial hello world
2 parents 329228a + b39962c commit 7d2a7f5

1 file changed

Lines changed: 244 additions & 0 deletions

File tree

  • Toolset/palettes/tutorial/courses/First Run/tutorials/Hello World/lessons
Lines changed: 244 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,244 @@
1+
tutorial "Hello World"
2+
3+
prologue
4+
Welcome to LiveCode, to help you get started this Interactive Tutorial will
5+
show you how to create a simple 'Hello World' app.
6+
end prologue
7+
8+
step "Tutorials Intro"
9+
You can keep track of how much of the tutorial you have completed
10+
with this progress bar, and exit the tutorial at any time by
11+
clicking on the stop button.
12+
13+
Clicking the fast-forward button will skip to the next important
14+
concept being introduced in the tutorial. Use this if you've got the
15+
idea about something or don't want to have to create every last
16+
part of the user interface, for example.
17+
18+
The tutorial will also help you out by disabling any options you
19+
don't need for the current step.
20+
action
21+
interlude
22+
highlight toolbar "tutorial"
23+
go to step "Stack Interlude"
24+
end step
25+
26+
skip point
27+
28+
step "Stack Interlude"
29+
We start by creating the User Interface (UI) for the Hello World app.
30+
31+
The first step is to create a new LiveCode app at the default size.
32+
33+
Click on the File menu, and select 'New Stack' → 'Default Size'.
34+
action
35+
highlight menu item "Default Size" of menu item "New Stack" of menu "File"
36+
capture the next new stack as "Mainstack"
37+
capture the next new card of stack "Mainstack" as "HelloWorld"
38+
wait until there is a stack "Mainstack"
39+
go to step "Properties interlude"
40+
end step
41+
42+
skip point
43+
44+
step "Properties interlude"
45+
Every object in LiveCode has a set of properties associated with it. These
46+
properties control the appearance, location and behavior of the objects
47+
in your app.
48+
49+
The Property Inspector is a window that allows you to control these properties.
50+
action
51+
interlude
52+
go to step "Set Stack Properties"
53+
end step
54+
55+
step "Set Stack Properties"
56+
Click on the 'Inspector' icon on the Toolbar to open the Property
57+
Inspector.
58+
action
59+
highlight toolbar "Inspector"
60+
wait until there is an inspector for stack "Mainstack"
61+
go to step "Set Stack Title"
62+
end step
63+
64+
step "Set Stack Title"
65+
Set the 'Title' property of the stack to "Hello World" and press 'Enter'.
66+
67+
You will see the title of the stack change after you set the property.
68+
action
69+
highlight property "title" of section "basic"
70+
wait until the title of stack "Mainstack" is "Hello World"
71+
go to step "Tools Palette Interlude"
72+
end step
73+
74+
skip point
75+
76+
step "Tools Palette Interlude"
77+
The next step is to add some objects to your stack.
78+
79+
This is the Tools Palette. It contains all the built-in objects that
80+
you can drag out onto your stack, such as buttons, text fields and
81+
scrollbars. It also contains more complex controls including a header bar,
82+
navigation bar, browser and line graph.
83+
action
84+
interlude
85+
highlight tools
86+
go to step "Create Button"
87+
end step
88+
89+
step "Create Button"
90+
The first object we will add is a button. Clicking on this button will
91+
show a message to the user.
92+
93+
Drag a button from the tools palette onto your stack.
94+
action
95+
highlight tool "Create Button"
96+
capture the next new button of stack "Mainstack" as "hello"
97+
wait until there is a button "hello"
98+
go to step "Set Button Location"
99+
end step
100+
101+
step "Set Button Location"
102+
Position the button, as shown.
103+
action
104+
add guide "buttonLoc" with rect "159,119,241,142" to stack "Mainstack"
105+
highlight guide "buttonLoc"
106+
wait until button "hello" fits guide "buttonLoc" with tolerance 5
107+
go to step "Open Property Inspector"
108+
end step
109+
110+
step "Open Property Inspector"
111+
Click on the 'Inspector' icon in the Toolbar to open the Property Inspector
112+
for the button.
113+
114+
Remember that properties control how objects look and behave and can be set using the Property Inspector.
115+
action
116+
highlight toolbar "Inspector"
117+
wait until there is an inspector for button "hello"
118+
go to step "Set button name"
119+
end step
120+
121+
step "Set button name"
122+
Set the 'Name' property of the button to "Say Hello" and press 'Enter'. You will see the Name appear on the button.
123+
action
124+
highlight property "name" of section "Basic"
125+
wait until the name of button "Hello" is "Say Hello"
126+
go to step "Events and messages interlude"
127+
end step
128+
129+
skip point
130+
131+
step "Events and messages interlude"
132+
Now that the UI is complete the next stage is to add code to the app
133+
to make it interactive.
134+
135+
LiveCode apps work by responding to 'messages', which are usually triggered by some kind of user action. A message might tell the app that the user has
136+
clicked on a button or typed in a field. You add code to tell the app what
137+
to do when a message is received.
138+
139+
Each object has it's own individual code, so different buttons can respond to
140+
messages in different ways.
141+
action
142+
interlude
143+
go to step "Open Add Script"
144+
end step
145+
146+
step "Open Add Script"
147+
Select the button and click the 'Code' button in the Toolbar.
148+
action
149+
highlight toolbar "Code"
150+
wait until there is a script editor for button "Hello"
151+
go to step "Script Editor Interlude"
152+
end step
153+
154+
step "Script Editor Interlude"
155+
The Script Editor is a window that allows you to add code to the
156+
objects on your stack.
157+
158+
Any code you have added in the Script Editor does not become live
159+
until you click on the 'Apply' button. When this is clicked, you will
160+
get feedback about whether the code you have written has any
161+
errors in it or not.
162+
action
163+
interlude
164+
highlight "Apply" of script editor for button "Hello"
165+
go to step "mouseUp message"
166+
end step
167+
168+
skip point
169+
170+
step "mouseUp message"
171+
The message we will respond to is 'mouseUp'. This message is sent when the
172+
user clicks on the button.
173+
174+
We will add code to display a message to the user saying "Hello World!"
175+
176+
Add this handler to the button script.
177+
178+
Don't forget to click the 'Apply' button when you have finished.
179+
script
180+
on mouseUp
181+
answer "Hello World!"
182+
end mouseUp
183+
action
184+
highlight script editor for button "Hello"
185+
wait until button "Hello" is scripted
186+
go to step "Edit Tool Interlude"
187+
end step
188+
189+
skip point
190+
191+
step "Edit Tool Interlude"
192+
LiveCode has two modes: Edit mode and Run mode.
193+
194+
Up until now you have been in Edit mode all the time. In Edit mode
195+
you can add, edit and move objects on your stack. You can also select objects
196+
to change their properties or add code to them.
197+
action
198+
interlude
199+
highlight tool "Edit Mode"
200+
go to step "Run Tool Interlude"
201+
end step
202+
203+
step "Run Tool Interlude"
204+
In Run mode your app is live - objects will behave as they would for
205+
the app user. For example, clicking on the 'Say Hello' button will show a hello message.
206+
207+
To test the code you have just added, we are going to enter Run mode and click the button.
208+
209+
Select 'Run mode' in the Tools Palette.
210+
action
211+
highlight tool "Run Mode"
212+
wait until the tool is run
213+
go to step "Test Button"
214+
end step
215+
216+
step "Test Button"
217+
Click on the 'Say Hello' button to see the message.
218+
action
219+
highlight button "hello"
220+
wait until button "hello" pops up answer dialog
221+
go to step "Next Steps"
222+
end step
223+
224+
step "Next Steps"
225+
That's it, you have finished your app.
226+
227+
Why don't you try customizing it by changing the message or adding multiple buttons that display different messages.
228+
229+
To learn more about LiveCode development why not try a more advanced tutorial or take a look at some of the lessons in our Lessons portal.
230+
action
231+
interlude
232+
highlight toolbar "Tutorials"
233+
go to step "Using in FileMaker"
234+
end step
235+
236+
epilogue
237+
Congratulations on completing your first LiveCode app. You have learned
238+
239+
- How to build the User Interface(UI) of an app by dragging and dropping objects
240+
241+
- The basics of coding in LiveCode to add interactivity to your app
242+
243+
- How to use the features of the LiveCode Integrated Development Environment (IDE)
244+
end epilogue

0 commit comments

Comments
 (0)