Fix typos in API.md

master
Wuzzy 2018-05-28 20:04:20 +02:00
parent cb30d34fb1
commit d2baa93992
1 changed files with 19 additions and 14 deletions

33
API.md
View File

@ -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)