Difference between revisions of "Resource keyword"
m (→Examples) |
m (→Examples) |
||
Line 55: | Line 55: | ||
// initialised using a literal: value = R"resource_test.nsc" | // initialised using a literal: value = R"resource_test.nsc" | ||
− | resource rLiteral = R"resource_test. | + | resource rLiteral = R"resource_test.nsc"; |
// initialised using a function: value = R"resource_test.nsc" | // initialised using a function: value = R"resource_test.nsc" |
Revision as of 10:16, 20 November 2009
The resource type represents a game resource file.
Literals
A literal is a textual representation of a particular value of a type.
A resource literal must adhere to the pattern R"<ResourceName>". The <ResourceName> element must adhere to the pattern <ResRef>.<ResType> and can be no more than 32 characters including the ".". The <ResRef> and <ResType> elements must only contain lower case letters, numbers, and/or underscores.
// valid resource literals resource rLiteral1 = R"abomination.utc"; // a creature resource literal resource rLiteral2 = R"it_some_ale.uti"; // an item resource literal // invalid resource literals resource rInvalid1 = "no_prefix_literal.uti"; // causes "Mismatch types" error resource rInvalid2 = R"no_extension_literal"; // causes "Unknown error" error resource rInvalid3 = R"too__many__characters__literal.uti"; // causes "Unknown error" error
Conversion
Explicit
There are no native functions that can be used to convert another data type to a resource.
The following functions can be used to convert a resource to another data type:
Implicit
There is no implicit conversion to a resource.
Persistence
The following functions allow a resource to exist outside of the scope of the current script by storing it on an object or event:
The following functions allow a resource which exist outside of the scope of the current script to be used in the current script by retrieving it from an object or event:
Examples
void main() { // uninitialised resource rDefault; // initialised using a literal: value = R"resource_test.nsc" resource rLiteral = R"resource_test.nsc"; // initialised using a function: value = R"resource_test.nsc" resource rFunction = GetCurrentScriptResource(); }