| None. |
|
Returns the latest resource document error message. The diagnostic store is shared with world document operations, so capture the text immediately after a failed operation. Use WorldLoadError for errors in a subsequently requested async snapshot. For the full story, see the reusable resources guide, which covers resource formats, ownership, editing and the save workflow. See also: ResourceDocumentLastDiagnostics, ResourceDocumentDiagnostics, WorldLoadError. |
; CreateResourceDocument Example
; ------------------------------
; Create an untitled material document in memory; nothing touches the disk
document=CreateResourceDocument("material")
If document=0 Then RuntimeError ResourceDocumentError()
Print "New material document"
Print " path: '"+ResourceDocumentPath(document)+"' (untitled)"
Print " dirty: "+ResourceDocumentDirty(document)
Print " revision: "+ResourceDocumentRevision(document)
; Recolour it with an edit transaction made at the revision we observed
revision=ResourceDocumentRevision(document)
text$="{'protocol':'blitz3d.resource-document-edit','version':1,'revision':"+revision+","
text=text+"'operations':[{'op':'set-material-property','property':'color','value':[0.9,0.4,0.1,1]}]}"
edit=ParseJson(Replace(text,"'",Chr(34)))
If ApplyResourceDocumentEdit(document,edit)=0 Then RuntimeError ResourceDocumentError()
Print ""
Print "ApplyResourceDocumentEdit succeeded; revision is now "+ResourceDocumentRevision(document)
; The same edit is now stale, so it is rejected and nothing changes
Print "Applying it again returns "+ApplyResourceDocumentEdit(document,edit)
Print " ResourceDocumentError: "+ResourceDocumentError()
FreeJson edit
; Broken replacement text is rejected too, with diagnostics
If ReplaceResourceDocumentSource(document,"{",ResourceDocumentRevision(document))=0
diagnostics=ResourceDocumentDiagnostics(document)
Print ""
Print "ReplaceResourceDocumentSource rejected '{' with "+JsonCount(diagnostics)+" diagnostic(s)"
FreeJson diagnostics
EndIf
; Validation reports on the document without changing it
report=ValidateResourceDocument(document)
valid=JsonObjectGet(report,"valid")
Print ""
Print "ValidateResourceDocument valid: "+JsonBoolean(valid)
FreeJson valid
FreeJson report
; Read the colour back from a JSON snapshot of the document
snapshot=ResourceDocumentJson(document)
definition=JsonObjectGet(snapshot,"definition")
Print "Authored definition: "+JsonStringify(definition)
FreeJson definition
FreeJson snapshot
Print "Source text length: "+Len(ResourceDocumentSource(document))+" characters"
; Diagnostics of the latest operation in this program, handle or not
latest=ResourceDocumentLastDiagnostics()
Print "Latest operation diagnostics: "+JsonCount(latest)
FreeJson latest
FreeResourceDocument document
Print ""
Print "Press any key to close the example"
WaitKey
End