From 4f9e9d9a6e8305a4afc26de61114ad7a7ba920b5 Mon Sep 17 00:00:00 2001 From: luk3yx Date: Wed, 19 Feb 2025 12:01:35 +1300 Subject: [PATCH] Document on_quit as an experimental feature --- README.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/README.md b/README.md index beecb1a..a6d5c5a 100644 --- a/README.md +++ b/README.md @@ -597,4 +597,29 @@ end) Special characters (excluding `-` and `_`) are not allowed in embed names. +
+Running code when a form is closed + +`gui.Container`, `gui.HBox`, `gui.VBox`, and `gui.Stack` elements support an +`on_quit` callback which gets run when a player closes a form. + +Note that this function is not called in some cases, such as when the player +leaves without closing the form or when another form/formspec is shown. + +This function must not return anything, behaviour may get added to return +values in the future. + +```lua +local parent_form = flow.make_gui(function(player, ctx) + return gui.VBox{ + on_quit = function(player, ctx) + core.chat_send_player(player:get_player_name(), "Form closed!") + end, + } +end) +``` + +If multiple `on_quit` callbacks are specified in different elements, they will +all get called. +