You are here

Developing for jACT-R: Scripted Conditions and Actions

Developing for jACT-R: Scripted Conditions and Actions

All model require some measure of atheoretic coding to interface with some device or experiment or to implement behavior that is outside of theoretical consideration. While custom conditions and actions are best, sometimes we just need to do a little hacking. That's where scripting comes in. Currently jACT-R only supports using javascript, but adding new scripting languages is relatively easy (if it's supported by javax.script).


Scriptable conditions use the scriptable-condition tag which must enclose a CDATA element (so that arbitrary text can be included). Then it's just a matter of implementing matches() and returning true or false (whether the condition is satisfied). Here's a simple snippet that expects =base to be resolved to a number, increments it and binds the value to =inc.

<scriptable-condition lang="javascript"><![CDATA[
        function matches()
        { // expects =base and binds =inc
          //test to make sure =base is resolved
         //get the value of =base as a double and increment
         var inc = jactr.get("=base").doubleValue();
         inc += 1;
         //bind =new to the value of inc
         jactr.set("=inc", inc);
         return true;

The use of the jactr.requires() method allows the condition to verify that the required variables have been resolved before attempt to execute the script.


Actions use the scriptable-action tag with the enclosed CDATA and implement the fire() method, with return value in seconds. The return value represents a theoretical amount of time that this action can take, just leave it as 0. This example posts a mock event to fire one second in the future. This is a trick that many Lisp modelers use to keep their models running when conflict resolution might otherwise result in the model being terminated.

<scriptable-action lang="javascript"><![CDATA[
        function fire()
         return 0; //amount of time this action takes to execute in theory


Script support

The jactr script object provides access to many common routines and is backed by the ScriptSupport class. With it you can copy or encode chunks, get and set variables (local and global) and slot values, get the current time, send output to the log, stop a model, post events (to delay model termination), and even get access to the runtime.

More information on this javascript interpreter can be found at the Mozilla Rhino development site.