Skip to reading
BASIC Scripting

Write and run your first function

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

FIRST SCRIPT

What should happen when someone examines a station bell? Let the author see a log entry and let the player see a line of text.

Code example
OPTION PCA3D BASIC 1.0
Code example
FUNCTION Run(context AS Dictionary)
    PRINT "The station bell rang."
    AWAIT ShowMessage({"text": "Last train at midnight.", "duration": 2})
    RETURN 42
END FUNCTION

Run is the entry point. PCA3D starts there when you run the record. context holds information from the caller. The OPTION line identifies the dialect. You can leave it out in the shorter examples.

Source table from Write and run your first function, page 4
PRINTWrites “The station bell rang.” to the output. Use it to check what the code is doing.
ShowMessageDisplays the quoted line to the player. The dictionary in braces supplies the text and its duration in seconds.
RETURN 42Sends 42 to the caller and leaves the function. A manual run does not automatically display the returned number.

01. Choose Validate on the BASIC toolbar. When the status below the code says BASIC validation passed., choose Apply Changes and then Save Project.

02. Choose Run Script. Watch the game preview for “Last train at midnight.” Change just those words, apply, and run again to check your edit.

Page 4 of 86Permalink
Go to page