Skip to reading
BASIC Scripting

Pick from several named cases

Edition 0.86.4.1 HF1

0.86.4.1 Hotfix 1 edition. Earlier lessons and screenshots retain their original version context; revised references and supplements describe the newer behavior.

Download PDFView PDF page

THE BASIC LANGUAGE

SELECT CASE is handy when one value determines which of several lines to use. Here, both local platforms share one reply.

Code example
FUNCTION Run()
    DIM track = 2
    SELECT CASE track
    CASE 1, 2
        RETURN "Local train"
    CASE 3
        RETURN "Express"
    CASE ELSE
        RETURN "No departure"
    END SELECT
END FUNCTION

BASIC evaluates track once. A comma in CASE 1, 2 means either value matches. CASE ELSE catches any value the earlier choices missed.

What you should see With track set to 2, the result is Local train. A 3 returns Express. A 9 returns No departure.

Use IF and ELSEIF for ranges such as “fewer than five coins.” The PCA3D dialect accepts equality choices in CASE. A classic BASIC CASE range or CASE IS expression needs to be rewritten here.

Page 11 of 86Permalink
Go to page