From 1f2638952c7ba8bc7d466738186ee2c80ac4b074 Mon Sep 17 00:00:00 2001 From: Samantha Grey <49354894+sammygrey@users.noreply.github.com> Date: Sun, 25 May 2025 13:17:09 -0400 Subject: [PATCH 1/4] Update LuaGlobals.yaml Added an example function for usage of pcall() --- content/en-us/reference/engine/globals/LuaGlobals.yaml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/content/en-us/reference/engine/globals/LuaGlobals.yaml b/content/en-us/reference/engine/globals/LuaGlobals.yaml index b2900cbbf..47b5fac29 100644 --- a/content/en-us/reference/engine/globals/LuaGlobals.yaml +++ b/content/en-us/reference/engine/globals/LuaGlobals.yaml @@ -346,6 +346,15 @@ functions: errors. In such case, `pcall()` also returns all results from the call, after this first result. In case of any error, `pcall()` returns false plus the error message. + + ```lua + local function divideByFive(n: number) + return n / 5 + end + + local success, response = pcall(divideByFive, "ten") + print(success, response) + ``` parameters: - name: func type: function From d270c5ef154ed6f588998dd6da5e9f4dcf00a77d Mon Sep 17 00:00:00 2001 From: Samantha Grey <49354894+sammygrey@users.noreply.github.com> Date: Sun, 25 May 2025 13:19:54 -0400 Subject: [PATCH 2/4] Update LuaGlobals.yaml --- content/en-us/reference/engine/globals/LuaGlobals.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/en-us/reference/engine/globals/LuaGlobals.yaml b/content/en-us/reference/engine/globals/LuaGlobals.yaml index 47b5fac29..0e3b479a7 100644 --- a/content/en-us/reference/engine/globals/LuaGlobals.yaml +++ b/content/en-us/reference/engine/globals/LuaGlobals.yaml @@ -348,7 +348,7 @@ functions: plus the error message. ```lua - local function divideByFive(n: number) + local function divideByFive(n) return n / 5 end From 7acdbb7155f7e38e7996d82035328d4d95d0d9bb Mon Sep 17 00:00:00 2001 From: Samantha Grey <49354894+sammygrey@users.noreply.github.com> Date: Mon, 26 May 2025 22:22:33 -0400 Subject: [PATCH 3/4] Update LuaGlobals.yaml added the suggested example code by @junveld This problem was brought to my attention by them and I believe their example code works for the suggested usecase. --- .../en-us/reference/engine/globals/LuaGlobals.yaml | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/content/en-us/reference/engine/globals/LuaGlobals.yaml b/content/en-us/reference/engine/globals/LuaGlobals.yaml index 0e3b479a7..0c9a3f2f4 100644 --- a/content/en-us/reference/engine/globals/LuaGlobals.yaml +++ b/content/en-us/reference/engine/globals/LuaGlobals.yaml @@ -348,12 +348,17 @@ functions: plus the error message. ```lua - local function divideByFive(n) + local function divideByFive(n: number): number return n / 5 end - local success, response = pcall(divideByFive, "ten") - print(success, response) + local success, response = pcall(divideByFive, "notANumber") -- results in error + + if success then + -- handle successful response ... + else + warn("Error message: " .. response) + end ``` parameters: - name: func From e4bd25bc138c2756e8e248fc515cb2d522eff43c Mon Sep 17 00:00:00 2001 From: IgnisRBX <43388550+IgnisRBX@users.noreply.github.com> Date: Mon, 2 Jun 2025 09:08:32 -1000 Subject: [PATCH 4/4] Update content/en-us/reference/engine/globals/LuaGlobals.yaml --- content/en-us/reference/engine/globals/LuaGlobals.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/content/en-us/reference/engine/globals/LuaGlobals.yaml b/content/en-us/reference/engine/globals/LuaGlobals.yaml index 0c9a3f2f4..4725fec00 100644 --- a/content/en-us/reference/engine/globals/LuaGlobals.yaml +++ b/content/en-us/reference/engine/globals/LuaGlobals.yaml @@ -349,15 +349,15 @@ functions: ```lua local function divideByFive(n: number): number - return n / 5 + return n / 5 end - local success, response = pcall(divideByFive, "notANumber") -- results in error + local success, errorMessage = pcall(divideByFive, "notANumber") -- Results in error... if success then - -- handle successful response ... + -- Handle successful response... else - warn("Error message: " .. response) + warn("Error message:", errorMessage) end ``` parameters: