보통 try catch를 쓰는것과 다르게 lua script 에서는 pcall 이라는것이 이를 대신한다.
httpservice 를 통해 RESTAPI 통신할때 사용하면 유용하다.
lua script 에서는 리턴값을 여러개 받을 수 있는 모양이다. pcall 을 이용하면 성공여부 (try catch 성공여부) 및 결과값 리턴을 동시에 해준다.
local success, response = pcall(function()
return HttpService:PostAsync(url, HttpService:JSONEncode(requestBody))
end)
if success then
if response.StatusCode == 400 then
print("Bad request")
else
print("Request was successful")
end
else
print("Request failed with error:", response)
end
'로블록스 게임제작' 카테고리의 다른 글
Local Script 간 이벤트 전달 (bindable Event) (0) | 2024.02.21 |
---|---|
SurfaceGUI 및 Adornee (0) | 2024.02.21 |
코루틴 (0) | 2024.02.14 |
RESTAPI 통신 및 모듈스크립트 호출 (0) | 2024.02.13 |
UI 상호작용 및 커스텀 이벤트 전달 (local -> server) (0) | 2024.02.13 |