Start Trial with Mouse at Screen Center


Author
Message
jmsaito
jmsaito
Associate Member (120 reputation)Associate Member (120 reputation)Associate Member (120 reputation)Associate Member (120 reputation)Associate Member (120 reputation)Associate Member (120 reputation)Associate Member (120 reputation)Associate Member (120 reputation)Associate Member (120 reputation)
Group: Forum Members
Posts: 9, Visits: 19
I saw that someone asked 12 years ago if you can initialize a trial with the mouse at the center of the screen (https://www.millisecond.com/forums/Topic3965.aspx).

The conclusion at that time was that this was not possible. Has this changed? If so, how do I do this?

Dave
Dave
Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)
Group: Administrators
Posts: 12K, Visits: 98K
jmsaito - 1/26/2022
I saw that someone asked 12 years ago if you can initialize a trial with the mouse at the center of the screen (https://www.millisecond.com/forums/Topic3965.aspx).

The conclusion at that time was that this was not possible. Has this changed? If so, how do I do this?

You can do

<trial mytrial>
/ ontrialbegin = [
    mouse.x = 50%;
    mouse.y = 50%;
]
/ stimulusframes = [1=o]
/ inputdevice = mouse
...
</trial>

but note that this will require the user to grant certain app permissions on some platforms (e.g. Macs).

You can have a script prompt the user and ask for certain permissions per
https://www.millisecond.com/support/docs/v6/html/language/attributes/requiredpermissions.htm

jmsaito
jmsaito
Associate Member (120 reputation)Associate Member (120 reputation)Associate Member (120 reputation)Associate Member (120 reputation)Associate Member (120 reputation)Associate Member (120 reputation)Associate Member (120 reputation)Associate Member (120 reputation)Associate Member (120 reputation)
Group: Forum Members
Posts: 9, Visits: 19
Dave - 1/26/2022
jmsaito - 1/26/2022
I saw that someone asked 12 years ago if you can initialize a trial with the mouse at the center of the screen (https://www.millisecond.com/forums/Topic3965.aspx).

The conclusion at that time was that this was not possible. Has this changed? If so, how do I do this?

You can do

<trial mytrial>
/ ontrialbegin = [
    mouse.x = 50%;
    mouse.y = 50%;
]
/ stimulusframes = [1=o]
/ inputdevice = mouse
...
</trial>

but note that this will require the user to grant certain app permissions on some platforms (e.g. Macs).

You can have a script prompt the user and ask for certain permissions per
https://www.millisecond.com/support/docs/v6/html/language/attributes/requiredpermissions.htm


Hi Dave, it looks like this works! However, it's brought up another question.

At current, I am creating a loop on the same trial until the user makes a mouse click within a certain region of the screen. So when I loop back, it re-centers the mouse and essentially makes finishing the trial impossible.

Any recommendations on a workaround? I've tried setting the mouse.x & y at the end of the previous trial, but this appears to break my branching...

<trial first_recall3>    
/ stimulustimes = [0 = color_wheel, FixationCross, resp_probe, probe2_holder, probe3_holder]
/ inputdevice = mouse
/ validresponse = ("lbuttondown")
/ timeout = 50
/ recorddata = true
/ ontrialend = [
    values.temp_resp = trial.first_recall3.response;
    values.final_RT = trial.first_recall3.latency;
    values.recall_x = mouse.x-parameters.center_x;
    values.recall_y = mouse.y-parameters.center_y;

    values.recall_radius = sqrt(pow(values.recall_x, 2)+pow(values.recall_y, 2));
    if (abs(parameters.wheel_r_px-values.recall_radius)<parameters.wheel_inrange_px){
        values.recall_inrange = 1
    } else {
        values.recall_inrange = 0
    }
    
    values.recall_angle = atan2(values.recall_y, values.recall_x)*180/M_PI;
    if (values.recall_angle<=0){
        values.recall_angle=values.recall_angle+360;
    };
    
    values.recall_angle_index = round(values.recall_angle)+(values.current_wheel*30);
    if (values.recall_angle_index>360){
        values.recall_angle_index = values.recall_angle_index-360;
    };
]
/ branch = [
    if (values.recall_inrange == 1 && values.recall_angle_index>0){
        values.resp_index = values.recall_angle_index;
        if (trial.first_recall3.response == "lbuttondown"){
            trial.last_recall3
        } else {
            trial.first_recall3
        };        
    } else {
        trial.first_recall3
    };

]
</trial>
Dave
Dave
Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)
Group: Administrators
Posts: 12K, Visits: 98K
jmsaito - 1/26/2022
Dave - 1/26/2022
jmsaito - 1/26/2022
I saw that someone asked 12 years ago if you can initialize a trial with the mouse at the center of the screen (https://www.millisecond.com/forums/Topic3965.aspx).

The conclusion at that time was that this was not possible. Has this changed? If so, how do I do this?

You can do

<trial mytrial>
/ ontrialbegin = [
    mouse.x = 50%;
    mouse.y = 50%;
]
/ stimulusframes = [1=o]
/ inputdevice = mouse
...
</trial>

but note that this will require the user to grant certain app permissions on some platforms (e.g. Macs).

You can have a script prompt the user and ask for certain permissions per
https://www.millisecond.com/support/docs/v6/html/language/attributes/requiredpermissions.htm


Hi Dave, it looks like this works! However, it's brought up another question.

At current, I am creating a loop on the same trial until the user makes a mouse click within a certain region of the screen. So when I loop back, it re-centers the mouse and essentially makes finishing the trial impossible.

Any recommendations on a workaround? I've tried setting the mouse.x & y at the end of the previous trial, but this appears to break my branching...

<trial first_recall3>    
/ stimulustimes = [0 = color_wheel, FixationCross, resp_probe, probe2_holder, probe3_holder]
/ inputdevice = mouse
/ validresponse = ("lbuttondown")
/ timeout = 50
/ recorddata = true
/ ontrialend = [
    values.temp_resp = trial.first_recall3.response;
    values.final_RT = trial.first_recall3.latency;
    values.recall_x = mouse.x-parameters.center_x;
    values.recall_y = mouse.y-parameters.center_y;

    values.recall_radius = sqrt(pow(values.recall_x, 2)+pow(values.recall_y, 2));
    if (abs(parameters.wheel_r_px-values.recall_radius)<parameters.wheel_inrange_px){
        values.recall_inrange = 1
    } else {
        values.recall_inrange = 0
    }
    
    values.recall_angle = atan2(values.recall_y, values.recall_x)*180/M_PI;
    if (values.recall_angle<=0){
        values.recall_angle=values.recall_angle+360;
    };
    
    values.recall_angle_index = round(values.recall_angle)+(values.current_wheel*30);
    if (values.recall_angle_index>360){
        values.recall_angle_index = values.recall_angle_index-360;
    };
]
/ branch = [
    if (values.recall_inrange == 1 && values.recall_angle_index>0){
        values.resp_index = values.recall_angle_index;
        if (trial.first_recall3.response == "lbuttondown"){
            trial.last_recall3
        } else {
            trial.first_recall3
        };        
    } else {
        trial.first_recall3
    };

]
</trial>

Sorry, that code snippet is not helpful. Could you please comment your code? It's also unclear what "previous trial" refers to, I only see code for a single trial element. I also cannot find any spot in the code snippet you posted where you recenter the mouse.
jmsaito
jmsaito
Associate Member (120 reputation)Associate Member (120 reputation)Associate Member (120 reputation)Associate Member (120 reputation)Associate Member (120 reputation)Associate Member (120 reputation)Associate Member (120 reputation)Associate Member (120 reputation)Associate Member (120 reputation)
Group: Forum Members
Posts: 9, Visits: 19
Dave - 1/26/2022
jmsaito - 1/26/2022
Dave - 1/26/2022
jmsaito - 1/26/2022
I saw that someone asked 12 years ago if you can initialize a trial with the mouse at the center of the screen (https://www.millisecond.com/forums/Topic3965.aspx).

The conclusion at that time was that this was not possible. Has this changed? If so, how do I do this?

You can do

<trial mytrial>
/ ontrialbegin = [
    mouse.x = 50%;
    mouse.y = 50%;
]
/ stimulusframes = [1=o]
/ inputdevice = mouse
...
</trial>

but note that this will require the user to grant certain app permissions on some platforms (e.g. Macs).

You can have a script prompt the user and ask for certain permissions per
https://www.millisecond.com/support/docs/v6/html/language/attributes/requiredpermissions.htm


Hi Dave, it looks like this works! However, it's brought up another question.

At current, I am creating a loop on the same trial until the user makes a mouse click within a certain region of the screen. So when I loop back, it re-centers the mouse and essentially makes finishing the trial impossible.

Any recommendations on a workaround? I've tried setting the mouse.x & y at the end of the previous trial, but this appears to break my branching...

<trial first_recall3>    
/ stimulustimes = [0 = color_wheel, FixationCross, resp_probe, probe2_holder, probe3_holder]
/ inputdevice = mouse
/ validresponse = ("lbuttondown")
/ timeout = 50
/ recorddata = true
/ ontrialend = [
    values.temp_resp = trial.first_recall3.response;
    values.final_RT = trial.first_recall3.latency;
    values.recall_x = mouse.x-parameters.center_x;
    values.recall_y = mouse.y-parameters.center_y;

    values.recall_radius = sqrt(pow(values.recall_x, 2)+pow(values.recall_y, 2));
    if (abs(parameters.wheel_r_px-values.recall_radius)<parameters.wheel_inrange_px){
        values.recall_inrange = 1
    } else {
        values.recall_inrange = 0
    }
    
    values.recall_angle = atan2(values.recall_y, values.recall_x)*180/M_PI;
    if (values.recall_angle<=0){
        values.recall_angle=values.recall_angle+360;
    };
    
    values.recall_angle_index = round(values.recall_angle)+(values.current_wheel*30);
    if (values.recall_angle_index>360){
        values.recall_angle_index = values.recall_angle_index-360;
    };
]
/ branch = [
    if (values.recall_inrange == 1 && values.recall_angle_index>0){
        values.resp_index = values.recall_angle_index;
        if (trial.first_recall3.response == "lbuttondown"){
            trial.last_recall3
        } else {
            trial.first_recall3
        };        
    } else {
        trial.first_recall3
    };

]
</trial>

Sorry, that code snippet is not helpful. Could you please comment your code? It's also unclear what "previous trial" refers to, I only see code for a single trial element. I also cannot find any spot in the code snippet you posted where you recenter the mouse.
<trial first_recall3>    # Participant is going to report a cued color from a color wheel
/ stimulustimes = [0 = color_wheel, FixationCross, resp_probe, probe2_holder, probe3_holder]     # At start, a color wheel, fixation cross, and 3 empty circles are shown at the location of 3 original memoranda
/ inputdevice = mouse
/ validresponse = ("lbuttondown")     # The participant is going to report the remembered color by clicking on the color wheel where that color falls
/ timeout = 50      # We loop the trial every 50 ms
/ recorddata = true
/ ontrialend = [
  values.temp_resp = trial.first_recall3.response;      # Save the response, RT, and location of the mouse click
  values.final_RT = trial.first_recall3.latency;
  values.recall_x = mouse.x-parameters.center_x;
  values.recall_y = mouse.y-parameters.center_y;

  values.recall_radius = sqrt(pow(values.recall_x, 2)+pow(values.recall_y, 2));      # We use the mouse coordinates to determine if the click happened on the wheel or not. Only care about on wheel clicks
  if (abs(parameters.wheel_r_px-values.recall_radius)<parameters.wheel_inrange_px){
   values.recall_inrange = 1
  } else {
   values.recall_inrange = 0
  }
 
  values.recall_angle = atan2(values.recall_y, values.recall_x)*180/M_PI;       # I convert mouse click coordinate to degrees to figure out of their mouse trajectory relative to the screencenter
  if (values.recall_angle<=0){
   values.recall_angle=values.recall_angle+360;
  };
 
  # Because the wheel is randomly rotating every trial in increments of 30 degrees, I account for this when I determine the angle
  values.recall_angle_index = round(values.recall_angle)+(values.current_wheel*30);     
  if (values.recall_angle_index>360){
   values.recall_angle_index = values.recall_angle_index-360;
  };
]
/ branch = [
  if (values.recall_inrange == 1 && values.recall_angle_index>0){       # Only collect responses that were (1) on the wheel and (2) greater than zero although (2) is a redundancy of the correction I do above
   values.resp_index = values.recall_angle_index;
   if (trial.first_recall3.response == "lbuttondown"){
    trial.last_recall3
   } else {
    trial.first_recall3
   };  
  } else {
   trial.first_recall3
  };

]
</trial>

jmsaito
jmsaito
Associate Member (120 reputation)Associate Member (120 reputation)Associate Member (120 reputation)Associate Member (120 reputation)Associate Member (120 reputation)Associate Member (120 reputation)Associate Member (120 reputation)Associate Member (120 reputation)Associate Member (120 reputation)
Group: Forum Members
Posts: 9, Visits: 19
jmsaito - 1/26/2022
Dave - 1/26/2022
jmsaito - 1/26/2022
Dave - 1/26/2022
jmsaito - 1/26/2022
I saw that someone asked 12 years ago if you can initialize a trial with the mouse at the center of the screen (https://www.millisecond.com/forums/Topic3965.aspx).

The conclusion at that time was that this was not possible. Has this changed? If so, how do I do this?

You can do

<trial mytrial>
/ ontrialbegin = [
    mouse.x = 50%;
    mouse.y = 50%;
]
/ stimulusframes = [1=o]
/ inputdevice = mouse
...
</trial>

but note that this will require the user to grant certain app permissions on some platforms (e.g. Macs).

You can have a script prompt the user and ask for certain permissions per
https://www.millisecond.com/support/docs/v6/html/language/attributes/requiredpermissions.htm


Hi Dave, it looks like this works! However, it's brought up another question.

At current, I am creating a loop on the same trial until the user makes a mouse click within a certain region of the screen. So when I loop back, it re-centers the mouse and essentially makes finishing the trial impossible.

Any recommendations on a workaround? I've tried setting the mouse.x & y at the end of the previous trial, but this appears to break my branching...

<trial first_recall3>    
/ stimulustimes = [0 = color_wheel, FixationCross, resp_probe, probe2_holder, probe3_holder]
/ inputdevice = mouse
/ validresponse = ("lbuttondown")
/ timeout = 50
/ recorddata = true
/ ontrialend = [
    values.temp_resp = trial.first_recall3.response;
    values.final_RT = trial.first_recall3.latency;
    values.recall_x = mouse.x-parameters.center_x;
    values.recall_y = mouse.y-parameters.center_y;

    values.recall_radius = sqrt(pow(values.recall_x, 2)+pow(values.recall_y, 2));
    if (abs(parameters.wheel_r_px-values.recall_radius)<parameters.wheel_inrange_px){
        values.recall_inrange = 1
    } else {
        values.recall_inrange = 0
    }
    
    values.recall_angle = atan2(values.recall_y, values.recall_x)*180/M_PI;
    if (values.recall_angle<=0){
        values.recall_angle=values.recall_angle+360;
    };
    
    values.recall_angle_index = round(values.recall_angle)+(values.current_wheel*30);
    if (values.recall_angle_index>360){
        values.recall_angle_index = values.recall_angle_index-360;
    };
]
/ branch = [
    if (values.recall_inrange == 1 && values.recall_angle_index>0){
        values.resp_index = values.recall_angle_index;
        if (trial.first_recall3.response == "lbuttondown"){
            trial.last_recall3
        } else {
            trial.first_recall3
        };        
    } else {
        trial.first_recall3
    };

]
</trial>

Sorry, that code snippet is not helpful. Could you please comment your code? It's also unclear what "previous trial" refers to, I only see code for a single trial element. I also cannot find any spot in the code snippet you posted where you recenter the mouse.
<trial first_recall3>    # Participant is going to report a cued color from a color wheel
/ stimulustimes = [0 = color_wheel, FixationCross, resp_probe, probe2_holder, probe3_holder]     # At start, a color wheel, fixation cross, and 3 empty circles are shown at the location of 3 original memoranda
/ inputdevice = mouse
/ validresponse = ("lbuttondown")     # The participant is going to report the remembered color by clicking on the color wheel where that color falls
/ timeout = 50      # We loop the trial every 50 ms
/ recorddata = true
/ ontrialend = [
  values.temp_resp = trial.first_recall3.response;      # Save the response, RT, and location of the mouse click
  values.final_RT = trial.first_recall3.latency;
  values.recall_x = mouse.x-parameters.center_x;
  values.recall_y = mouse.y-parameters.center_y;

  values.recall_radius = sqrt(pow(values.recall_x, 2)+pow(values.recall_y, 2));      # We use the mouse coordinates to determine if the click happened on the wheel or not. Only care about on wheel clicks
  if (abs(parameters.wheel_r_px-values.recall_radius)<parameters.wheel_inrange_px){
   values.recall_inrange = 1
  } else {
   values.recall_inrange = 0
  }
 
  values.recall_angle = atan2(values.recall_y, values.recall_x)*180/M_PI;       # I convert mouse click coordinate to degrees to figure out of their mouse trajectory relative to the screencenter
  if (values.recall_angle<=0){
   values.recall_angle=values.recall_angle+360;
  };
 
  # Because the wheel is randomly rotating every trial in increments of 30 degrees, I account for this when I determine the angle
  values.recall_angle_index = round(values.recall_angle)+(values.current_wheel*30);     
  if (values.recall_angle_index>360){
   values.recall_angle_index = values.recall_angle_index-360;
  };
]
/ branch = [
  if (values.recall_inrange == 1 && values.recall_angle_index>0){       # Only collect responses that were (1) on the wheel and (2) greater than zero although (2) is a redundancy of the correction I do above
   values.resp_index = values.recall_angle_index;
   if (trial.first_recall3.response == "lbuttondown"){
    trial.last_recall3
   } else {
    trial.first_recall3
   };  
  } else {
   trial.first_recall3
  };

]
</trial>

I've left comments following hashtags throughout each section of the tria
Dave
Dave
Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)
Group: Administrators
Posts: 12K, Visits: 98K
jmsaito - 1/26/2022
jmsaito - 1/26/2022
Dave - 1/26/2022
jmsaito - 1/26/2022
Dave - 1/26/2022
jmsaito - 1/26/2022
I saw that someone asked 12 years ago if you can initialize a trial with the mouse at the center of the screen (https://www.millisecond.com/forums/Topic3965.aspx).

The conclusion at that time was that this was not possible. Has this changed? If so, how do I do this?

You can do

<trial mytrial>
/ ontrialbegin = [
    mouse.x = 50%;
    mouse.y = 50%;
]
/ stimulusframes = [1=o]
/ inputdevice = mouse
...
</trial>

but note that this will require the user to grant certain app permissions on some platforms (e.g. Macs).

You can have a script prompt the user and ask for certain permissions per
https://www.millisecond.com/support/docs/v6/html/language/attributes/requiredpermissions.htm


Hi Dave, it looks like this works! However, it's brought up another question.

At current, I am creating a loop on the same trial until the user makes a mouse click within a certain region of the screen. So when I loop back, it re-centers the mouse and essentially makes finishing the trial impossible.

Any recommendations on a workaround? I've tried setting the mouse.x & y at the end of the previous trial, but this appears to break my branching...

<trial first_recall3>    
/ stimulustimes = [0 = color_wheel, FixationCross, resp_probe, probe2_holder, probe3_holder]
/ inputdevice = mouse
/ validresponse = ("lbuttondown")
/ timeout = 50
/ recorddata = true
/ ontrialend = [
    values.temp_resp = trial.first_recall3.response;
    values.final_RT = trial.first_recall3.latency;
    values.recall_x = mouse.x-parameters.center_x;
    values.recall_y = mouse.y-parameters.center_y;

    values.recall_radius = sqrt(pow(values.recall_x, 2)+pow(values.recall_y, 2));
    if (abs(parameters.wheel_r_px-values.recall_radius)<parameters.wheel_inrange_px){
        values.recall_inrange = 1
    } else {
        values.recall_inrange = 0
    }
    
    values.recall_angle = atan2(values.recall_y, values.recall_x)*180/M_PI;
    if (values.recall_angle<=0){
        values.recall_angle=values.recall_angle+360;
    };
    
    values.recall_angle_index = round(values.recall_angle)+(values.current_wheel*30);
    if (values.recall_angle_index>360){
        values.recall_angle_index = values.recall_angle_index-360;
    };
]
/ branch = [
    if (values.recall_inrange == 1 && values.recall_angle_index>0){
        values.resp_index = values.recall_angle_index;
        if (trial.first_recall3.response == "lbuttondown"){
            trial.last_recall3
        } else {
            trial.first_recall3
        };        
    } else {
        trial.first_recall3
    };

]
</trial>

Sorry, that code snippet is not helpful. Could you please comment your code? It's also unclear what "previous trial" refers to, I only see code for a single trial element. I also cannot find any spot in the code snippet you posted where you recenter the mouse.
<trial first_recall3>    # Participant is going to report a cued color from a color wheel
/ stimulustimes = [0 = color_wheel, FixationCross, resp_probe, probe2_holder, probe3_holder]     # At start, a color wheel, fixation cross, and 3 empty circles are shown at the location of 3 original memoranda
/ inputdevice = mouse
/ validresponse = ("lbuttondown")     # The participant is going to report the remembered color by clicking on the color wheel where that color falls
/ timeout = 50      # We loop the trial every 50 ms
/ recorddata = true
/ ontrialend = [
  values.temp_resp = trial.first_recall3.response;      # Save the response, RT, and location of the mouse click
  values.final_RT = trial.first_recall3.latency;
  values.recall_x = mouse.x-parameters.center_x;
  values.recall_y = mouse.y-parameters.center_y;

  values.recall_radius = sqrt(pow(values.recall_x, 2)+pow(values.recall_y, 2));      # We use the mouse coordinates to determine if the click happened on the wheel or not. Only care about on wheel clicks
  if (abs(parameters.wheel_r_px-values.recall_radius)<parameters.wheel_inrange_px){
   values.recall_inrange = 1
  } else {
   values.recall_inrange = 0
  }
 
  values.recall_angle = atan2(values.recall_y, values.recall_x)*180/M_PI;       # I convert mouse click coordinate to degrees to figure out of their mouse trajectory relative to the screencenter
  if (values.recall_angle<=0){
   values.recall_angle=values.recall_angle+360;
  };
 
  # Because the wheel is randomly rotating every trial in increments of 30 degrees, I account for this when I determine the angle
  values.recall_angle_index = round(values.recall_angle)+(values.current_wheel*30);     
  if (values.recall_angle_index>360){
   values.recall_angle_index = values.recall_angle_index-360;
  };
]
/ branch = [
  if (values.recall_inrange == 1 && values.recall_angle_index>0){       # Only collect responses that were (1) on the wheel and (2) greater than zero although (2) is a redundancy of the correction I do above
   values.resp_index = values.recall_angle_index;
   if (trial.first_recall3.response == "lbuttondown"){
    trial.last_recall3
   } else {
    trial.first_recall3
   };  
  } else {
   trial.first_recall3
  };

]
</trial>

I've left comments following hashtags throughout each section of the tria

(1) There's actually syntax for inline comments: // comment goes here
(2) I still don't see anything that explains what you mean when you refer to " the previous trial."
(3) I still don't see any place where an attempt is made to set mouse coordingates to center.

I suggest the following course of action:
- Create a short, condensed and commented script that captures the essence of what you want to do. Provide that script and any external files (e.g. images) it requires to run by attaching it to your post.
- Explain -- clearly -- what you cannot get to work or what you believe to be not working properly. "I've tried setting the mouse.x & y at the end of the previous trial, but this appears to break my branching..." is not something that makes sense without the proper context.

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Reading This Topic

Explore
Messages
Mentions
Search