ModelSaveError$ ( )

Parameters

None.

Description

Returns why the last SaveMesh failed, or an empty string if it worked.

SaveMesh returns False when it cannot write a file. ModelSaveError gives you the sentence to show your player, or to put in your level editor's status bar: SaveMesh writes .glb files: name the file crate.glb, Could not write 'C:/Levels/house.glb': the folder does not exist, Could not save 'ship.glb': 'Ship' has no mesh to save or Could not save 'hero.glb': 'Body' is skinned to the bone 'Hips', which is not part of the saved entity.

The standard pattern is one line under every save:

If SaveMesh(house,"house.glb")=False Then Notify "Could not save the house: "+ModelSaveError()

There is one string, and it holds the result of the most recent SaveMesh, so read it straight away. A successful save clears it.

See also: SaveMesh, ModelLoadError, PrepareModelError.

Example

; ModelSaveError Example
; ----------------------

Graphics3D 640,480,0,2
SetBuffer BackBuffer()

camera=CreateCamera()
PositionEntity camera,0,1,-5

light=CreateLight()
RotateEntity light,45,45,0

; The crate a level editor wants to save
crate=CreateCube()
EntityColor crate,170,120,70

; SaveMesh writes .glb files only, so this fails and says why
wrong_type=SaveMesh(crate,"crate.b3d")
wrong_type_reason$=ModelSaveError()

; A folder that does not exist fails too
no_folder=SaveMesh(crate,SystemProperty("tempdir")+"no such folder\crate.glb")
no_folder_reason$=ModelSaveError()

; A good file name works, and clears the error
file$=SystemProperty("tempdir")+"crate.glb"
good=SaveMesh(crate,file)
good_reason$=ModelSaveError()

While Not KeyDown(1)

    TurnEntity crate,0.5,1,0

    ; Arrow keys move the camera
    If KeyDown(200) Then MoveEntity camera,0,0,0.1
    If KeyDown(208) Then MoveEntity camera,0,0,-0.1
    If KeyDown(203) Then TurnEntity camera,0,1,0
    If KeyDown(205) Then TurnEntity camera,0,-1,0

    RenderWorld

    Text 0,0,"Arrow keys: move camera   Esc: exit"
    Text 0,20,"crate.b3d: "+wrong_type+"  "+wrong_type_reason
    Text 0,40,"missing folder: "+no_folder+"  "+no_folder_reason
    Text 0,60,"crate.glb: "+good+"  ModelSaveError()="+Chr(34)+good_reason+Chr(34)

    Flip

Wend

DeleteFile file
End

Index