Jump to content

Check if a resource still exists


Feche1320

Recommended Posts

Hello I am having a problem, I load resources at server startup, use the refreshResources function to add new maps/delete them, the problem is when a map gets deleted.. there is no isResource function or something similar to check if a resource still exists or not.. the only workaround is to use getResourceName but it throws a warning saying that the resource doesn't exist (this is obvious becose the resource got deleted), thanks :D

Link to comment
function isResource( resourceName ) 
    if resourceName and type(resourceName) == 'string' then 
    local resource = getResourceFromName( resourceName ) 
        if resource then 
        return true 
        else 
        return false 
        end 
    end 
end 

Link to comment
function isResource( resourceName ) 
    if resourceName and type(resourceName) == 'string' then 
    local resource = getResourceFromName( resourceName ) 
        if resource then 
        return true 
        else 
        return false 
        end 
    end 
end 

I am checking if it is a resource by passing the resource to the function, not by the name.

EDIT:

I inserted into the table the resource name aswell, so your code is working, thanks.

Link to comment

It becomes obvious when you compare the syntax of the two functions: getResourceFromName and getResourceName.

resource = getResourceFromName(string name) 
string = getResourceName(resource res) 

Passing a string is always possible but you can't pass a resource that doesn't exist, that's the reason for the warning, sometimes it's good to know how things actually work ;)

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...