Make callback on cancel

This commit is contained in:
Wuzzy 2018-05-17 14:10:36 +02:00
parent 852a34c011
commit b2e2075872
2 changed files with 5 additions and 4 deletions

7
API.md
View File

@ -38,15 +38,16 @@ You can also choose one of the following pre-defined filter functions:
### `select_item.register_on_select_item(callback)`
Register a call function `callback` to the `select_item` mod.
Whenever a player selects an item, `callback` is called.
Whenever a player selects an item or cancels the selection,
`callback` is called.
#### `callback` function
This has the function signature `callback(playername, itemstring)`.
* `playername` is the name of the player who selected the item,
* `itemstring` is the itemstring of the chosen item.
* `itemstring` is the itemstring of the chosen item or `nil` if aborted
Normally, if the player pushes a button, the formspec is closed.
Normally, if the player pushes any button, the formspec is closed.
But if you return `false` in this callback, the formspec is *not*
Use this when you run into problems.

View File

@ -154,7 +154,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
break
end
end
if item then
if item or fields.quit then
local close = true
for i=1,#callbacks do
local ret = callbacks[i](playername, item)