Blitz3D+ Command Reference

LoadResourceDocument ( file$[,repair] )

Parameters

file$ - material, prefab or physics descriptor file

repair (optional) - True keeps source that fails validation so it can be corrected (default); False rejects it

Description

Loads a resource descriptor file as an editable document.

Returns an authoring document, or 0 on failure. Repair mode retains source that fails validation for correction, and ResourceDocumentSource exposes the retained text. A document must validate before saving or instantiation.

This operation creates no entities, GPU resources, audio channels or physics objects - use LoadResourceDocumentAsync to turn a document into a runtime world.

For the full story, see the reusable resources guide, which covers resource formats, ownership, editing and the save workflow.

Requires Extended mode.

See also: CreateResourceDocument, SaveResourceDocument, ResourceDocumentSource, LoadResourceDocumentAsync, FreeResourceDocument.

Example

; SaveResourceDocument Example
; ----------------------------
; Requires Extended mode.

Print "This example saves demo_paint.material next to itself, then deletes it."
Print "Press Y to continue, any other key to skip."
WaitKey
If KeyDown(21)

    file$="demo_paint.material"
    document=CreateResourceDocument("material")
    If document=0 Then RuntimeError ResourceDocumentError()

    ; An untitled document needs a path on its first save (Save As)
    If SaveResourceDocument(document,file$)=0 Then RuntimeError ResourceDocumentError()
    Print "Saved: "+ResourceDocumentPath(document)
    Print "  dirty after saving: "+ResourceDocumentDirty(document)
    Print "  disk revision: "+Left(ResourceDocumentDiskRevision(document),16)+"..."
    FreeResourceDocument document

    ; Load the file back as an editable document
    reloaded=LoadResourceDocument(file$)
    If reloaded=0 Then RuntimeError ResourceDocumentError()
    Print ""
    Print "LoadResourceDocument reopened it; the disk revision matches: "+Left(ResourceDocumentDiskRevision(reloaded),16)+"..."
    FreeResourceDocument reloaded

    ; A missing file returns 0, with the reason and diagnostics retained
    missing=LoadResourceDocument("no_such_paint.material")
    Print ""
    Print "Loading a missing file returned "+missing
    Print "  ResourceDocumentError: "+ResourceDocumentError()

    DeleteFile file$
    Print ""
    Print "Demo file deleted"

Else
    Print "Skipped"
EndIf

Print ""
Print "Press any key to close the example"
WaitKey

End

Index