Skip to main content

Built-in Functions

Circuitscript provides a set of built-in functions available in every script without any imports. These cover common operations like iteration, array manipulation, type conversion, and component inspection.


range

range(end)
range(start, end)

Returns an array of integers from start (inclusive, default 0) to end (exclusive). Typically used with for loops.

from "std" import *

vcc = supply("VCC")
gnd = dgnd()

at vcc
wire right 100

for i in range(0, 4):
add led("GREEN") pin 2
wire right 100

add res(10k)
wire right 100 down 100
to gnd
line 6:1VCCComponent D1_1: line 10:512D1_1GREENComponent D1_2: line 10:512D1_2GREENComponent D1_3: line 10:512D1_3GREENComponent D1_4: line 10:512D1_4GREENComponent R1: line 13:1R110kline 15:4GND

enumerate

enumerate(array)

Returns an array of [index, value] pairs from the input array. Useful when you need both the position and the value while iterating.

from "std" import *

vcc = supply("VCC")
gnd = dgnd()

at vcc
wire right 100

colors = ["yellow", "red", "blue", "green"]

for pair in enumerate(colors):
i = array_get(pair, 0)
color = array_get(pair, 1)
add led(color) pin 2
wire right 100

add res(10k)
wire right 100 down 100
to gnd
line 6:1VCCComponent D1_1: line 14:512D1_1yellowComponent D1_2: line 14:512D1_2redComponent D1_3: line 14:512D1_3blueComponent D1_4: line 14:512D1_4greenComponent R1: line 17:1R110kline 19:4GND

len

len(object)

Returns the number of elements in an array, or the number of keys in an object.


str

str(value)

Converts a value (number, boolean, etc.) to its string representation.


to_mils

to_mils(value)

Converts a metric value (millimetres) to mils (thousandths of an inch). Useful when working with layout coordinates that use imperial units.


array_push

array_push(array, value)

Appends value to the end of array and returns the array.

items = []
array_push(items, "a")
array_push(items, "b")
array_push(items, "c")
# items is now ["a", "b", "c"]

array_get

array_get(array, index)

Returns the element at index in array (zero-based).


array_set

array_set(array, index, value)

Sets the element at index in array to value and returns the array.

items = ["a", "b", "c"]
array_set(items, 1, "z")
# items is now ["a", "z", "c"]

pin_set_type

pin_set_type(component, pin_id, type)

Sets the pin type of pin_id on component. Accepts both full type names and short-form aliases (e.g. "in", "out"). See the pin types reference for the list of valid values.


pin_get_type

pin_get_type(component, pin_id)

Returns the current pin type string for pin_id on component.


has_pin

has_pin(component, pin_id)

Returns true if component has a pin with the given ID, false otherwise.


print

print(value, ...)

Prints one or more values to the interpreter output. Accepts any number of arguments. Useful for debugging scripts.