Copying a routine

Hello,

Hello,

How can i create instances of a routine instead of copies? A copy preserves all the components such that if i want to copy a routine and change something in it thereafter, it changes the previous one. I want to copy out as an instance rather than a pointer. Any advice on how this can be done? It would be an absolute horror if i had to rewrite each copy.

thanks

OS (e.g. Win10): mac sierra
PsychoPy version (e.g. 1.84.x): 2020.2.3
Standard Standalone? (y/n) If not then what?: scratch build

You can insert multiple copies of the same routine into the experiment flow or you can repeat a routine using a loop. I try to do one of these two methods rather than making a copy of the routine itself whenever possible, so that if I need to make an edit, I only make it once.

1 Like

I can’t really tell from your post what it is that you want to do, but you can repeat a routine using a loop and change some parts of the routine using a conditions sheet for your loop.

1 Like

If I understand you correctly, you should go to the “Experiment” menu and choose “Copy routine”. Then go back to the “Experiment” menu and choose “Paste routine”. You will be asked to provide a name for the new version of the routine. All of its components will be automatically be re-named and so can be changed independently of the originals.

There is an issue with terminology here perhaps: in Builder terms, “copy” in this case does mean make a new instance, using the original as a template (as if it was a class definition), rather than a pointer to the original. What you refer to as “copying” is represented in the Builder interface as “inserting” a routine into the flow, which effectively clones the original multiple times.

I think your approach is that of someone who naturally conceptualises things from an object-oriented-programming point of view. Builder was originally made for non-programmers, so, oddly, aspects of it can sometimes be harder for experienced programmers to get to grips with.

People ask about how to copy and paste routines a fair bit (as it isn’t that intuitive).

Here is a youtube video for future users searching this question.

1 Like

Hi,

I followed Becca’s posts exactly.

Insert Routine -> Experiment (Copy Routine) -> Experiment (Paste Routine).
I rename the routine.
I change a component’s name. It is reflected in the earlier components in the original routine I copied from.

So the steps mentioned above do not work. Copying is not creating an instance. It is acting like a pointer.

I noticed in the video, the Insert Routine goes at the end. This is not an option for me. After ‘Copy Routine’, you are expected to name the routine. As a result, picking the name goes first before Experiment (Copy Routine) -> Experiment (Paste Routine).

@Michael

You understood my problem precisely . Thank You!! However what you suggested (same as Becca and wakecarter) does not work as I explained in my comments above.

If you insert a routine (bottom left) you can put it anywhere in your flow.

Hi,

I figured it out. All good!

Can one clear the component’s queue at the beginning of the routine?
If I copy the routine in a way that they are not instances, can I clear the component so that it forgets anything that it did in the original routine ?
Part of the problem i ran into was a routine remembering what it did in the first one.

This is obviously not a problem if i create genuine instance (thanks for all the recommendations above) but then I have a billion different names for the same routine such as routine, routine_2, routine_3, … I want to avoid some of this redundancy by using a pointer-like copy with a cache clearing mechanism in the beginning.

thanks

I am willing to build it myself. I just need to know some of the parts that might be available such as cache clearing.

It sounds like you are fighting against Builder’s design. Perhaps it would be best if you describe what you actually trying to achieve in terms of a concrete experimental procedure – it generally shouldn’t be necessary to have a proliferation of routines.

Loop
Load image.
2 sets of questions. Both mouse operated. Report.
End Loop

The central problem is that the mouse component seems to remember old clicks and/or doesn’t respond correctly to new ones.

Is the mouse component is set to “New clicks only”?

valid click

That’s a separate setting (under “End routine on press”). There is another setting specifically called “New clicks only”.

End routine on press : valid click

Other echoices that are available: never, any click

Save mouse state on : on click

Other choices that are available: final , every frame, never

It works now. I removed additional processing i was doing post click that recorded the clicked_name[0] and turned the color of the stimuli to a different one if it was clicked. I have no idea why that would cause problems, but its presence was a problem some of the time.

I would consider this ticket closed. thank you for your help on earlier posts.

In order to mark the thread as closed, please could you make one of the posts as the solution (which may be your own post)?