forked from twolivesleft/Codea-Documentation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStorage.yaml
582 lines (519 loc) · 18.9 KB
/
Storage.yaml
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
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
id: storage
name: Storage
subtitle: Storing Persistent Data
ordering:
- Saving and Reading Images
- Local Storage
- Project Storage
- Global Storage
- Project Tabs
functions:
#---------------------------------
# readImage
#---------------------------------
- category: function
description: This function reads a stored sprite (i.e., a sprite that is visible
in the sprite picker) into an image type. You can read from the included sprite
packs, or your Documents and Dropbox sprite packs.
The `width` and `height` parameters are *only* used for vector sprites. These tell
Codea what resolution to rasterize the sprite at. If they are not specified, then
the sprite is rendered at the size specified in the vector source file. If only
the width is specified, the height is computed based on the aspect ratio.
examples:
- example: |
-- Read a sprite into an image
myImage = readImage("Planet Cute:Heart")
group: Saving and Reading Images
id: readImage
name: readImage( spriteKey )
parameters:
- description: string, name of sprite pack and sprite, separated by a colon (e.g.,
"Documents:MySprite")
name: spriteKey
- description: int, for vector sprites only. The desired width at which the vector sprite
is to be rendered.
name: width
- description: int, for vector sprites only. The desired height at which the vector sprite
is to be rendered.
name: height
related:
- saveImage
- image
- spriteList
returns: The image associated with **spriteKey** or **nil** if **spriteKey**
doesn't exist or is invalid.
syntax: |
readImage( spriteKey )
readImage( spriteKey, width )
readImage( spriteKey, width, height )
#---------------------------------
#---------------------------------
# saveImage
#---------------------------------
- category: function
description: >
This function saves an image into a sprite pack. Only user sprite
packs (**Documents** and **Dropbox**) are permitted for this operation.
If an existing sprite exists under the **spriteKey** name it will be overwritten,
if **nil** is specified for the **image** parameter then the sprite at
**spriteKey** will be deleted.
Note that if you are using a retina
device, two files will be saved when using this function. A retina sized image
with an "@2x" suffix, and a 50% scale non-retina image.
Note that
if you save an image to your **Dropbox** sprite pack then you will have to
open the sprite picker and sync your Dropbox sprite pack in order for the image
to be uploaded to your Dropbox account.
examples:
- example: |
-- Save a sprite into documents
function setup()
myImage = image(400,400)
setContext(myImage)
background(0,0,0,0)
fill(255,0,0)
ellipse(200,200,200)
setContext()
saveImage('Documents:Circle',myImage)
end
group: Saving and Reading Images
id: saveImage
name: saveImage( spriteKey, image )
parameters:
- description: string, name of sprite pack and sprite, separated by a colon (e.g.,
"Documents:MySprite")
name: spriteKey
- description: image, the image to be saved under **spriteKey**
name: image
related:
- readImage
- image
- spriteList
syntax: saveImage( spriteKey, image )
#---------------------------------
#---------------------------------
# spriteList
#---------------------------------
- category: function
description: This function returns a list of the names of images contained
in the sprite pack specified by **spritePackName**. For example, calling
**spriteList( "Documents" )** would return an array of the sprites stored
in your documents directory.
group: Saving and Reading Images
id: spriteList
name: spriteList( spritePackName )
parameters:
- description: string, name of the sprite pack. For example, "Documents", "Dropbox",
"Planet Cute"
name: spritePackName
related:
- readImage
- saveImage
- image
returns: An array of strings listing the sprites stored in the specified sprite
pack.
syntax: spriteList( spritePackName )
#---------------------------------
#---------------------------------
# readLocalData
#---------------------------------
- category: function
description: >
This function reads a value associated with **key** from the
local device storage for the current project.
Local storage for a
particular project is unique to your device. That is, sharing your project will
not share the associated data. This sort of storage is useful for things such
as high scores, statistics, and any values you are likely to associate while
a user is interacting with your game or simulation.
examples:
- example: |
-- Load high score
-- Defaults to 0 if it doesnt exist
highscore = readLocalData("highscore", 0)
group: Local Storage
id: readLocalData
name: readLocalData( key )
parameters:
- description: string, name of the piece of data you would like to get
name: key
- description: if the key doesn't exist, this value is returned instead
name: defaultValue
related:
- saveLocalData
- clearLocalData
returns: The value associated with **key**, or **defaultValue** if key doesn't
exist and **defaultValue** is specified. **nil** if **key** doesn't
exist and **defaultValue** is not specified.
syntax: |
readLocalData( key )
readLocalData( key, defaultValue )
#---------------------------------
#---------------------------------
# saveLocalData
#---------------------------------
- category: function
description: >
This function stores a value associated with **key** in the
local device storage for the current project.
Local storage for a
particular project is unique to your device. That is, sharing your project will
not share the associated data. This sort of storage is useful for things such
as high scores, statistics, and any values you are likely to associate while
a user is interacting with your game or simulation.
examples:
- example: |
-- Save high score
saveLocalData("highscore", currentScore)
group: Local Storage
id: saveLocalData
name: saveLocalData( key, value )
parameters:
- description: string, name of the piece of data you would like to store
name: key
- description: the value to store under **key**
name: value
related:
- readLocalData
- clearLocalData
syntax: saveLocalData( key, value )
#---------------------------------
#---------------------------------
# listLocalData
#---------------------------------
- category: function
description: >
This function returns a table containing all the keys in local
storage.
Local storage for a particular project is unique to your
device. That is, sharing your project will not share the associated data. This
sort of storage is useful for things such as high scores, statistics, and any
values you are likely to associate while a user is interacting with your game
or simulation.
group: Local Storage
id: listLocalData
name: listLocalData()
related:
- readLocalData
- saveLocalData
- clearLocalData
returns: A table containing all the keys stored in local data
syntax: listLocalData( )
#---------------------------------
#---------------------------------
# clearLocalData
#---------------------------------
- category: function
description: >
This function clears all local data for the current project.
Local
storage for a particular project is unique to your device. That is, sharing
your project will not share the associated data. This sort of storage is useful
for things such as high scores, statistics, and any values you are likely to
associate while a user is interacting with your game or simulation.
group: Local Storage
id: clearLocalData
name: clearLocalData()
related:
- readLocalData
- saveLocalData
syntax: clearLocalData( )
#---------------------------------
#---------------------------------
# readProjectData
#---------------------------------
- category: function
description: >
This function reads a value associated with **key** from the
project storage for the current project.
Project storage is bundled
with your project. That is, sharing your project will also share the associated
data. This sort of storage is useful for things such procedurally generated
levels, maps, and other static or dynamic data you may want to provide with
your project.
group: Project Storage
id: readProjectData
name: readProjectData( key )
parameters:
- description: string, name of the piece of data you would like to get
name: key
- description: if the key doesn't exist, this value is returned instead
name: defaultValue
related:
- saveProjectData
- clearProjectData
returns: The value associated with **key**, or **defaultValue** if key doesn't
exist and **defaultValue** is specified. **nil** if **key** doesn't
exist and **defaultValue** is not specified.
syntax: |
readProjectData( key )
readProjectData( key, defaultValue )
#---------------------------------
#---------------------------------
# saveProjectData
#---------------------------------
- category: function
description: >
This function stores a value associated with **key** in your
project's storage.
Project storage is bundled with your project.
That is, sharing your project will also share the associated data. This sort
of storage is useful for things such procedurally generated levels, maps, and
other static or dynamic data you may want to provide with your project.
group: Project Storage
id: saveProjectData
name: saveProjectData( key, value )
parameters:
- description: string, name of the piece of data you would like to store
name: key
- description: the value to store under **key**
name: value
related:
- readProjectData
- clearProjectData
syntax: saveProjectData( key, value )
#---------------------------------
#---------------------------------
# saveProjectInfo
#---------------------------------
- category: function
description: This function allows you to save metadata about your project from
within your code. For example, you may set the description that appears on the
Project Browser page by calling **saveProjectInfo()** with 'description'
as the key.
group: Project Storage
id: saveProjectInfo
name: saveProjectInfo( key, value )
parameters:
- description: string, name of the project metadata to store. Currently supports
"Description" and "Author"
name: key
- description: the value to store under **key**
name: value
related:
- readProjectInfo
syntax: saveProjectInfo( key, value )
#---------------------------------
#---------------------------------
# readProjectInfo
#---------------------------------
- category: function
description: This function reads a value associated with **key** from the
project metadata for the current project.
group: Project Storage
id: readProjectInfo
name: readProjectInfo( key )
parameters:
- description: string, name of the piece of metadata you would like to get
name: key
related:
- saveProjectInfo
returns: The value associated with **key**, or nil if the key does not exist
syntax: readProjectInfo( key )
#---------------------------------
#---------------------------------
# listProjectData
#---------------------------------
- category: function
description: >
This function returns a table containing all the keys stored in
project data.
Project storage is bundled with your project. That
is, sharing your project will also share the associated data. This sort of storage
is useful for things such procedurally generated levels, maps, and other static
or dynamic data you may want to provide with your project.
group: Project Storage
id: listProjectData
name: listProjectData()
related:
- readProjectData
- saveProjectData
- clearProjectData
returns: A table containing all the keys stored in project data
syntax: listProjectData( )
#---------------------------------
#---------------------------------
# clearProjectData
#---------------------------------
- category: function
description: >
This function clears all project-stored data.
Project storage is bundled with your project. That is, sharing your project will also
share the associated data. This sort of storage is useful for things such procedurally
generated levels, maps, and other static or dynamic data you may want to provide
with your project.
group: Project Storage
id: clearProjectData
name: clearProjectData()
related:
- readProjectData
- saveProjectData
syntax: clearProjectData( )
#---------------------------------
#---------------------------------
# readGlobalData
#---------------------------------
- category: function
description: >
This function reads a value associated with **key** from the
global storage on this device.
Global storage is shared among all
projects on this device.
group: Global Storage
id: readGlobalData
name: readGlobalData( key )
parameters:
- description: string, name of the piece of data you would like to get
name: key
- description: if the key doesn't exist, this value is returned instead
name: defaultValue
related:
- saveGlobalData
- clearProjectData
returns: The value associated with **key**, or **defaultValue** if key doesn't
exist and **defaultValue** is specified. **nil** if **key** doesn't
exist and **defaultValue** is not specified.
syntax: |
readGlobalData( key )
readGlobalData( key, defaultValue )
#---------------------------------
#---------------------------------
# saveGlobalData
#---------------------------------
- category: function
description: >
This function stores a value associated with **key** in this
device's global storage.
Global storage is shared among all projects
on this device.
group: Global Storage
id: saveGlobalData
name: saveGlobalData( key, value )
parameters:
- description: string, name of the piece of data you would like to store
name: key
- description: the value to store under **key**
name: value
related:
- readGlobalData
syntax: saveGlobalData( key, value )
#---------------------------------
#---------------------------------
# listGlobalData
#---------------------------------
- category: function
description: >
This function returns a table containing all the keys stored in
global data.
Global storage is shared among all projects on this
device.
group: Global Storage
id: listGlobalData
name: listGlobalData()
related:
- readGlobalData
- saveGlobalData
returns: A table containing all the keys stored in global data
syntax: listGlobalData( )
#---------------------------------
#---------------------------------
# readProjectTab
#---------------------------------
- category: function
description: >
This function can be used to read the contents of a tab in the current project,
or in another project. The contents of the tab are returned as a string. The
`key` parameter specifies the tab to read, and can optionally include the project
name to read from. If no project name is specified, the tab is read from the
current project.
The `key` parameter takes the form *"Project Name:Tab Name"*. *"Project Name"* specifies
the project to read from, and *"Tab Name"* specifies the tab to read. If *"Project Name"*
is not specified, "Tab Name" is assumed to exist in the currently running project, and is
read from there.
If the `key` can not be found, then an error is printed and playback is paused.
examples:
- example: |
-- Read the main tab in the current project
mainTab = readProjectTab("Main")
-- Print the results
print( mainTab )
- example: |
-- Read the main tab in a different project
mainTab = readProjectTab("My Project:Main")
-- Print the results
print( mainTab )
group: Project Tabs
id: readProjectTab
name: readProjectTab( key )
parameters:
- description: string, a key specifying the project and tab you would like to read
name: key
related:
- saveProjectTab
- listProjectTabs
returns: A string containing the contents of the tab specified by `key`. If `key` is
not found, returns nothing.
syntax: |
readProjectTab( key )
#---------------------------------
#---------------------------------
# saveProjectTab
#---------------------------------
- category: function
description: >
This function can be used to save the contents of a tab in the current project,
or in another user project.
The `key` parameter takes the form *"Project Name:Tab Name"*. *"Project Name"* specifies
the project to save to, and *"Tab Name"* specifies the tab to write. If *"Project Name"*
is not specified, *"Tab Name"* is assumed to exist in the currently running project.
The `value` parameter is a string that is written to the location specified by `key`.
If `value` is nil, then Codea will delete the tab specified by `key`.
Please note that this function only works on user projects, and will not work on the
built in example projects as they are read-only.
examples:
- example: |
-- Create a tab named "Test"
-- In the current project
saveProjectTab("Test", "-- This is a test!")
- example: |
-- Delete the tab named "Test"
-- In the current project
saveProjectTab("Test", nil)
group: Project Tabs
id: saveProjectTab
name: saveProjectTab( key, value )
parameters:
- description: string, a key specifying a project and tab
name: key
- description: >
string, the contents to write into the tab specified by `key`, a value
of `nil` deletes the tab.
name: value
related:
- readProjectTab
- listProjectTabs
syntax: saveProjectTab( key, value )
#---------------------------------
#---------------------------------
# listProjectTabs
#---------------------------------
- category: function
description: >
This function returns a table containing all the tabs in the specified project.
If no argument is provided, this function will return a table containing all
the tabs in the *currently running* project. If a value is specified for `project`
then the tab list will be fetched from that project.
group: Project Tabs
id: listProjectTabs
name: listProjectTabs()
parameters:
- description: string, the name of a project to retrieve tabs from
name: project
related:
- readProjectTab
- saveProjectTab
returns: A table containing all the tabs in the specified project
syntax: |
listProjectTabs( )
listProjectTabs( project )
#---------------------------------