Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

What does the parameter of Pcall Do I don't understand where it saids func,tuple args?

Asked by 5 years ago
Edited 5 years ago

So I stumbled across the parameters of PCALL and wondered how I can use it

it saids first parameter is function and the other one is a tuple

but I don't have a idea on how to use it

For Example

local DataStoreService = game:GetService("DataStoreService")
local myDataStore = DataStoreService:GetDataStore("DataStoreName")



-- getting data
local success, result = pcall(DataStoreService.GetAsync, DataStoreService, "Gay")

if success then
   print('G')

 -- do something to result
else
    -- result is the error message
end


But if I tried

DataStoreService.GetAsync

Outside Pcall it would error

1 answer

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

The other arguments to pcall will be the ones used as arguments in the function assigned to said pcall's first parameter. Here's an example to better explain what I mean by that:

-- The function to be called
function OnPcall(string1, string2, string3)
    return string1 .. " " .. string2 .. " " .. string3
end

-- "Hello", "my" and "friends!" will be passed to our function OnPcall
local success, message = pcall(OnPcall, "Hello", "my", "friends!")
if success then
    print("Message: " .. message)
else
    warn("Error: " .. message)
end
Ad

Answer this question