GetResourceState: Difference between revisions
Jump to navigation
Jump to search
(add oop syntax) |
m (Improved example) |
||
(One intermediate revision by one other user not shown) | |||
Line 1: | Line 1: | ||
{{Server client function}} | {{Server client function}} | ||
__NOTOC__ | __NOTOC__ | ||
This function returns the state of a given resource | This function returns the state of a given resource | ||
==Syntax== | |||
==Syntax== | |||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
string getResourceState ( resource theResource ) | string getResourceState ( resource theResource ) | ||
Line 10: | Line 9: | ||
===Required Arguments=== | ===Required Arguments=== | ||
*'''theResource:''' The resource you wish to get the | *'''theResource:''' The resource you wish to get the state of. | ||
{{OOP||[[resource]]:getState|state}} | {{OOP||[[resource]]:getState|state}} | ||
===Returns=== | ===Returns=== | ||
Line 17: | Line 16: | ||
*'''loaded''' | *'''loaded''' | ||
*'''running''' | *'''running''' | ||
*'''starting''' | *'''starting''' | ||
*'''stopping''' | *'''stopping''' | ||
*'''failed to load''' - Use [[getResourceLoadFailureReason]] to find out why it failed. | *'''failed to load''' - Use [[getResourceLoadFailureReason]] to find out why it failed. | ||
==Example== | ==Example== | ||
Line 27: | Line 24: | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
function getState( player, command, resourceName ) | function getState( player, command, resourceName ) | ||
if resourceName then | if not resourceName then | ||
outputChatBox( "Syntax: " .. command .. " [resource name]", player, 255, 0, 0 ) | outputChatBox( "Syntax: " .. command .. " [resource name]", player, 255, 0, 0 ) | ||
return | |||
end | |||
local resource = getResourceFromName( resourceName ) | |||
if not resource then | |||
outputChatBox( "Error: No resource with name " .. resourceName .. " exists.", player, 255, 0, 0 ) | |||
return | |||
end | end | ||
local state = getResourceState( resource ) | |||
outputChatBox( "Resource " .. resourceName .. " is " .. state, player, 0, 0, 255 ) | |||
end | end | ||
Latest revision as of 18:10, 21 March 2024
This function returns the state of a given resource
Syntax
string getResourceState ( resource theResource )
Required Arguments
- theResource: The resource you wish to get the state of.
OOP Syntax Help! I don't understand this!
- Method: resource:getState(...)
- Variable: .state
Returns
If successful returns a string with the resource state in it, false otherwise. The state can be one of:
- loaded
- running
- starting
- stopping
- failed to load - Use getResourceLoadFailureReason to find out why it failed.
Example
This example returns the state of a given resource. Syntax: /state <Resource Name>
function getState( player, command, resourceName ) if not resourceName then outputChatBox( "Syntax: " .. command .. " [resource name]", player, 255, 0, 0 ) return end local resource = getResourceFromName( resourceName ) if not resource then outputChatBox( "Error: No resource with name " .. resourceName .. " exists.", player, 255, 0, 0 ) return end local state = getResourceState( resource ) outputChatBox( "Resource " .. resourceName .. " is " .. state, player, 0, 0, 255 ) end addCommandHandler( "state", getState )
See Also
- abortRemoteRequest
- call
- fetchRemote
- getResourceConfig
- getResourceDynamicElementRoot
- getResourceExportedFunctions
- getResourceFromName
- getResourceName
- getResourceRootElement
- getResourceState
- getThisResource
- getRemoteRequests
- getRemoteRequestInfo