Remove debug statement and add documentation.

This commit is contained in:
luk3yx 2019-08-11 15:59:26 +12:00
parent bfc60f6dba
commit 5e9f0c8150
2 changed files with 31 additions and 3 deletions

View File

@ -29,6 +29,37 @@ More documentation coming soon.
inside an "anonymous snippet" owned by the player.
- `snippets.exec(code)`: Executes `code` inside a generic snippet.
- `snippets.run(name, ...)`: Executes a snippet.
- `snippets.Form(player_or_name)`: Creates a form.
### Forms
`snippets.Form`s can display and handle formspecs, and are recommended inside
snippets over `minetest.show_formspec`, as they do not create semi-permanent
global handlers. There is currently no way to set the `formname`, it is
automatically chosen/generated and is used internally.
Form methods:
- `form:show()` / `form:open()`: Displays the form.
- `form:hide()` / `form:close()`: Closes the form.
- `form:set_prepend(formspec)`: Sets text to prepend to the formspec. This has
nothing to do with global formspec prepends.
- `form:set_formspec(formspec)`: Sets the formspec text. This does not modify
prepended text or appended text. Any change to this (or the prepend/append
values) is displayed immediately to the client.
- `form:set_append(formspec)`: Sets text to append to the formspec before
displaying it.
- `form:get_prepend`, `form:get_formspec`, `form:get_append`
- `form:add_callback(function(form, fields))`: This creates a callback which
is called whenever form data is received from the client.
- `form:add_callback(name, function(form, fields))`: Similar to the above,
however is only called if `fields` contains `name` (a string).
- `form.context`: Private data stored with this `form` object. Not sent to
clients.
- `form.pname`: The player name associated with this form.
*When a form is deleted (`form=nil`) and it is not open by the client, garbage
collection will allow the internal `formname` to be reused.*
## Example snippets

View File

@ -49,13 +49,10 @@ function minetest.show_formspec(pname, ...)
end
-- Show formspecs
local print = print
function Form:show()
local data = get(self)
if not get_player_by_name(data.victim) then return false end
open_formspecs[data.victim] = self
print('show_formspec', data.victim, data.formname,
data.prepend .. data.formspec .. data.append)
show_formspec(data.victim, data.formname,
data.prepend .. data.formspec .. data.append)
return true