Skip to reading
BASIC Scripting

Call BASIC and native Godot helpers

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

BASIC IN YOUR GAME

A function can belong to another BASIC record, or to a PCA Script, Lua or GDScript record. The caller needs the record ID, function name and arguments in the right order.

Code example
FUNCTION Run()
    DIM total = CallScript("ticket_price", "Fare", [3, 4], {})
    RETURN total
END FUNCTION

The arguments are [3, 4]. The last {} is the optional context dictionary. This call to Fare returns 12. The script record and function can have different names.

When you need a Godot API#

Put this listing in a native GDScript record with ID native_screen. It asks Godot for the width of the visible game viewport.

Code example
func Width() -> int:
    return int(Runtime.get_viewport().get_visible_rect().size.x)

Put the following in a BASIC record. Let GDScript handle the engine object and return a plain number to BASIC.

Code example
FUNCTION Run()
    RETURN CallScript("native_screen", "Width", [], {})
END FUNCTION

What you should see The Linux preview returned 1280. Another window or device can have a different width. To run a visual graph, BASIC also accepts RUN VISUAL SCRIPT "graph_id" with a matching graph ID.

Page 27 of 86Permalink
Go to page