Welcome! Log In Create A New Profile

Advanced

Does run_scene pause the script until completion?

Posted by jamesbutler01 
Does run_scene pause the script until completion?
January 31, 2020 09:58AM
Nevermind - was the recording setup being weird.


Hi Jaewon

I have the following code, where I wish to use an eventmarker to signal the beginning of a scene, and another eventmarker to signal when the scene has finished:

    ec_options_on = 0;
    ec_option_chosen = 1;
    ec_no_option_chosen = 2;

    % Build scene
    f1 = SingleTarget(joy_);
    f1.Target = curr_options(1);
    f1.Threshold = [3 2];
    fth1 = FreeThenHold(f1);
    fth1.MaxTime = choice_timeout;
    fth1.HoldTime = choice_hold_time;
    
    or = OrAdapter(fth1);
    
    f2 = SingleTarget(joy_);
    f2.Target = curr_options(2);
    f2.Threshold =  [3 2];
    fth2 = FreeThenHold(f2);
    fth2.MaxTime = choice_timeout;
    fth2.HoldTime = choice_hold_time;
    or.add(fth2);
    
    scene = create_scene(or, [curr_options]);

    % Signal scene about to start
    eventmarker(ec_options_on );

    % Start scene
    run_scene(scene);
    
    % Signal choice made (approximate RT measure)
    eventmarker(ec_option_chosen);

But I am receiving ec_option_chosen straight after ec_options_on, not ~500ms later after they have actually selected an option. I thought that run_scene "pauses" the script, which resumes when the adapter finishes, but maybe I am just completely misunderstanding how it works. I should say that the script works fine behaviourally, and doesn't progress the task until an option is selected.

This seems to be unique to this "or" and "fth" combination, and other usages like this seem to be working okay.

I was also using this below code as an approximate reward measure, which also doesn't seem to function as well?
function give_reward(amount)
eventmarker(ec_pump_on)
goodmonkey(amount);
eventmarker(ec_pump_off)
end
Re: Does run_scene pause the script until completion?
January 31, 2020 07:07PM
There are a few things that I must point out.

First, you should use the AllContinue adapter, instead of OrAdapter. OrAdapter checks only the Success state of fth1 and fth2, so it works if joystick is eventually acquired by either of them. However, if the subject does not respond and choice_timeout is over, neither of them can succeed and your scene falls into an infinite loop. AllContinue terminates the scene when either of fth1 and fth2 stops, which is the behavior you want, I think.

Second, you should NOT use the eventmarker function to record onset times of stimuli or rewards. toggleobject, goodmonkey, and run_scene all have their own options to stamp eventcodes, so you rarely need the eventmarker function if you script in a right way. The start and end times of rewards are recorded in the RewardRecord field of the data file anyway, if you use goodmonkey.

Third, you cannot expect that you can mark the time of choice precisely with eventcodes. You can determine whether a certain behavior occurs or not, only after you watch it first. The moment at which the joystick cursor crosses a line is long gone by the time you are able to declare it. So all reaction time analysis should be done offline, unless some errors are allowed. This doesn't mean that you need to finish experiments before analyzing reaction times. You can calculate a precise reaction time in the timing script like the following, but just not while the scene is running.

stimulus_onset_time  = run_scene(scene, marker_for_stimulus_onset);

time_of_joystick_acquisition = [];
if fth1.Success, time_of_joystick_acquisition = fth1.AcquiredTime; end
if fth2.Success, time_of_joystick_acquisition = fth2.AcquiredTime; end

if ~isempty(time_of_joystick_acquisition), rt = time_of_joystick_acquisition - stimulus_onset_time; end
Re: Does run_scene pause the script until completion?
February 01, 2020 05:10AM
Yes thanks Jaewon. This is just to allow me to get a rough idea of signals online using solely my recording file/recording software using triggers from the various eventmarker inputs from ML. For more detailed RT/timestamps I will use the bhv file information afterwards.

The National Institute of Mental Health (NIMH) is part of the National Institutes of Health (NIH), a component of the U.S. Department of Health and Human Services.