Running script in Text DAT from anywhere in my network

The following script in a Text DAT called reset works correctly when I run it.

op( 'feedback1' ).par.resetpulse.pulse()

The confusion for me is how to run this from elsewhere in my network?
I assume I need to use a CHOP Execute?
Can anyone help with proper pathing?

Proper pathing is a much debated thing in the TD community. The easiest and most straightforward way is probably to use global op shortcuts, or parent shortcuts if the script is being run by a child operator..

Also, FWIW, the nicest place to put scripts is in extensions (see wiki) not just sitting in a DAT

@art3mis op('feedback1') is a relative path, that is, relative to the network it’s in. To be able to trigger this from anywhere you’d need an absolute path:

op('/project1/someplace/feedback1')

(this assumes you have a COMP node called someplace).

To invoke the script that lives in the Text DAT, you could make a button to invoke it. Basically you need some kind of invoking trigger, e.g. a button press, a script DAT, a Parameter Execute DAT.

For simplicity, make a Button COMP, set it to ‘momentary’. Put down a Parameter Execute DAT. Set the ParamExec DAT’s OPs field to the new button, set the Parameters par to value0, and leave only Value Change toggled to on. In the docked parexec1 script, set the onValueCHanged() to:

def onValueChange(par, prev):
	# use par.eval() to get current value
	if par.eval() == 1:
		op('/project1/someplace/text1').run()
	return

This will run the entire script in the Text DAT. Of course if you’re only need is to pulse that one parameter, just put that code directly in the parexec1.

1 Like

Indeed I find I’m creating the same Script DATs in multiple places. Other than pointing all of them to the same Text DAT for their code, it sounds like extensions might be a way to go.

What would the callbacks of a Script DAT (or Parameter Execute DAT) look like if the meat of the script was in an extension?

Is there a way to override or edit the template code that gets created for the Script DAT’s callaback Text DAT?

Assuming your script DAT is inside a custom component with parent shortcut “Scrypto”, you’d just have a line like this in your onCook callback:
parent.Scrypto.OnCookScript(whateverArgs)
Then you put all the code in the OnCookScript function in the extension.

If you want to access OnCookScript globally (and just have one custom comp) you could use a global OP shortcut instead and your call would look like this:
op.Scrypto.OnCookScript(whateverArgs)

Obviously you don’t have to use these example names. Please don’t :wink: You do have to capitalize the function for it to be “promoted” to the component object though.

You can’t override the default code.

Thanks!!!