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
01local function ReturnSomething()
02    return 'Hi'
03end
04 
05 
06local S,E = pcall(function()
07    ReturnSomething()
08 
09 
10end)
11 
12print(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:

1local S, E  = pcall(function()
2    return "Hi"
3end
4print(S, E)

true, Hi

  • or, if I were to edit your approach -
1local function returnSomething()
2    return "Hi"
3end
4 
5local S, E = pcall(function()
6    return returnSomething()
7end)
8 
9print(S, E)

true, Hi

Ad

Answer this question