PennController.ResetPrefix( "prefix" )
PennController.ResetPrefix( null )
NOTE: until beta 0.2, a bug prevented from defining a custom prefix (only
null worked)—this bug was fixed in beta 0.3. As of beta 0.3, the default prefix is no longer
By default, all the commands to create and refer back to elements in a PennController trial should be preceded by a prefix (
PennController). This is to avoid inadvertently overwriting (or being overwritten by) commands of the same names defined somewhere else, outside of the module. For instance, it could be that you or another module defined a function
getImage which, say, takes a filename and adds it at the end of a certain URL (this would be useful if you defined many items using built-in Ibex controllers that contain images and you do not want to type the host URL each time).
Yet, having to write
PennController.Elements. before each creation of/reference to an element would be particularly long, painful and not necessarily fit to your aesthetic preferences. Consider this:
PennController( PennController.Elements.defaultImage .settings.size(80, 80) , PennController.Elements.newText("helloworld", "Hello world!") .print() , PennController.Elements.newCanvas("geometry", 200, 100) .settings.add( 10, 10, PennController.Elements.newImage("left image", "triangle.png") ) .settings.add( 110, 10, PennController.Elements.newImage("right image", "square.png") ) .print() , PennController.Elements.newSelector("shapes") .settings.add( PennController.Elements.getImage("left image") , PennController.Elements.getImage("right image") ) .print() .wait() );
Long, painful and a little messy, right?
Now if you already have a
getImage function defined somewhere else and you do not want to rename it, but you do not want PennController to erase it either, you can choose to reset the prefix to make everything shorter while keeping your own
getImage function. For instance, you can choose to use the prefix
E for Element (assuming no script defined a global object named E otherwise):
PennController.ResetPrefix("E"); PennController( E.defaultImage .settings.size(80, 80) , E.newText("helloworld", "Hello world!") .print() , E.newCanvas("geometry", 200, 100) .settings.add( 10, 10, E.newImage("left image", "triangle.png") ) .settings.add( 110, 10, E.newImage("right image", "square.png") ) .print() , E.newSelector("shapes") .settings.add( E.getImage("left image") , E.getImage("right image") ) .print() .wait() );
This is already much better. But to the extent that PennController’s element commands have names that are not used by default Ibex projects, you may want to straight out drop the prefix using
PennController.ResetPrefix( null ), which is what is assumed throughout this documentation (no longer assuming the pre-existence of a getImage function in your project).