-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathsample.livecodescript
More file actions
312 lines (227 loc) · 4.64 KB
/
sample.livecodescript
File metadata and controls
312 lines (227 loc) · 4.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
script "LiveCode Sublime Text Language Module Example Stack"
global gGlobalVar # no variable assignemnt allowed for globals
global gGlobalVar2 -- just a variable for testing
local sLocalVar = true /* Default to true */
local sLocalVar2 = "a value"
constant kConstant = "red"
constant kConstant2 = "some value"
on libraryStack
if the short name of the target is not me then pass libraryStack
local tVar
/* This is a
multiline comment
*/
put "The \ character is the " & \
"line continuation character" into tVar
end libraryStack
command processParams
local tVar
put ($# - 1) into tVar
end processParams
setProp uCustomProp pValue
put pValue into sLocalVar
end uCustomProp
setProp uCustomProp2[pCategory] pValue
set the uCustomProp2[pCategory] of me to pValue
# line continuation.
# This:
if "1" is 1 then \
return "something"
else \
return "something else"
# Is the same as this:
if "1" is 1 then return "something"
else return "something else"
end uCustomProp2
getProp myCustomProp
return the myCustomProp2["test"] of me
end myCustomProp
getProp myCustomProp2 [pKey]
return sLocalVar[pKey]
end myCustomProp2
function myFunction pParam1, @rParam2
switch pParam1
case "1"
break
case "2"
break
case 3
break
default
return "test" for value
end switch
return myPrivateFunction(pParam1, rParam2)
end myFunction
command myCommand pParam
local tError
if 1 is "1" then return "nothing" # a comment
myPrivateCommand pParam
put the result into tError
return tError for error
end myCommand
private function myPrivateFunction pParam1, @xParam2
local tArray
local i,j,x
# with counterVar = startvalue to endvalue
repeat with i = 1 to the number of elements of tArray
if i = 1 then
next repeat
else
exit repeat
end if
end repeat
# with counterVar = startvalue to endvalue step x
repeat with i = 1 to 20 step 2
end repeat
# with counterVar = startvalue down to endvalue
repeat with i = 20 down to 10
subtract 1 from j
end repeat
# repeat x times
repeat 2 times
add 1 to i
end repeat
# repeat forever
repeat forever
add 1 to i
if i > 100 then exit repeat
end repeat
-- repeat while
repeat while x < 2
add 1 to x
end repeat
# repeat until
put 0 into x
repeat until x > 3
add 1 to x
end repeat
local tList, tVar
repeat for each item tItem in tList
add 1 to x
end repeat
repeat for each key tKey in tArray
put tKey & ":" && tArray[tKey] & cr after tVar
end repeat
repeat for each element tElement in tArray
end repeat
end myPrivateFunction
private command myPrivateCommand pParam1
local i
if 1 is 1 then
if i is 5 then next repeat
repeat with i = 1 to 10
exit repeat
end repeat
end if
end myPrivateCommand
private on myPrivateMessage
try
put 1 / 0
catch e
put "that didn't work so well"
end try
throw "it worked" && "!"
end myPrivateMessage
on mouseUp pBtnNum
answer param(0) && pBtnNum
end mouseUp
before mouseUp pBtnNum
answer param(0) && pBtnNum
end mouseUp
after mouseUp pBtnNum
answer param(0) && pBtnNum
end mouseUp
/**
The following examples are edge cases. These examples all compile
but the formatting may be a little strange.
*/
on mouseUp
beep
makeSomething
end mouseUp
on makeSomething
local a
local b
local c
local D
put "a" into a
put "b" into b
if a = b then put "c"
else if D = D then
put "d = d"
else
put "last else"
end if
if a then put c
if c then put a
if a then
if b then
else
end if
else
end if
if a then
doSomething
else put a
if a then
doSomething
else if d then put c
if a then doSomething else if d then put c
if a then doSomething
else if d then put c
if a
then
put a
put b
put c
end if
if a
then
put a
else
put b
end if
if a then
if b then get c else get d
else
doSomethingElse
end if
end makeSomething
on mouseDown/*ca */
local a
local f
local b
local aLIne
if aLine contains "/*" and aLine contains not "*/" then -- test
end if
/*aösfd */
put "beep"
put "a" into a
put "b" into f
if a = f then # comment \
put "--"; put "h" \
put "#" \
put "*" \
put "*"
if f = 1 then
end if
-- /*what is going on
-- --end if
-- here*/
else
put "a"
end if
if a is not b then beep
end mouseDown
on mouseMove
local a
local d
if a < d then
--beep
end if
end mouseMove
getprop myProp[begin]
beep
end myProp
on doSomethingElse
end doSomethingElse