Hi all
I load resources when resource.load, but I dont found info about how to check resource exist.
Help please.
Hi all
I load resources when resource.load, but I dont found info about how to check resource exist.
Help please.
There is no way to check if a filename exists among the custom resources you can embed in a Defold game. But, if you call sys.load_resource()
on a resource name that doesn’t exist the function will return nil, and I guess that’s enough right?
You mean some that code
if sys.load_resource(<path_to_resource>) then
local var = resource.load(<path_to_resource>)
end
If yes - that enough thank you
Well, yes. I’m guessing that resource.load() also returns nil if the resource doesn’t exist. Give it a try!
resource.load return script error about resource not found And I goto find resolve for problem.
It should be possible to wrap the call to resource.load
in a pcall
.
Something like this:
local success, result = pcall(resource.load, <path_to_resource>)
if success then
print("Resource loaded!")
else
print("Could not load resource, error: " .. tostring(result))
end
Thank you. I try it.