-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.html
5244 lines (4995 loc) · 252 KB
/
main.html
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
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
__NOTOC__
{{#seo:|
description=Pssssstt hey kids wanna learn some APIs|
image=https://static.miraheze.org/apicowiki/5/5f/Thumbnail-Modding.png|
}}
<div class="aw aw-api">
<div class="aw-panel">
<div class="aw-panel--left">
<p>Welcome to the API reference for APICO! This API is split up into a bunch of sections listed below, each with an overview table.</p>
<p>You can toggle the details of each section, which contain further information and examples, with the <nowiki>[Expand Details]</nowiki> button.</p>
<p>If you're looking for info on how to start making mods, check out out [[Modding Guide|Getting Started]] section.</p>
<p>For any of the {{I|i=api_define_*}} methods you can check out the [https://github.com/APICO-Modders/APICO-Sample-Mod Sample Mod] on GitHub for sprite examples.
</div>
<div class="aw-panel--right">
<div class="aw-info">
<p class="h"><i>Modding</i></p>
<p class="sh">API Reference</p>
</div>
</div>
</div>
{| class="wikitable"
! Section !! Description
|-
| [[#Standard Datatypes|Standard Datatypes]] || LUA datatypes that are referenced in the API
|-
| [[#Custom Datatypes|Custom Datatypes]] || Custom datatypes (LUA tables) that are referenced in the API
|-
| [[#Hooks|Hooks]] || Custom hooks your mod can implement to react to certain game events or cycles
|-
| [[#All Methods|All Methods]] || Methods to get all instances of specific types
|-
| [[#Create Methods|Create Methods]] || Methods to create new instances or effects
|-
| [[#Define Methods|Define Methods]] || Methods to define things like items, objects, bees, or recipes
|-
| [[#Describe Methods|Describe Methods]] || Methods to describe game metadata like dictionary definitions
|-
| [[#Draw Methods|Draw Methods]] || Methods to draw sprites or shapes in draw cycles
|-
| [[#Get Methods|Get Methods]] || Methods to get instances or properties
|-
| [[#Give Methods|Give Methods]] || Methods to give the player items or money
|-
| [[#Misc Methods|Misc Methods]] || Misc. helper methods you may find useful
|-
| [[#Mod Methods|Mod Methods]] || Methods to access and call other loaded mod methods
|-
| [[#Set Methods|Set Methods]] || Methods to set values or properties
|-
| [[#Slot Methods|Slot Methods]] || Methods to help manipulate menu slots
|-
| [[#Take Methods|Take Methods]] || Methods to take currency from the player
|-
| [[#Use Methods|Use Methods]] || Methods related to using up items the player has
|}
<p>Datatypes, like {{D|i=table}}, are in yellow and can be clicked on for more details.<br/>Hooks, like {{H|i=register()}}, are in blue and can also be clicked on for more details.<br/>Methods, like {{F|i=api_create_log()}}, are in orange and can also be clicked on for more details.<br/><br/>Whenever we mentiond an {{I|i=OID}} we are referring to the item's unique game ID, check the [[OID Reference]] for more info.</p>
<div class="aw-api-section mw-customcollapsible-s1">
<h1>[[File:Predictor_Item.png|32px]]Standard Datatypes</h1>
<p>These are all the standard datatypes for LUA used by the API</p>
{| class="wikitable"
! Datatype !! Description
|-
| {{D|i=string}} || standard string datatype
|-
| {{D|i=integer}} || standard integer datatype
|-
| {{D|i=decimal}} || standard decimal datatype
|-
| {{D|i=boolean}} || standard boolean datatype
|-
| {{D|i=list}} || standard list/array datatype - list indices start at 1 in LUA!
|-
| {{D|i=table}} || 2D array / js object-like datatype, with key-value pairs
|}
<div class="mw-collapsible mw-collapsed" id="mw-customcollapsible-s1">
<h2>string</h2>
<p>This is a standard string represented by {{I|i="Quotes"}} as in most languages.</p><br/>
<h2>integer</h2>
<p>This is a standard integer</p><br/>
<h2>decimal</h2>
<p>This is a standard decimal number</p><br/>
<h2>boolean</h2>
<p>This is a true/false value, in these docs you will see 0 and 1 used</p><br/>
<h2>list</h2>
<p>A list is simply a list of values, represented by {{I|i=<nowiki>{1,2,3}</nowiki>}}. The values inside a list can be any datatype and don't need to match each other.<br/><b>In LUA, the index for lists starts at 1!!!</b></p><br/>
<h2>table</h2>
<p>A table is like a 2D array or a JS object. You can give it any key, which can have any value, for example you could have {{I| i=<nowiki>{name="APICO"}</nowiki>}}.<br/>A lot of the parameters either needed by the API or returned are some form of table, which we refer to as a "custom datatype"</p><br/>
<h2>nil</h2>
<p>This is the null or undefined value in LUA</p>
</div>
</div><br/>
<div class="aw-api-section mw-customcollapsible-s2">
<h1>[[File:Microscope_Item.png|32px]]Custom Datatypes</h1>
<p>These are custom "datatypes" to help make the API clearer. In reality all of these datatypes are just {{D|i=table}} elements with different key values set that you can access with {{I|i=datatype["key"]}}</p>
{| class="wikitable"
! Datatype !! Description
|-
| {{D|i=bee_definition}} || Represents a definition for a new bee
|-
| {{D|i=blueprint}} || Represents a blueprint instruction for the worldgen
|-
| {{D|i=boundary}} || Represents a bounding box for an instance
|-
| {{D|i=color}} || Represents a custom RGB color
|-
| {{D|i=coordinate}} || Represents an x/y coordinate, relative to the top-left of the world
|-
| {{D|i=flower_definition}} || Represents a definition for a new flower
|-
| {{D|i=info}} || Represents the help information shown on a menu
|-
| {{D|i=ingredient}} || Represents an ingredient for a crafting recipe
|-
| {{D|i=instance}} || Represents a generic instance, used for items, objects, buttons, gui, and menu objects
|-
| {{D|i=item_definition}} || Represents a definition for a new item
|-
| {{D|i=layout}} || Represents a layout of slots for a menu definition
|-
| {{D|i=menu_definition}} || Represents a definition for a new menu object
|-
| {{D|i=npc_definition}} || Represents a definition for a new NPC
|-
| {{D|i=obj_definition}} || Represents a definition for a new object
|-
| {{D|i=quest_definition}} || Represents a definition for a new quest
|-
| {{D|i=quest_line}} || Represents a page of text for a quest
|-
| {{D|i=recipe}} || Represents a crafting recipe for the workbench
|-
| {{D|i=scripts}} || Represents a set of scripts for a menu definition
|-
| {{D|i=stats}} || Represents the stats property of a slot
|-
| {{D|i=slot}} || Represents a slot instance
|-
| {{D|i=time}} || Represents the game time
|-
| {{D|i=wall_definition}} || Represents a definition for a new wall
|-
| {{D|i=weather}} || Represents the game weather
|-
| {{D|i=window_definition}} || Represents a definition for a new window
|}
<div class="mw-collapsible mw-collapsed" id="mw-customcollapsible-s2">
<h2>bee_definition</h2>
<p>Represents a definition for a new bee. This will add an entry into the bee book as well as give you a bee you can use and breed with.</p>
{| class="wikitable"
! Key !! Datatype !! Description
|-
| id || {{D|i=string}} || lowercase unique name for your bee, i.e. {{I|i=common}}, used for progress
|-
| title || {{D|i=string}} || name of your bee for tooltips + books, i.e. {{I|i=Common}}
|-
| latin || {{D|i=string}} || the latin name for your bee, shown in the book
|-
| hint || {{D|i=string}} || the hint to show in the book when this species hasn't been discovered yet
|-
| desc || {{D|i=string}} || the description to show in the book when this species has been discovered
|-
| lifespan || list({{D|i=string}}) || a list of possible lifespan traits this species can spawn with, value options are {{I|i=Hyper}}, {{I|i=Rapid}}, {{I|i=Short}}, {{I|i=Normal}}, {{I|i=Long}}, {{I|i=Ancient}}, {{I|i=Eternal}}
|-
| productivity || list({{D|i=string}}) || a list of possible productivity traits this species can spawn with, value options are {{I|i=Sluggish}}, {{I|i=Slowest}}, {{I|i=Slow}}, {{I|i=Normal}}, {{I|i=Fast}}, {{I|i=Fastest}}, {{I|i=Brisk}}
|-
| fertility || list({{D|i=string}}) || a list of possible fertility traits this species can spawn with, value options are {{I|i=Sterile}}, {{I|i=Infertile}}, {{I|i=Unlucky}}, {{I|i=Fertile}}, {{I|i=Fecund}}, {{I|i=Prolific}}, {{I|i=Swarming}}
|-
| stability || list({{D|i=string}}) || a list of possible stability traits this species can spawn with, value options are {{I|i=Chaotic}}, {{I|i=Erratic}}, {{I|i=Unstable}}, {{I|i=Normal}}, {{I|i=Stable}}, {{I|i=Ordered}}, {{I|i=Pure}}
|-
| behaviour || list({{D|i=string}}) || a list of possible behaviour traits this species can spawn with, value options are {{I|i=Diurnal}}, {{I|i=Nocturnal}}, {{I|i=Crepuscular}}, {{I|i=Cathemeral}}
|-
| climate || list({{D|i=string}}) || a list of possible climate traits this species can spawn with, value options are {{I|i=Temperate}}, {{I|i=Tropic}}, {{I|i=Polar}}, {{I|i=Any}}
|-
| rainlover || {{D|i=boolean}} || whether this species can work while it's raining
|-
| snowlover || {{D|i=boolean}} || whether this species can work while it's snowing
|-
| grumpy || {{D|i=boolean}} || whether this species is grumpy and needs to be calmed before being worked with
|-
| produce || {{D|i=string}} || the item oid of the item this species' "special produce" that will be created when frames are extracted
|-
| chance || {{D|i=integer}} || the chance this bee can be formed when it's the mutation for a hybrid
|-
| requirement || {{D|i=string}} || the requirement for how this bee can be formed when it's the mutation for a hybrid, shown in the Predictor
|-
| bid || {{D|i=string}} || a unique 2 character identifier for this species to use for the beebox / beebank storage. The identifier cannot be a number, i.e. {{I|i=01}} as these are reserved by the base game.<br/>This must be unique across all mods, so ask your fellow modders first!
|-
| calming || list({{D|i=string}}) || [Optional] if this species is grumpy, you can provide a list of flower oids that calm it, i.e. {{I|i=["flower1", "flower2"]}} (see [[OID Reference]])
|-
| tier || {{D|i=integer}} || [Optional] the tier this bee should belond to, if there is room. Should be a number between 1-5, if no room is in the given tier it'll try the next tier up until it defaults to 5
|}<br/>
<h2>blueprint</h2>
<p>Blueprints represent an instruction for the worldgen. Each Blueprint defines an area in the world to create a blob of land.</p>
{| class="wikitable"
! Key !! Datatype !! Description
|-
| width || {{D|i=integer}} || the width of the blueprint, which effects the blob of land created
|-
| height || {{D|i=integer}} || the height of the blueprint, which effects the blob of land created
|-
| x || {{D|i=integer}} || the y position in the world to put this blueprint
|-
| y || {{D|i=integer}} || the y position in the world to put this blueprint
|-
| type || {{D|i=string}} || the type of biome to set for this blueprint, options are "forest", "swamp", "snow", "hallow"
|-
| dye || {{D|i=integer}} || [Optional] set a dye to apply to the land and nature items, valid number between 1-16
|}<br/>
<h2>boundary</h2>
<p>Boundaries represent the bounding box for a given instance.</p>
{| class="wikitable"
! Key !! Datatype !! Description
|-
| top || {{D|i=integer}} || the top y position of the bounding box
|-
| left || {{D|i=integer}} || the left x position of the bounding box
|-
| bottom || {{D|i=integer}} || the bottom y position of the bounding box
|-
| right || {{D|i=integer}} || the right x position of the bounding box
|}<br/>
<h2>color</h2>
<p>Colors represent an RGB color that can be defined or passed through the API.</p>
{| class="wikitable"
! Key !! Datatype !! Description
|-
| r || {{D|i=integer}} || the red value of the color
|-
| g || {{D|i=integer}} || the green value of the color
|-
| b || {{D|i=integer}} || the blue value of the color
|}<br/>
<h2>coordinate</h2>
<p>Coordinates represent an x + y position</p>
{| class="wikitable"
! Key !! Datatype !! Description
|-
| x || {{D|i=integer}} || the x position of this co-ordinate
|-
| y || {{D|i=integer}} || the y position of this co-ordinate
|}<br/>
<h2>flower_definition</h2>
<p>Represents a definition for a new flower. Flowers can be picked up, placed, crafted with, and visited by bees.<br/><b>Contrary to all other definitions, flowers defined through the API have an oid without your mod_name, so they will need to be unique across all mods.</b></p>
{| class="wikitable"
! Key !! Datatype !! Description
|-
| id || {{D|i=string}} || unique ID for this flower - your oid will be a combination of "flower" and your id, i.e. {{I|i=flower69}}
|-
| species || {{D|i=string}} || lowercase unique name for your flower, i.e. {{I|i=waspbane}}, used for progress
|-
| title || {{D|i=string}} || name of your flower for tooltips, i.e. {{I|i=Waspbane}}
|-
| latin || {{D|i=string}} || the latin name for your flower, shown in the book
|-
| hint || {{D|i=string}} || the hint to show in the book when this species hasn't been discovered yet
|-
| desc || {{D|i=string}} || the description to show in the book when this species has been discovered
|-
| aquatic || {{D|i=boolean}} || whether this flower can be planted / grow on shallow water
|-
| deep || {{D|i=boolean}} || [Optional] whether this flower can be planted / grow on deep water
|-
| shop_buy || {{D|i=integer}} || [Optional] the amount this flower can be bought for if sold by an NPC
|-
| shop_sell || {{D|i=integer}} || [Optional] the amount this flower can be sold for at an NPC
|-
| machines || list({{D|i=string}}) || [Optional] a list of object oids that this flower can be used in, i.e. {{I|i= ["workbench", "sawmill"]}}, shown in tooltips (see [[OID Reference]])
|-
| tools || list({{D|i=string}}) || [Optional] a list of tools that can be used on this flower, i.e. {{I|i=["mouse1", "axe1"]}}, shown in tooltips
|-
| variants || {{D|i=integer}} || [Optional] specifies the number of variants in your sprite image, defaults to 1
|-
| chance || {{D|i=integer}} || [Optional] the chance this species will be formed as a mutation, defaults to 100
|-
| smoker || list({{D|i=string}}) || [Optional] a list of bee species that this flower can be used to calm in a smoker, i.e. {{I|i=["stubborn"]}}
|-
| has_lighting || {{D|i=boolean}} || [Optional] if true, the flower will light up at night like Pondshine
|}<br/>
<h2>info</h2>
<p>Represents a list of information tooltips to use with a menu object's definition. This is the information shown when someone pressed the "Help" button for a menu.<br/>Technically this is a list of values, hence the keys below being numbers.</p>
{| class="wikitable"
! Key !! Datatype !! Description
|-
| 0 || {{D|i=string}} || the tooltip to show, i.e. {{I|i=1. Input Slots}}
|-
| 1 || {{D|i=string}} || the color key to use for the tooltip, valid options are {{I|i=GREEN}}, {{I|i=BLUE}}, {{I|i=RED}}, {{I|i=YELLOW}}, or {{I|i=WHITE}}
|}<br/>
<h2>ingredient</h2>
<p>Represents an ingredient for a recipe</p>
{| class="wikitable"
! Key !! Datatype !! Description
|-
| item || {{D|i=string}} || the item for this ingredient
|-
| amount || {{D|i=integer}} || the amount of this item needed for this ingredient
|}<br/>
<h2>instance</h2>
<p>A generic representation of any instance. All instance types have the same properties, albeit some will be {{D|i=nil}}. See [[Instance Properties]] for more specific information.</p>
{| class="wikitable"
! Key !! Datatype !! Description
|-
| id || {{D|i=integer}} || the GMS id for this instance, to use in API methods
|-
| x || {{D|i=integer}} || the x position of this inst
|-
| y || {{D|i=integer}} || the y position of this inst
|-
| oid || {{D|i=integer}} || the APICO "id" value used with the Dictionary - will be nil on item/slot instances (see [[OID Reference]])
|-
| sprite_index || {{D|i=integer}} || the sprite image id used for this instance
|-
| image_index || {{D|i=integer}} || the sprite image "frame" currently set for this instance
|-
| image_xscale || {{D|i=integer}} || image xscale used in rendering, i.e. -1 to flip vertically
|-
| image_yscale || {{D|i=integer}} || image yscale used in rendering, i.e. -1 to flip horizontally
|-
| menu_id || {{D|i=integer}} || the menu instance for this instance - will be nil if not a menu object instance
|-
| slots || list({{D|i=slot}}) || a list of slot instances - will be nil if not a menu instance
|}<br/>
<h2>item_definition</h2>
<p>Represents a definition for a new item. Items can be picked up, dropped, used, and crafted with.<br/>A good in-game example of an item would be Logs</p>
{| class="wikitable"
! Key !! Datatype !! Description
|-
| id || {{D|i=string}} || id to use to create an oid for this item. Unless defining a flower, your new item oid will be a your mod_id + the item id give, i.e. "sample_mod_my_item" (be mindful of [[Reserved OIDs]])
|-
| name || {{D|i=string}} || the name of this item, shown in tooltips
|-
| category || {{D|i=string}} || the category for this item, shown in expanded tooltips
|-
| tooltip || {{D|i=string}} || the tooltip message for this item, shown in expanded tooltips
|-
| shop_key || {{D|i=boolean}} || [Optional] whether this is a "key" item and so cannot be sold
|-
| shop_buy || {{D|i=boolean}} || [Optional] the amount this item can be bought for if sold by an NPC
|-
| shop_sell || {{D|i=boolean}} || [Optional] the amount this item can be sold for at an NPC
|-
| machines || list({{D|i=string}}) || [Optional] a list of object oids that this item this can be used in, i.e. {{I|i=["workbench", "sawmill"]}}, shown in tooltips (see [[OID Reference]])
|-
| placeable || {{D|i=boolean}} || [Optional] whether this item can be placed down on the ground, will use the object oid specified in "obj" if true
|-
| place_grass || {{D|i=boolean}} || [Optional] if placeable, this specifies if the item can only be placed on grass
|-
| place_water || {{D|i=boolean}} || [Optional] if placeable, this specifies if the item can only be placed on shallow water
|-
| place_deep || {{D|i=boolean}} || [Optional] if placeable, this specifies if the item can only be placed on deep water
|-
| singular || {{D|i=boolean}} || [Optional] if specified, items created with this definition will not be able to stack, like frames - you MUST give it a durability if you set this
|-
| durability || {{D|i=boolean}} || [Optional] if specified, items created with this definition will have a durability, like tools
|-
| obj || {{D|i=string}} || [Optional] if placeable, this specifies the object oid that will be created when the item is used
|-
| honeycore || {{D|i=boolean}} || [Optional] if true, this item will be bought + sold for honeycore instead of rubees
|-
| bee_lore || {{D|i=string}} || [Optional] if set, this will be used as the "lore" in the bee book if this item is a bee's special produce
|}<br/>
<h2>layout</h2>
<p>Represents a layout to use with a menu object's definition. This tells the game where you want the slots in relation to the menu's top left coordinate as well as what can or can't be put in that slot.<br/>Technically this is a list of values, hence the keys below being numbers.</p>
{| class="wikitable"
! Key !! Datatype !! Description
|-
| 0 || {{D|i=string}} || the x position for the slot, relative to the menu's top left coordinate
|-
| 1 || {{D|i=string}} || the y position for the slot, relative to the menu's top left coordinate
|-
| 2 || {{D|i=string}} || [Optional] the type of slot this is, valid options are {{I|i=Input}}, {{I|i=Liquid Input}}, {{I|i=Output}}, {{I|i=Liquid Output}}, or {{I|i=Shop}}. Output slots cannot have items put in them.
|-
| 3 || list({{D|i=string}}) || [Optional] if the type of slot is {{I|i=Input}} or {{I|i=Liquid Input}}, this let's you define the items that are allowed in them, i.e. {{I|i=["log", "sticks1"]}}. You can also use some "specials" that allow any items of that same oid, namely: "seedX", "flowerX", "trackX", "dyeX", as well as "customX" (see {{F|i=api_define_validation_icon()}})
|}<br/>
<h2>menu_definition</h2>
<p>Represents a definition for a new menu object. Menu Objects are similar to objects but can be clicked to open a menu, like say a Sawbench.<br/>They can be also given logic to run all the time so are a powerful tool for your mods.</p>
{| class="wikitable"
! Key !! Datatype !! Description
|-
| id || {{D|i=string}} || id to use to create an oid for this object. Your new object oid will be a your mod_id + the object id give, i.e. "sample_mod_my_object" (be mindful of [[Reserved OIDs]])
|-
| name || {{D|i=string}} || the name of this object shown in tooltips
|-
| category || {{D|i=string}} || the category for this object, shown in expanded tooltips
|-
| tooltip || {{D|i=string}} || the tooltip message for this object, shown in expanded tooltips
|-
| shop_key || {{D|i=boolean}} || [Optional] whether this is a "key" object and so cannot be sold
|-
| shop_buy || {{D|i=boolean}} || [Optional] the amount this object can be bought for if sold by an NPC
|-
| shop_sell || {{D|i=boolean}} || [Optional] the amount this object can be sold for at an NPC
|-
| layout || list({{D|i=layout}}) || a list of layouts to set the slots for this objects menu
|-
| info || list({{D|i=info}}) || a list of information to show when the menu help button is pressed
|-
| buttons || list({{D|i=string}}) || a list of buttons for this objects menu to have, valid options are {{I|i=Help}}, {{I|i=Target}}, {{I|i=Sort}}, {{I|i=Move}}, {{I|i=Close}}
|-
| machines || list({{D|i=string}}) || [Optional] a list of object oids that this object this can be used in, i.e. {{I|i= ["workbench", "sawmill"]}}, shown in tooltips (see [[OID Reference]])
|-
| tools || list({{D|i=string}}) || [Optional] a list of tools that can be used on this object, i.e. {{I|i=["mouse1", "axe1"]}}, shown in tooltips
|-
| nature || {{D|i=boolean}} || [Optional] this specifies if the object can only be placed on grass
|-
| aquatic || {{D|i=boolean}} || [Optional] this specifies if the object can only be placed on shallow water
|-
| deep || {{D|i=boolean}} || [Optional] this specifies if the object can only be placed on deep water
|-
| singular || {{D|i=boolean}} || [Optional] this specifies if the object can stack or can only be singular, like frames or bees
|-
| invisible || {{D|i=boolean}} || [Optional] if true, this object will not be drawn - it's bounding box will still be interactive though!
|-
| center || {{D|i=boolean}} || [Optional] if true, when this object's menu opens it will automatically be put in the center of the screen
|-
| item_sprite || {{D|i=string}} || [Optional] if you have an object that's overworld sprite is bigger than 16x16, you can use this to specify an alternate sprite to use as the item + slot sprite
|}<br/>
<h2>npc_definition</h2>
<p>Represents a definition for a new NPC. NPCs are basically just menu objects that move around and have a special second menu for their shop.</p>
{| class="wikitable"
! Key !! Datatype !! Description
|-
| id || {{D|i=integer}} || id to use for the npc, must be unique across all mods
|-
| name || {{D|i=string}} || the name of this NPC, shown in tooltips and their dialogue
|-
| pronouns || {{D|i=string}} || the pronouns for this NPC, shown in their dialogue
|-
| tooltip || {{D|i=string}} || the tooltip message for this NPC, usually just a greeting message
|-
| specials || list({{D|i=string}}) || a list of at least 3 item oids that this NPC will have in it's special item pool
|-
| stock|| list({{D|i=string}}) || a list of up to 10 item oids that this NPC will have as it's shop stock
|-
| greeting || {{D|i=string}} || the default greeting message shown in the dialogue menu when it opens
|-
| dialogue || list({{D|i=string}}) || a list of dialogue to show one after the other when a player clicks the "talk" button
|-
| walking || {{D|i=boolean}} || [Optional] whether this NPC will walk around or stay still
|-
| shop || {{D|i=boolean}} || [Optional] whether this NPC will have a shop or just be dialogue only
|}<br/>
<h2>obj_definition</h2>
<p>Represents a definition for a new object. Objects can be picked up, dropped, placed, clicked on, and crafted with.<br/>A good in-game example of an object would be the Bench</p>
{| class="wikitable"
! Key !! Datatype !! Description
|-
| id || {{D|i=string}} || id to use to create an oid for this object. Unless defining a flower, your new object oid will be a your mod_id + the object id give, i.e. "sample_mod_my_object" (be mindful of [[Reserved OIDs]])
|-
| name || {{D|i=string}} || the name of this object shown in tooltips
|-
| category || {{D|i=string}} || the category for this object, shown in expanded tooltips
|-
| tooltip || {{D|i=string}} || the tooltip message for this object, shown in expanded tooltips
|-
| shop_key || {{D|i=boolean}} || [Optional] whether this is a "key" object and so cannot be sold
|-
| shop_buy || {{D|i=boolean}} || [Optional] the amount this object can be bought for if sold by an NPC
|-
| shop_sell || {{D|i=boolean}} || [Optional] the amount this object can be sold for at an NPC
|-
| machines || list({{D|i=string}}) || [Optional] a list of object oids that this object this can be used in, i.e. {{I|i= ["workbench", "sawmill"]}}, shown in tooltips (see [[OID Reference]])
|-
| tools || list({{D|i=string}}) || [Optional] a list of tools that can be used on this object, i.e. {{I|i=["mouse1", "axe1"]}}, shown in tooltips
|-
| drops || list({{D|i=string}}) || [Optional] a list of items that will be dropped when this object is chopped/mined (see "tree" or "shrub" definitions in the dictionary for examples of formatting)
|-
| place_grass || {{D|i=boolean}} || [Optional] this specifies if the object can only be placed on grass
|-
| place_water || {{D|i=boolean}} || [Optional] this specifies if the object can only be placed on shallow water
|-
| place_deep || {{D|i=boolean}} || [Optional] this specifies if the object can only be placed on deep water
|-
| durability || {{D|i=boolean}} || [Optional] if specified, objects created with this definition will have a durability, like tools (this is NOT the same as health)
|-
| hp || {{D|i=boolean}} || [Optional] if specified, object created will have health, likes trees (this is NOT the same as durability)
|-
| singular || {{D|i=boolean}} || [Optional] if specified, objects created with this definition will not be able to stack, like frames
|-
| honeycore || {{D|i=boolean}} || [Optional] if true, this objects will be bought + sold for honeycore instead of rubees
|-
| invisible || {{D|i=boolean}} || [Optional] if true, this object will not be drawn - it's bounding box will still be interactive though!
|-
| bed || {{D|i=boolean}} || [Optional] if true, this object will act as a bed when clicked
|-
| bench || {{D|i=boolean}} || [Optional] if true, this object will act as a bench when clicked
|-
| has_lighting || {{D|i=boolean}} || [Optional] if true, this object will light up at night
|-
| has_shadow || {{D|i=boolean}} || [Optional] if true, a shadow will be automatically drawn under this object
|-
| pickable || {{D|i=boolean}} || [Optional] if true, you'll be able to pick up this item with the mouse
|-
| variants || {{D|i=integer}} || [Optional] for nature objects, like trees, this specifies the amount of variants within the sprite for the object
|-
| growth || {{D|i=string}} || [Optional] if set, after the object is created a timer will start, after which a new object will be created instead, for example saplings in the game use {{I|i="tree 360 560"}} to make a tree randomly after 360-560 seconds
|-
| item_sprite || {{D|i=string}} || [Optional] if you have an object that's overworld sprite is bigger than 16x16, you can use this to specify an alternate sprite to use as the item + slot sprite
|}<br/>
<h2>quest_definition</h2>
<p>Represents a quest definition to make a new quest in the book.</p>
{| class="wikitable"
! Key !! Datatype !! Description
|-
| id || {{D|i=string}} || the unique id for your quest, for use with the progress handler
|-
| title || {{D|i=string}} || the title of your quest as shown in the book chapter list
|-
| reqs || list({{D|i=string}}) || the requirements needed for the quest to be ready, e.g. {{I|i=["axe1@2"]}} would mean 2 wooden axes are needed to complete
|-
| icon || {{D|i=string}} || the item oid of the item to use for the icon in the overview section of the book (see [[OID Reference]])
|-
| reward || {{D|i=string}} || the reward that will be given when the quest is handed in, e.g. {{I|i="honeycore1@10"}} would give 10 honeycore crystals
|-
| unlock || list({{D|i=string}}) || a list of quests ids to unlock when this quest is complete
|}<br/>
<h2>quest_line</h2>
<p>Represents a line in a page of a quest, along with any text or images you want to show.</p>
{| class="wikitable"
! Key !! Datatype !! Description
|-
| text || {{D|i=string}} || the text for this line
|-
| color || {{D|i=string}} || [Optional] the color key for the text, defaults to "FONT_BOOK"
|-
| gif || {{D|i=string}} || [Optional] instead of text you can show a sprite by specifying the oid of the sprite. The sprite should have a width of 148 pixels and a height of either 46, 66, or 86 pixels.
|-
| width || {{D|i=integer}} || [Optional] if a gif is specified this sets the height of the gif, should be 46, 66, or 86
|}<br/>
<h2>recipe</h2>
<p>Represents a crafting recipe for the workbench.</p>
{| class="wikitable"
! Key !! Datatype !! Description
|-
| item || {{D|i=string}} || the item oid that this recipe will craft (see [[OID Reference]])
|-
| recipe || list({{D|i=ingredient}}) || the ingredients to use for this recipe
|-
| total || {{D|i=integer}} || [Optional] the total amount of the item you get when crafted, defaults to 1
|}<br/>
<h2>scripts</h2>
<p>Represents a set of script definitions to use when defining a custom menu object. Each script must be a valid function found in your {{I|i=mod.lua}} file.</p>
{| class="wikitable"
! Key !! Datatype !! Description
|-
| define || {{D|i=string}} || a script to run when the menu object is first defined, allowing you to set custom properties and stuff
|-
| change || {{D|i=string}} || a script to run when a slot inside the menu object gets changed
|-
| tick || {{D|i=string}} || a script to run every tick (0.1s) for that menu object, as long as it's active
|-
| draw || {{D|i=string}} || a script to run every draw cycle for this menu object, only when the object's menu is actually open
|}<br/>
<h2>stats</h2>
<p>All slots + items have a stats property that is used for certain items that need to store specific extra properties - this is used for all bee "items", but also for canisters and frames.<br>For bees, you can find the following properties from the stats property:</p>
{| class="wikitable"
! Key !! Datatype !! Description
|-
| species || {{D|i=string}} || the dominant species for the bee, i.e. {{I|i=common}}
|-
| queen || {{D|i=string}} || whether this bee is a queen or not
|-
| beetrice || {{D|i=boolean}} || whether this bee is a descendent of beetrice - the first bee you get from the book
|-
| microscoped || {{D|i=boolean}} || whether a bee has been microscoped (so people can't microscope the same bee 3 times)
|-
| shiny || {{D|i=boolean}} || whether this bee is a blessed variant
|-
| d_traits || {{D|i=table}} || this table contains a key for every bee trait with the bee's dominant value for that trait, keys included any custom defined traits through {{F|i=api_define_trait()}} as well as the following standard traits: {{I|i=species}}, {{I|i=lifespan}}, {{I|i=productivity}}, {{I|i=fertility}}, {{I|i=behaviour}}, {{I|i=climate}}, {{I|i=stability}}, {{I|i=pluvioplhile}}, {{I|i=chionophile}} and {{I|i=aggressive}}. Dominent traits are what determines how the bee acts in beehives.
|-
| r_traits || {{D|i=table}} || this table contains a key for every bee trait with the bee's recessive value for that trait, keys included any custom defined traits through {{F|i=api_define_trait()}} as well as the following standard traits: {{I|i=species}}, {{I|i=lifespan}}, {{I|i=productivity}}, {{I|i=fertility}}, {{I|i=behaviour}}, {{I|i=climate}}, {{I|i=stability}}, {{I|i=pluvioplhile}}, {{I|i=chionophile}} and {{I|i=aggressive}}.
|}
<p>For canisters, you can find the following properties from the stats property:</p>
{| class="wikitable"
! Key !! Datatype !! Description
|-
| type || {{D|i=string}} || the type of liquid in the canister, can be an empty string if empty or one of the following: {{I|i=water}}, {{I|i=resin}}, {{I|i=honey}}, or {{I|i=mead}}
|-
| amount || {{D|i=integer}} || the current amount in the canister
|-
| max || {{D|i=integer}} || the max amount this canister can hold
|}
<p>For frames, you can find the following properties from the stats property:</p>
{| class="wikitable"
! Key !! Datatype !! Description
|-
| filled || {{D|i=boolean}} || whether the frame has been filled from a hive
|-
| uncapped || {{D|i=boolean}} || whether the frame has been uncapped
|-
| flowers || {{D|i=string}} || a comma-separated list of flowers the bees who filled this frame visited
|-
| species || {{D|i=string}} || the species of bee that filled this frame
|-
| productivity || {{D|i=string}} || the dominant productivity trait value of the bee that filled this frame
|}<br/>
<h2>slot</h2>
<p>Represents a slot instance that is part of a parent menu. Slots can be blank or hold items in them.</p>
{| class="wikitable"
! Key !! Datatype !! Description
|-
| id || {{D|i=integer}} || the GMS id for this instance, to use in API methods
|-
| index || {{D|i=integer}} || the index of this slot within a menu based on the menu layout, starting at 1
|-
| item || {{D|i=string}} || if this slot holds an item, this will be the item oid, otherwise it'll be blank, i.e. {{I|i=""}} (see [[OID Reference]])
|-
| count || {{D|i=integer}} || if this slot holds a non-singular item, this will store the count of the slot
|-
| current_health || {{D|i=integer}} || if this slot holds an item with durability, this will be the current durability amount
|-
| total_health || {{D|i=integer}} || if this slot holds an item with durability, this will be the full durability amount
|-
| stats || {{D|i=stats}} || used by frames, canisters and bees (or anything you might have set manually)
|}<br/>
<h2>time</h2>
<p>Represents the current game time when retrieved through {{F|i=api_get_time}}.<br/>Dawn starts at 3am and ends at 7am. Dusk starts at 5pm and ends at 9pm.</p>
{| class="wikitable"
! Key !! Datatype !! Description
|-
| time || {{D|i=integer}} || the current time in the day, in ms. This is a number from 0 - 1440000.<br/>One hour in-game is 60000ms, or 1 minute.
|-
| day || {{D|i=integer}} || the current day that the player is on
|-
| name || {{D|i=string}} || the "name" for the time of day, either {{I|i=Day}}, {{I|i=Dawn}}, {{I|i=Dusk}}, or {{I|i=Night}}
|-
| clock || {{D|i=string}} || the current "clock" for the time of day, i.e. {{I|i=12:04}}
|}<br/>
<h2>wall_definition</h2>
<p>Represents a definition for a new wall. Walls can be placed down and picked up with a hammer.</p>
{| class="wikitable"
! Key !! Datatype !! Description
|-
| id || {{D|i=string}} || id to use to create an oid for this item, must be unique across all mods (i.e. wall90001)
|-
| name || {{D|i=string}} || the name of this item, shown in tooltips
|-
| shop_buy || {{D|i=boolean}} || [Optional] the amount this item can be bought for if sold by an NPC
|-
| shop_sell || {{D|i=boolean}} || [Optional] the amount this item can be sold for at an NPC
|}<br/>
<h2>window_definition</h2>
<p>Represents a definition for a new window. Windows can be placed on walls and picked up with a hammer.</p>
{| class="wikitable"
! Key !! Datatype !! Description
|-
| id || {{D|i=string}} || id to use to create an oid for this item, must be unique across all mods (i.e. window90001)
|-
| name || {{D|i=string}} || the name of this item, shown in tooltips
|-
| shop_buy || {{D|i=boolean}} || [Optional] the amount this item can be bought for if sold by an NPC
|-
| shop_sell || {{D|i=boolean}} || [Optional] the amount this item can be sold for at an NPC
|}<br/>
<h2>weather</h2>
<p>Represents the current weather when retrieved through {{F|i=api_get_weather}}. Weather is simply either on or off - the weather effects shown are based on the biome the player is currently in.<br/>Weather is decided at the start of a new day, with a 30% chance every day after Day 4 (or 100% chance if currently in a swamp biome)</p>
{| class="wikitable"
! Key !! Datatype !! Description
|-
| active || {{D|i=boolean}} || whether weather is current "on" or not
|-
| start_time || {{D|i=integer}} || the time weather will start today, in ms
|-
| end_time || {{D|i=integer}} || the time weather will end today, in ms
|}
</div>
</div><br/>
<div class="aw-api-section mw-customcollapsible-s1">
<h1>[[File:Standard_Boat_Item.png|32px]]Hooks</h1>
<p>Hooks are special functions that allow you to hook into different processes as well as let you actually register and setup your mod. When you register your mod you can specify the hooks you want to apply.<br/>Both {{H|i=register()}} and {{H|i=init()}} are required for your mod to run.<br/>You can only have one function for each hook (i.e. you can't have two "click()" hooks).</p>
{| class="wikitable"
! Hook !! Description
|-
| {{H|i=click()}} || this hook is called whenever the player clicks on something with the mouse (or uses "action" on a gamepad)
|-
| {{H|i=clock()}} || this hook is called every 1s of real-time
|-
| {{H|i=create()}} || this hook is a called whenever an object (tree, flower, generic object, menu object) or item is created
|-
| {{H|i=data()}} || this hook is a callback used whenever you call {{F|i=api_get_data()}} or {{F|i=api_set_data()}} due to file load being async
|-
| {{H|i=destroy()}} || this hook is a called whenever an object (tree, flower, generic object, menu object) is destroyed
|-
| {{H|i=draw()}} || this hook is called every draw cycle, on the overworld layer (above objects)
|-
| {{H|i=gui()}} || this hook is called every draw cycle, on the gui layer
|-
| {{H|i=http()}} || this hook is called when a HTTP response is returned from {{F|i=api_http_request()}}
|-
| {{H|i=init()}} || this hook is called when the mod is first initialised, allowing you to setup mod code for the first time
|-
| {{H|i=key()}} || this hook is called whenever a key is pressed
|-
| {{H|i=pdraw()}} || this hook is called every draw cycle, on the player layer
|-
| {{H|i=ready()}} || this hook is called when all mods have been both registered and initialised and after all objects are loaded in
|-
| {{H|i=register()}} || this hook is called first to register the mod with a unique name and setup required hooks
|-
| {{H|i=save()}} || this hook is called whenever the player saves or the autosave is called
|-
| {{H|i=scroll()}} || this hook is called when the mouse wheel is scrolled
|-
| {{H|i=tdraw()}} || this hook is called every draw cycle, on the overworld layer (above tiles but below objects)
|-
| {{H|i=tick()}} || this hook is called ever 0.1s of real time
|-
| {{H|i=worldgen()}} || this hook is called after the initial world generation is complete but the world hasn't been fully processed, letting you add to the world
|}
<div class="mw-collapsible mw-collapsed" id="mw-customcollapsible-s1">
<h2>click()</h2>
<p>This hook is called whenever a player clicks on something with the mouse or uses the "action" button on their gamepad. You can find out what key was pressed with the {{F|i=api_get_key_down()}} or {{F|i=api_get_key_pressed()}} methods.<br/>As this is a single hook for the whole mod you'll probably want to split out the calls within this method to other modules to keep things manageable.</p>
<p>This hook is called with the following parameters:</p>
{| class="wikitable"
! Parameter !! Datatype !! Description
|-
| button || {{D|i=string}} || the button of the mouse, will be {{I|i=LEFT}}, {{I|i=RIGHT}} or {{I|i=MIDDLE}}
|-
| click_type || {{D|i=string}} || the type of click, will be {{I|i=PRESSED}} or {{I|i=RELEASED}},
|}
<p>Example code to do something if a player clicks on a tree:</p>
<syntaxhighlight lang="lua">
function click()
highlighted = api_get_highlighted("obj")
if highlighted ~= nil then
inst = api_get_inst(highlighted)
if inst["oid"] == true then
-- do something with the trees
end
end
end
</syntaxhighlight><br/>
<h2>clock()</h2>
<p>This hook is called every 1s of real time by the game. You can use this to handle any general time related logic you need.</p>
<p>Example code to give the player 1 log every second:</p>
<syntaxhighlight lang="lua">
function clock()
api_give_item("log", 1)
end
</syntaxhighlight><br/>
<h2>create()</h2>
<p>This hook is called whenever an item, tree, flower, generic object, or menu object is destroyed. This will happen for all created items so be sure to be filtering out your logic by specific oid / type!<br/><b>As items can be picked up sometimes immedietely you should be careful on modifying items through this hook as the item may already have been destroyed (i.e. picked up)</b></p>
{| class="wikitable"
! Parameter !! Datatype !! Description
|-
| id || {{D|i=integer}} || the instance id of the inst that just got destroyed
|-
| x || {{D|i=integer}} || the x position of the inst that just go destroyed
|-
| y || {{D|i=integer}} || the y position of the inst that just go destroyed
|-
| oid|| {{D|i=string}} || the oid of the inst that just go destroyed (see [[OID Reference]])
|-
| inst_type || {{D|i=string}} || the "type" of inst created, can be one of the following: {{I|i=tree}}, {{I|i=flower}}, {{I|i=obj}}, {{I|i=menu_obj}}, or {{I|i=item}}
|}
<p>Example code to drop a custom item whenever a tree is chopped down:</p>
<syntaxhighlight lang="lua">
function create(id, x, y, oid, inst_type)
-- whenever a tree is created (i.e. growing from a sapling)
-- turn it into skipper
if oid == "tree" and inst_type == "tree" then
api_create_obj("npc1", x, y)
api_destroy_inst(id)
end
end
</syntaxhighlight><br/>
<h2>data()</h2>
<p>This hook is called whenever you call the {{F|i=api_get_data()}} or {{F|i=api_set_data()}} methods, as file loading is asynchronous.<br/>Each mod has it's own dedicated JSON file that you can read and write to through the API to avoid direct file access.</p>
{| class="wikitable"
! Parameter !! Datatype !! Description
|-
| ev || {{D|i=string}} || the type of data event, either {{I|i=SAVE}} or {{I|i=SAVE}} depending on which method you used
|-
| data || {{D|i=string}} or {{D|i=table}} || if a {{I|i=SAVE}} type, will return {{I|i=Success}}, otherwise if a {{I|i=LOAD}} type this parameter will contain your JSON file data as a table
|}
<p>Example code to load the mod datafile during {{H|i=init()}} and access the data:</p>
<syntaxhighlight lang="lua">
function init()
-- get our data file
api_get_data()
end
function data(ev, data)
if ev == "LOAD" and data ~= nil then
-- do something with our data
val = data["value"]
end
end
</syntaxhighlight><br/>
<h2>destroy()</h2>
<p>This hook is called whenever a tree, flower, generic object, or menu object is destroyed.<br/>While you will be passed the instance ID of the instance destroyed, this instance will no longer exist so you cannot use methods like {{F|i=api_get_data()}} or {{F|i=api_set_data()}}.</p>
{| class="wikitable"
! Parameter !! Datatype !! Description
|-
| id || {{D|i=integer}} || the instance id of the inst that just got destroyed
|-
| x || {{D|i=integer}} || the x position of the inst that just go destroyed
|-
| y || {{D|i=integer}} || the y position of the inst that just go destroyed
|-
| oid|| {{D|i=string}} || the oid of the inst that just go destroyed (see [[OID Reference]])
|}
<p>Example code to drop a custom item whenever a tree is chopped down:</p>
<syntaxhighlight lang="lua">
function destroy(id, x, y, oid)
-- if tree was destroyed, drop an item
if oid == "tree" then
api_create_item("my_new_obj", 10, x, y)
end
end
</syntaxhighlight><br/>
<h2>draw()</h2>
<p>This hook is called every in-game draw cycle. This hook allows you to use the various Draw Methods to draw stuff every cycle.<br/>This hook will draw items to the overworld layer - if you want to draw ontop of menus / UI you'll need to use the {{H|i=gui()}} hook instead.</p>
<p>Example code to draw some text above the player:</p>
<syntaxhighlight lang="lua">
function draw()
-- get position
player_pos = api_get_player_position()
cam_pos = api_get_cam()
px = player_pos["x"] - cam_pos["x"]
py = player_pos["y"] - cam_pos["y"]
-- draw some text
api_draw_text(px, py, "Hello World!", true)
end
</syntaxhighlight><br/>
<h2>gui()</h2>
<p>This hook is called every in-game draw cycle and, like {{H|i=draw()}} hook, this hook allows you to use the various Draw Methods to draw stuff every cycle.<br/>This hook will draw items to the GUI layer on top of everything else. If you want to draw underneath menus you need to use {{H|i=draw()}} instead.</p>
<p>Example code to draw a black circle on top of everything:</p>
<syntaxhighlight lang="lua">
function gui()
-- get position
cam_pos = api_get_cam()
px = player_pos["x"] - cam_pos["x"]
py = player_pos["y"] - cam_pos["y"]
-- draw a circle
api_draw_circle(px, py, 100, false, "BLACK")
end
</syntaxhighlight><br/>
<h2>http()</h2>
<p>This hook is called every time a HTTP response is returned by {{F|i=api_http_request()}}.<br/>This hook returns regardless of whether the HTTP request succeeded or failed.</p>
{| class="wikitable"
! Parameter !! Datatype !! Description
|-
| response_id || {{D|i=string}} || the string you set in your {{F|i=api_http_request()}} method to help you identify the callback
|-
| status || {{D|i=string}} || returns either "Success" or "Error" depending on the HTTP status returned
|-
| response || {{D|i=string}} || response body returned from the HTTP request
|}
<p>Example code to handle some random HTTP call to get the APICO website homepage:</p>
<syntaxhighlight lang="lua">
-- call our HTTP req whereever we like
function init()
api_http_request("https://apico.buzz", "GET", {}, "", "my_request")
return "Success"
end
-- http requests are async so you'll need the http() hook to handle the response
function http(response_id, status, response)
-- check the response_id and status before handling the response body
if response_id == "my_request" and status == "Success" then
api_log("http", response)
end
end
</syntaxhighlight><br/>
<h2>init()</h2>
<p>An extremely important and required hook which is called after your mod is registered. This is a chance for you to setup anything you need for your mod straight away, like defining different items and objects or setting up mod globals.<br/>If your mod doesn't have an {{H|i=init()}} hook it will not be loaded.<br/>This hook is called before any mod objects might be loaded so you should use {{H|i=ready()}} if you want to get any mod objects that might have been saved.</p>
<p>Your {{H|i=init()}} hook should return {{I|i=Success}} if things went well, or an error message to be shown in the Modding Console.</p>
<p>Example code to define a global color when the mod is initialised:</p>
<syntaxhighlight lang="lua">
global_color = 0
function init()
-- create a new color, if it fails return an error so the mod load is aborted
global_loaded = api_define_color("super_green", {r=0,b=0,g=255})
if global_loaded == nil then return "Error: Couldn't create custom color" end
-- otherwise if all was a success tell the game we're good so it carries on loading our mod
return "Success"
end
</syntaxhighlight><br/>
<h2>key()</h2>
<p>This hook is called whenever a key is pressed. You can use {{F|i=api_get_key_down}} or {{F|i=api_get_key_pressed}} to find out what key/s are being pressed.</p>
{| class="wikitable"
! Parameter !! Datatype !! Description
|-
| key_code || {{D|i=integer}} || the [[Key Codes|keycode]] of the key that was pressed to trigger this event
|}
<p>Example code to run an action when the player presses the spacebar:</p>
<syntaxhighlight lang="lua">
function key(key_code)
if key_code == 32 then
-- spacebar has been pressed!
end
end
</syntaxhighlight><br/>
<h2>pdraw()</h2>
<p>This hook is called every in-game draw cycle. This hook allows you to use the various Draw Methods to draw stuff every cycle.<br/>This hook will draw items to the player layer - this means anything you draw will be on top of the player but at the correct depth (behind trees/walls etc).</p>
<p>Example code to draw some text above the player:</p>
<syntaxhighlight lang="lua">
function draw()
-- get position
-- note we dont need to add the camera offset as we are calling this hook from the players own draw cycle
player_pos = api_get_player_position()
px = player_pos["x"]
py = player_pos["y"]
-- draw some text
api_draw_text(px, py, "Player Name!", true)
end
</syntaxhighlight><br/>
<h2>ready()</h2>
<p>This hook is called when all mods have been both registered and initialised. If your mod relies on another mod or just wants to know when everything is ready then it can listen for this event.<br/>This event is called after all world objects are loaded in, including mod objects, and is called right as the player is able to control themselves.</p>
<p>Example code to run a function from another mod after all mods have loaded:</p>
<syntaxhighlight lang="lua">
function ready()
-- check mod exists first
if api_mod_exists("my_other_mod") then
-- call a method from the other mod
api_mod_call("my_other_mod", "some_method", {"param1", "param2"})
end
end
</syntaxhighlight><br/>
<h2>register()</h2>
<p>This is the most important hook as it's called first by the game to register your mod and setup the hooks you want. KISS with this one, don't put any other logic in this method - save that for {{H|i=init()}} or {{H|i=ready()}}.</p>
<p>Your {{H|i=register()}} hook should return a table with the following values:</p>
{| class="wikitable"
! Parameter !! Datatype !! Description
|-
| name || {{D|i=string}} || the unique name of your mod
|-
| hooks || list({{D|i=string}}) || a list of hooks you want your mod to subscribe too, i.e. {{I|i=<nowiki>{"click", "clock"}</nowiki>}}. You do not need to specify "register" or "init" as they are required.
|-
| modules || list({{D|i=string}}) || a list of "modules" you want your mod to load. These should be the names of .lua files within a folder called "modules" at the root of your mod. All mod files will be loaded into one single file so any scripts or globals in each file will be accessible from each other.
|}
<p>Example code to register "sample_mod" and subscribe to the {{H|i=clock()}} and {{H|i=tick()}} hooks</p>
<syntaxhighlight lang="lua">
function register()
return {
name = "sample_mod",
hooks = {"clock", "tick"},
modules = {"define"} -- will load /modules/define.lua (if it exists)
}
end
</syntaxhighlight><br/>
<h2>save()</h2>
<p>This hook is called whenever the player manually saves or the game autosaves, to give you a chance to save your mod file if you need to.</p>
<p>Example code to update the mod datafile when the game saves:</p>
<syntaxhighlight lang="lua">
-- fake mod data table
global_data = {
data = "my data",
times_saved = 0
}
-- hook into the save event
function save()
-- log to the console to check that save is called
api_log("save", "Save called!")
-- increment a value and save new data
global_data["times_saved"] = global_data["times_saved"] + 1
api_set_data(global_data)
end
-- handle the async callback
function data(ev, data)
if ev == "SAVE" and data ~= nil then
api_log("save", "Save complete!")
end
end
</syntaxhighlight><br/>
<h2>scroll()</h2>
<p>This hook is called whenever the mouse wheel is scrolled</p>
{| class="wikitable"
! Parameter !! Datatype !! Description