Skip to main content

ComputerCraft API reference

Mod version shipped with FlammiCraft: 1.13.0

Overview · Main instructions

Detailed reference retained from the original AFN help. Integration-specific entries apply only when the corresponding mod is installed. Examples describe mod behavior; pack recipes and settings may differ.

Place a computer next to an AFN Bridge or connect it through a wired network to read and write its channels through the afn_bridge peripheral.

Computer access starts disabled. Allow Read, Activate and Configure separately in the bridge screen; with an authentication board only whitelisted computer IDs are admitted.

CC:T ships the afn module in its ROM: require('afn') finds the attached bridge for you; every function accepts an optional trailing bridge peripheral name.

afn.channels() lists every channel, afn.active() only the currently active ones and afn.display_channels() the channels in the screen rotation.

afn.get(name) returns a channel snapshot with id, name, type, subtype, receive_enabled, active, strength, value, displayed, attach_auth, revision, last_error, synaxis_receive, synaxis_publish, redstone_bindings, schema_version, primary_frequency, secondary_mode and secondary_frequency.

afn.value(name) returns { present, kind, value, revision }; a channel without a value is reported with present=false instead of failing.

afn.frequency(name) returns { primary, secondary_mode, secondary_frequency, attach_auth }.

afn.state(name) returns receive state, activity, strength and display flags; afn.last_error(name) returns the last rejection code.

afn.set(name, strength) sets a sustained external redstone strength (0-15, default 15).

afn.pulse(name, strength, ticks) fires a pulse; ticks defaults to 20 and may not exceed 1200.

afn.toggle(name, strength) flips the computer's external source.

afn.clear(name) releases this computer's source on the channel; afn.clear_all(name) clears every computer source (requires Configure).

Writes return { success, error, active, strength }; value writes additionally report value_present, value_kind, value and revision.

afn.set_information(name, value[, revision]) writes legacy information; afn.set_value(name, value[, revision]) and afn.clear_value(name[, revision]) edit the unified value; revision guards against concurrent overwrites. All of these require Configure.

afn.transmit_temporary(frequency, strength, attach_auth) and afn.pulse_temporary(frequency, strength, ticks, attach_auth) transmit to any frequency; they return { success, error, active, strength, handle } and afn.clear_temporary(handle) revokes them.

afn.bind_redstone(name, side, strength) binds a channel to one redstone output side of the bridge; afn.unbind_redstone(name, side) removes it. Both require Configure.

afn.create_channel({ name = 'main', primary_frequency = '1.2' }) creates a channel. Fields: name, type, frequency/primary_frequency, subtype/value_kind, value/channel_value, receive_enabled, displayed, attach_auth, secondary_mode and secondary_frequency.

afn.update_channel(name, { ... }) changes only the supplied fields.

afn.remove_channel(name) deletes a channel; afn.set_channel_type(name, type[, replacement]) and afn.set_information_subtype(name, subtype[, replacement]) switch its type.

afn.set_primary_frequency(name, freq) sets the primary frequency; afn.set_secondary(name, mode[, freq]) sets the secondary one with mode none, manual or auth.

afn.set_synaxis_receive/publish/activation(name, enabled[, format, x, y]) configures a Synaxis port; coordinates use block units from the screen's top-left corner.

Channel management returns { success, error, channel }; channel is the updated snapshot, or nil on failure.

afn.get_display_channel(), afn.set_display_channel(name), afn.next_display_channel() and afn.previous_display_channel() only need Read; afn.set_display_channels(names) and afn.set_channel_displayed(name, displayed) need Configure.

afn.screen() reads the whole screen layout and afn.set_screen(changes) edits it; afn.display(name) and afn.set_display(name, changes) read or write one channel's appearance.

changes may contain mode, show_name, show_idle, interaction_enabled, sensitivity, minimum, maximum, charset, bar_horizontal, chart_components, presets, control_color, background_color, other_color, control_palette, background_palette and map_* appearance fields.

mode supports default, switch, bar, gauge, map, logistics, stock, and dialogue.

Changes to an active channel's strength raise afn_channel_changed, channel-value changes raise afn_channel_value_changed, and legacy information changes still raise afn_information_changed; event data includes the channel name and state. Low-rate events are limited to 2 per computer every 4 ticks and excess is coalesced; started, stopped, and timeout events are immediate.

Strength is 0-15 and pulse duration is 1-1200 ticks; out-of-range values are rejected.

Value object limits: 64 nesting levels, 8192 nodes and 4096 entries per container. Text follows the server allowance.

Reading requires Read; set/pulse/toggle/temporary transmission require Activate; releasing your own source only needs an authorized computer; channel create/update/remove, value writes, screen and channel appearance, redstone bindings and clear_all require Configure.

Example: read main's current state, then keep forwarding its strength to 2.1 as it changes; revoke the outgoing source when main stops.

Channel changes raise afn_channel_changed, value changes raise afn_channel_value_changed and legacy information changes still raise afn_information_changed.

The three change events are low-rate: at most 2 per computer every 4 ticks, with excess coalesced; afn_channel_started, afn_channel_stopped and afn_channel_timeout are delivered immediately.

Channel management

Display and screen

Events

Example

Getting started

Limits and permissions

Reading channels

Writing and pulses