Rename moveresult speed to velocity
[oweals/minetest.git] / doc / menu_lua_api.txt
1 Minetest Lua Mainmenu API Reference 5.3.0
2 =========================================
3
4 Introduction
5 -------------
6 The main menu is defined as a formspec by Lua in builtin/mainmenu/
7 Description of formspec language to show your menu is in lua_api.txt
8
9 Callbacks
10 ---------
11 core.buttonhandler(fields): called when a button is pressed.
12 ^ fields = {name1 = value1, name2 = value2, ...}
13 core.event_handler(event)
14 ^ event: "MenuQuit", "KeyEnter", "ExitButton" or "EditBoxEnter"
15
16 Gamedata
17 --------
18 The "gamedata" table is read when calling core.start(). It should contain:
19 {
20         playername     = <name>,
21         password       = <password>,
22         address        = <IP/adress>,
23         port           = <port>,
24         selected_world = <index>, -- 0 for client mode
25         singleplayer   = <true/false>,
26 }
27
28 Functions
29 ---------
30 core.start()
31 core.close()
32
33 Filesystem:
34 core.get_builtin_path()
35 ^ returns path to builtin root
36 core.create_dir(absolute_path) (possible in async calls)
37 ^ absolute_path to directory to create (needs to be absolute)
38 ^ returns true/false
39 core.delete_dir(absolute_path) (possible in async calls)
40 ^ absolute_path to directory to delete (needs to be absolute)
41 ^ returns true/false
42 core.copy_dir(source,destination,keep_soure) (possible in async calls)
43 ^ source folder
44 ^ destination folder
45 ^ keep_source DEFAULT true --> if set to false source is deleted after copying
46 ^ returns true/false
47 core.extract_zip(zipfile,destination) [unzip within path required]
48 ^ zipfile to extract
49 ^ destination folder to extract to
50 ^ returns true/false
51 core.download_file(url,target) (possible in async calls)
52 ^ url to download
53 ^ target to store to
54 ^ returns true/false
55 core.get_version() (possible in async calls)
56 ^ returns current core version
57 core.sound_play(spec, looped) -> handle
58 ^ spec = SimpleSoundSpec (see lua-api.txt)
59 ^ looped = bool
60 core.sound_stop(handle)
61 core.get_video_drivers()
62 ^ get list of video drivers supported by engine (not all modes are guaranteed to work)
63 ^ returns list of available video drivers' settings name and 'friendly' display name
64 ^ e.g. { {name="opengl", friendly_name="OpenGL"}, {name="software", friendly_name="Software Renderer"} }
65 ^ first element of returned list is guaranteed to be the NULL driver
66 core.get_mapgen_names([include_hidden=false]) -> table of map generator algorithms
67     registered in the core (possible in async calls)
68 core.get_cache_path() -> path of cache
69
70 Formspec:
71 core.update_formspec(formspec)
72 core.get_table_index(tablename) -> index
73 ^ can also handle textlists
74 core.formspec_escape(string) -> string
75 ^ escapes characters [ ] \ , ; that can not be used in formspecs
76 core.explode_table_event(string) -> table
77 ^ returns e.g. {type="CHG", row=1, column=2}
78 ^ type: "INV" (no row selected), "CHG" (selected) or "DCL" (double-click)
79 core.explode_textlist_event(string) -> table
80 ^ returns e.g. {type="CHG", index=1}
81 ^ type: "INV" (no row selected), "CHG" (selected) or "DCL" (double-click)
82 core.set_formspec_prepend(formspec)
83 ^ string to be added to every mainmenu formspec, to be used for theming.
84
85 GUI:
86 core.set_background(type, texturepath,[tile],[minsize])
87 ^ type: "background", "overlay", "header" or "footer"
88 ^ tile: tile the image instead of scaling (background only)
89 ^ minsize: minimum tile size, images are scaled to at least this size prior
90 ^   doing tiling (background only)
91 core.set_clouds(<true/false>)
92 core.set_topleft_text(text)
93 core.show_keys_menu()
94 core.show_path_select_dialog(formname, caption, is_file_select)
95 ^ shows a path select dialog
96 ^ formname is base name of dialog response returned in fields
97 ^     -if dialog was accepted "_accepted"
98 ^        will be added to fieldname containing the path
99 ^     -if dialog was canceled "_cancelled"
100 ^        will be added to fieldname value is set to formname itself
101 ^ if `is_file_select` is `true`, a file and not a folder will be selected
102 ^ returns nil or selected file/folder
103 core.get_screen_info()
104 ^ returns {
105         density         = <screen density 0.75,1.0,2.0,3.0 ... (dpi)>,
106         display_width   = <width of display>,
107         display_height  = <height of display>,
108         window_width    = <current window width>,
109         window_height   = <current window height>
110         }
111
112 ### Content and Packages
113
114 Content - an installed mod, modpack, game, or texture pack (txt)
115 Package - content which is downloadable from the content db, may or may not be installed.
116
117 * core.get_modpath() (possible in async calls)
118         * returns path to global modpath
119 * core.get_clientmodpath() (possible in async calls)
120         * returns path to global client-side modpath
121 * core.get_gamepath() (possible in async calls)
122         * returns path to global gamepath
123 * core.get_texturepath() (possible in async calls)
124         * returns path to default textures
125 * core.get_game(index)
126         * returns:
127
128                 {
129                         id               = <id>,
130                         path             = <full path to game>,
131                         gamemods_path    = <path>,
132                         name             = <name of game>,
133                         menuicon_path    = <full path to menuicon>,
134                         author           = "author",
135                         DEPRECATED:
136                         addon_mods_paths = {[1] = <path>,},
137                 }
138
139 * core.get_games() -> table of all games in upper format (possible in async calls)
140 * core.get_content_info(path)
141         * returns
142
143                 {
144                         name             = "name of content",
145                         type             = "mod" or "modpack" or "game" or "txp",
146                         description      = "description",
147                         author           = "author",
148                         path             = "path/to/content",
149                         depends          = {"mod", "names"}, -- mods only
150                         optional_depends = {"mod", "names"}, -- mods only
151                 }
152
153
154 Favorites:
155 core.get_favorites(location) -> list of favorites (possible in async calls)
156 ^ location: "local" or "online"
157 ^ returns {
158         [1] = {
159                 clients       = <number of clients/nil>,
160                 clients_max   = <maximum number of clients/nil>,
161                 version       = <server version/nil>,
162                 password      = <true/nil>,
163                 creative      = <true/nil>,
164                 damage        = <true/nil>,
165                 pvp           = <true/nil>,
166                 description   = <server description/nil>,
167                 name          = <server name/nil>,
168                 address       = <address of server/nil>,
169                 port          = <port>
170                 clients_list  = <array of clients/nil>
171                 mods          = <array of mods/nil>
172         },
173         ...
174 }
175 core.delete_favorite(id, location) -> success
176
177 Logging:
178 core.debug(line) (possible in async calls)
179 ^ Always printed to stderr and logfile (print() is redirected here)
180 core.log(line) (possible in async calls)
181 core.log(loglevel, line) (possible in async calls)
182 ^ loglevel one of "error", "action", "info", "verbose"
183
184 Settings:
185 core.settings:set(name, value)
186 core.settings:get(name) -> string or nil (possible in async calls)
187 core.settings:set_bool(name, value)
188 core.settings:get_bool(name) -> bool or nil (possible in async calls)
189 core.settings:save() -> nil, save all settings to config file
190
191 For a complete list of methods of the Settings object see
192 [lua_api.txt](https://github.com/minetest/minetest/blob/master/doc/lua_api.txt)
193
194 Worlds:
195 core.get_worlds() -> list of worlds (possible in async calls)
196 ^ returns {
197         [1] = {
198         path   = <full path to world>,
199         name   = <name of world>,
200         gameid = <gameid of world>,
201         },
202 }
203 core.create_world(worldname, gameid)
204 core.delete_world(index)
205
206 Helpers:
207 core.get_us_time()
208 ^ returns time with microsecond precision
209 core.gettext(string) -> string
210 ^ look up the translation of a string in the gettext message catalog
211 fgettext_ne(string, ...)
212 ^ call core.gettext(string), replace "$1"..."$9" with the given
213 ^ extra arguments and return the result
214 fgettext(string, ...) -> string
215 ^ same as fgettext_ne(), but calls core.formspec_escape before returning result
216 core.parse_json(string[, nullvalue]) -> something (possible in async calls)
217 ^ see core.parse_json (lua_api.txt)
218 dump(obj, dumped={})
219 ^ Return object serialized as a string
220 string:split(separator)
221 ^ eg. string:split("a,b", ",") == {"a","b"}
222 string:trim()
223 ^ eg. string.trim("\n \t\tfoo bar\t ") == "foo bar"
224 core.is_yes(arg) (possible in async calls)
225 ^ returns whether arg can be interpreted as yes
226 minetest.encode_base64(string) (possible in async calls)
227 ^ Encodes a string in base64.
228 minetest.decode_base64(string) (possible in async calls)
229 ^ Decodes a string encoded in base64.
230
231 Version compat:
232 core.get_min_supp_proto()
233 ^ returns the minimum supported network protocol version
234 core.get_max_supp_proto()
235 ^ returns the maximum supported network protocol version
236
237 Async:
238 core.handle_async(async_job,parameters,finished)
239 ^ execute a function asynchronously
240 ^ async_job is a function receiving one parameter and returning one parameter
241 ^ parameters parameter table passed to async_job
242 ^ finished function to be called once async_job has finished
243 ^    the result of async_job is passed to this function
244
245 Limitations of Async operations
246  -No access to global lua variables, don't even try
247  -Limited set of available functions
248         e.g. No access to functions modifying menu like core.start,core.close,
249         core.show_path_select_dialog
250
251 Background music
252 ----------------
253 The main menu supports background music.
254 It looks for a `main_menu` sound in `$USER_PATH/sounds`. The same naming
255 conventions as for normal sounds apply.
256 This means the player can add a custom sound.
257 It will be played in the main menu (gain = 1.0), looped.