Skip to reading
Error Handling & Debugging

Handle a bad value in BASIC

Edition 0.86.4.4 Hotfix 2

Updated through 0.86.4.4 Hotfix 2, with cinematic property, recorded-pose or voice-timing lessons as described in this guide. Earlier examples, screenshots and complete registry figures retain their stated edition context.

Download PDFView PDF page

LANGUAGE GUIDE · BASIC

PCA3D BASIC spells the same idea TRY, CATCH and END TRY. A guard lets a function report the problem before it changes anything in the game.

Code example
FUNCTION Run()
    DIM count = -1
    TRY
        ASSERT count >= 0
        RETURN "Ready"
    CATCH problem
        RETURN "Check the count"
    END TRY
END FUNCTION

This complete BASIC record returned Check the count. The assertion interrupts the normal path. In a catch block, PRINT problem.message can give the author the original reason while the caller receives a shorter reply.

When a helper reports failure itself#

Code example
IF NOT WriteTextFile("user://notes.txt", note_text) THEN
    PRINT "journal | write failed"
    RETURN FALSE
END IF

This fragment belongs inside a function where note_text already contains the intended text. A file write returns a Boolean. Checking it handles an unsuccessful write even when no catchable error occurs. Tell the player the journal was saved only on the success path.

For a BASIC record, use Validate and PRINT to trace the path. The interactive Step and watch controls shown on page 9 are in the PCA Script workspace.

Page 16 of 37Permalink
Go to page