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

Returning Something in pcall using functions?

Asked by 4 years ago
local function ReturnSomething()
    return 'Hi'
end


local S,E = pcall(function()
    ReturnSomething()


end)

print(S,E) 

this prints (true , nil)

for some reason

I cant get a function to return something to a pcall

I want E to return Hi not nil how do i do this

1 answer

Log in to vote
2
Answered by
Psudar 882 Moderation Voter
4 years ago
Edited 4 years ago

You need to return it in the actual pcall() callback, instead of in your function.

ie:

local S, E  = pcall(function()
    return "Hi"
end
print(S, E)

true, Hi

  • or, if I were to edit your approach -
local function returnSomething()
    return "Hi"
end

local S, E = pcall(function()
    return returnSomething()
end)

print(S, E) 

true, Hi

Ad

Answer this question