From d2baa93992ff69f5ec69c9f44081636569ea158f Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Mon, 28 May 2018 20:04:20 +0200 Subject: [PATCH] Fix typos in API.md --- API.md | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/API.md b/API.md index 1bd8291..6853099 100644 --- a/API.md +++ b/API.md @@ -12,12 +12,14 @@ Shows an item selection dialog to a player. The player can choose one item (which triggers a callback) or abort selection (in which case nothing happens). -By default, this displays almost all items with the exception of -unknown items and `ignore`. This also includes items which players -may normally not be supposed to see, especially those not -found in Creative Inventory. You should set the `filter` argument +By default, this displays all items with the exception of unknown +items and `ignore`. This also includes items which players may +normally not be supposed to see, like those usually not found in +so-called “creative inventories”. You should set the `filter` argument to filter out unwanted items. +The items are also sorted by a sorting rule. + #### Parameters * `playername`: Name of player to show dialog to * `dialogname`: Identifier of the dialog (must not contain “%%”) @@ -35,10 +37,10 @@ moves items with empty description to the end, preceded by items with description, but `not_in_creative_inventory=1`, and then everything else to the beginning. -#### Filter function +##### Filter function The filter function has the function signature `filter(itemstring)`. This function will be called for each item with the itemstring -given as argument. The function shall return `true` if the item +given as argument. The function must return `true` if the item in question is allowed in the selection dialog and `false` if it must not appear. @@ -56,23 +58,25 @@ Whenever a player selects an item or cancels the selection, #### `callback` function This has the function signature `callback(playername, dialogname, itemstring)`. -* `playername` is the name of the player who selected the item, -* `dialogname` is the dialog identifier of the used item selection dialog +* `playername` is the name of the player who selected the item +* `dialogname` is the dialog identifier of the item selection dialog being used * `itemstring` is the itemstring of the chosen item or `nil` if aborted Normally, if the player pushes any button, the formspec is closed. -But if you return `false` in this callback, the formspec is *not* +But if you return `false` in this callback, the formspec is *not* closed. ## Examples -Display all items from Creative inventory to player 1: +Display all items from Creative inventory to Player 1: + ``` select_item.show_dialog("Player 1", "example:creative", select_item.filters.creative) ``` Display all flammable to Player 1: + ``` select_item.show_dialog("Player 1", "example:flammable", function(itemstring) - if minetest.get_item_group(itemstring), "flammable") >= 1 then + if minetest.get_item_group(itemstring, "flammable") >= 1 then return true else return false @@ -84,12 +88,13 @@ Note the different values for `dialogname`. Adding a selected to the player's inventory after player selected item in the “Creative” dialog above: + ``` select_item.register_on_select_item(function(playername, dialogname, itemstring) - -- Check for the dialog type you care about. This check should almost always be done - -- to ensure interopability with other mods. + --[[ Check for the dialog type you care about. This check should almost always be done + to ensure interoperability with other mods. ]] if dialogname == "example:creative" then - local inv = minetest.get_inventory({type="player" location=playername}) + local inv = minetest.get_inventory({type="player", location=playername}) inv:add_item("main", ItemStack(itemstring)) end end)