FontSheetError$ ( )

Parameters

None.

Description

Returns the reason the last font-sheet load failed.

LoadFontSheet deliberately does not stop your program when a descriptor or its image is missing or malformed - it returns 0 and records what went wrong here, so you can fall back to LoadFont, show the player a sensible message, or log the problem and carry on.

The usual pattern is to check the handle first and only read this when it came back 0: if sheet=0 then print FontSheetError$(). The string names the file and the specific problem - a descriptor that will not parse, an unsupported BMFont variant, a texture that is missing or too large - which saves a lot of guessing when a font works on your machine and not on someone else's.

The result is empty before any failure has happened and is cleared again by a successful load, so it always describes the most recent attempt rather than accumulating a history. Read it straight after the load you care about.

Requires Extended mode.

See also: LoadFontSheet, SetFontSheetSpacing, LoadFont, SetFont.

Example

; FontSheetError Example
; ----------------------
; Requires Extended mode.

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

; Deliberately try to load a descriptor that does not exist:
; LoadFontSheet returns 0 instead of opening an error dialog
bad=LoadFontSheet("missing-font-sheet.fnt")

; FontSheetError returns the diagnostic for the most recent failure
bad_error$=FontSheetError()

; A successful load clears the diagnostic again
good=LoadFontSheet("../../../samples/font-sheets/assets/glossy_cyan_techno_font_atlas_game.fnt",36)
good_error$=FontSheetError()

; A small system font for the report text
info_font=LoadFont("Arial",14)

While Not KeyDown(1)

    Cls

    SetFont info_font
    Color 255,255,255
    Text 0,0,"Esc: exit"

    Text 0,40,"LoadFontSheet(missing-font-sheet.fnt) returned "+bad
    Color 255,120,120
    Text 0,60,"FontSheetError() ="
    ; The diagnostic includes the full path, so wrap it over two lines
    Text 20,80,Left$(bad_error$,60)
    Text 20,100,Mid$(bad_error$,61)

    Color 255,255,255
    Text 0,140,"Valid sheet then loaded OK, handle "+good
    Text 0,160,"FontSheetError() after success = '"+good_error$+"' (empty again)"

    ; Prove the good handle works
    If good<>0 Then
        SetFont good
        Color 180,255,255
        Text 320,220,"loaded!",True
    End If

    Flip

Wend

End

Index