cables DocumentationHow To UseWorking with filesKeyboard ShortcutsUser Interface WalkthroughBeginner TutorialBeginner 1: Drawing A CircleBeginner 2: TransformationsBeginner 3: ColorMore TransformationsIntermediateImage CompositionsPost-Processing 3D ScenesCommunicationcables APIExporting And EmbeddingHow to serve files externally and fix CORS headersExporting PatchesExport using the cables command line interfaceExport via IframeExport creating a standalone executableExport to github (pages)Export and deploy to netlifyExport for Cables Standalone VersionExport a ZIP fileExternal triggers / functionsUsing variablesPreviewing / uploading exported cables patchesExamples for EmbeddingPermissionsUsersPatchesTeamsOpsMultiplayerPatchlistsCoding OpsCreating AttachmentsGeneral op/Port CallbacksPortsDynamic PortsArray PortsBoolean portsInteger Number PortsObject PortsString portsTrigger PortsFloating Point Number PortsGUI/UI attributesHello Op - Part 1LibrariesDeveloping OpsRenaming / Creating a new versionCreating Viz OpsGuidelinesObject PortsPatching Ops / SubPatchOpsWriting ShadersWeb Audio Op DevelopmentHTML And CSS In CablesLightingLightsShadowsWorking With AudioBasic Audio SetupWorking with EffectsReal-Time Audio Analyzation & Audio VisualizationOffline Audio Visualization & AnalyzationOptimizing Performance In PatchesTools for debugging your patchHow to optimize cables patches with the Performance opHow to optimize cables patches with the ProfilerCommon pitfalls with the "usual suspects"Optimizing arraysDebugging Shaders with ShaderInfoFAQAudio in web browsersHow to make demoscene demos with cables.glEmbeddingHow to integrate my cables patch into my CMS (webflow/wix/squarespace/...)?How to remove grey rectangles on touch (mobile)?Why doesn't the DownloadTexture op work on iOS?How to disable page scrolling on mobile?Mobile tippsHow to run exported patches on your local machineTransparent CanvasFeatures and SupportHow to contribute code to cablesWill there be support for (animated) GIFs?Can i use a website as a texture?Screenshots and Video recordingHow to report a bug in cablesHow can I share a patch to get help?How can I support cables?Video playback in cablesGeneral questionsWhat is dev.cables.glJavascript Frameworkscordova / phonegapelectronreactvuejsLicenses and paymentWhat license do i need to use cables?Will I have to pay for it in the future?How is my work licensed when using cables?Does cables support midi and OSC?Patch PermissionsMy User Profile & Social MediaShadertoyCables at schools and universitiesTechnical questionsWebGL1 and WebGL2undefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefined

External triggers / functions

Triggering cables ops from outside

Sometimes you need to trigger a cables-port from outside cables, e.g. when you embed a cables-patch into a website.

Using the op Ops.Cables.Function you can define a function name which is visble from outside cables, just give it a name by setting the input-port Function Name, e.g. myFunction and you can trigger the op from your website’s JavaScript-code using CABLES.patch.config.myFunction();

If you need to pass a parameter, you can set a cables variable first (see Variables) and then trigger it.

Calling external functions

If you want to call an external JavaScript-function from inside cables you need to define it as a property of CABLES.patch.config.

Let’s create a function helloFromOutside():

In cables add the op Callback. Set its parameter Callback Name to helloFromOutside. Now connect a Mouse op to it so it gets triggered whenever the mouse was clicked (Mouse – click —> Callback - exe).

Export the project and open the index.html file in a text editor. Let’s define the function helloFromOutside right before the closing script tag:

        function showError(err) {

        document.addEventListener('CABLES.jsLoaded', function(event) {
            CABLES.patch=new CABLES.Patch({
                patchFile: 'js/Callback_Example_Patch.json',
                prefixAssetPath: '',
                glCanvasId: 'glcanvas',
                glCanvasResizeToWindow: true,
                onError: showError

            CABLES.patch.config.helloFromOutside = function(parameters) {
                console.log('cables called... hello!?');

Start a local webserver to serve the website and open it in your browser. Once you click the mouse on the canvas you should see cables called... hello!? inside the console.

If you pass any parameters with the Callback-op, these will be bundled as the parameters-array

Testing external functions

If you want to test the above callback without leaving cables you can define a test-function in the browser console:

Open the developer tools by pressing cmd + alt + i and enter:

gui.corePatch().config.helloFromOutside = function() {
    console.log('cables called... hello!?');

Based on the example above you should now be able to click somewhere on the canvas and see cables called... hello!? printed in the console.

Summarising: Inside cables test-callbacks have to be defined as a property of gui.corePatch().config, in your outside JavaScript-code they must be defined as a property of CABLES.patch.config .

Found a problem? Edit this file on github and contribute to cables!