Millisecond Forums

display error message once mouse movement stops for 200ms

https://forums.millisecond.com/Topic29981.aspx

By peter.k.p - 10/25/2020

Hi there,
I want to display an error message when the mouse movement stops for 200ms in a trial (see for what I tried below which does not work yet). I also want to add a /timeout for 4000ms. Is there a way to specify both within one trial? Thanks for all suggestions, I appreciate it.


<trial ydecrease>
/ ontrialbegin = [
       values.errortype = 2
        values.starttime = script.elapsedtime;
]
/ inputdevice = mouse
/ stimulusframes = [1 = clearscreen, left, right, stim_left, default_stim_right]
/ timeout = 200
/ validresponse = (mousemove,noresponse)
/ responsetrial = ("noresponse", trial.error) // if there is no mouse movement for 200ms show error message
/ ontrialend = [
    values.mouse_change = abs(values.mouse_y - trial.ydecrease.responsey);
]
/ branch = [
    if (expressions.ismouseinrectangle) {
        return trial.clickresponse;
        values.mouse_y = trial.ydecrease.responsey;        
    } else if (trial.ydecrease.responsey <= values.mouse_y) {
        values.mouse_y = trial.ydecrease.responsey;
        return trial.ydecrease;
    } else if (trial.ydecrease.responsey > values.mouse_y) {
        values.changedirection += 1;
        values.errortype = 1;
        return trial.error;}
]
/recorddata = true
</trial>


<trial error>
/ inputdevice = mouse
/ ontrialbegin = [
        values.starttime = script.elapsedtime;
        if(values.errortype == 1)
        trial.error.insertstimulustime(text.error_moved_down, 0)
        else if(values.errortype == 2)
        trial.error.insertstimulustime(text.error_movement_stopped, 0)
        else if(values.errortype == 3)
        trial.error.insertstimulustime(text.error_no_click, 0)
]
/ stimulusframes = [1 = clearscreen]
/ validresponse = (0)
/ timeout = 1000
/ branch = [
        values.mouse_y = trial.error.responsey;
        values.finalresponse = "aborted";
        trial.pressstart
]
/ recorddata = true
</trial>


<text error_moved_down>
/ items = ("Mouse moved down!")
/ position = (50%, 50%)
/ fontstyle = ("Arial", 5%, true, false, false, false, 5, 0)
/ txcolor = white
/ txbgcolor = red
/ erase = ""
</text>

<text error_movement_stopped>
/ items = ("Mouse movement stopped!")
/ position = (50%, 50%)
/ fontstyle = ("Arial", 5%, true, false, false, false, 5, 0)
/ txcolor = white
/ txbgcolor = red
/ erase = ""
</text>

<text error_no_click>
/ items = ("Response too slow!")
/ position = (50%, 50%)
/ fontstyle = ("Arial", 5%, true, false, false, false, 5, 0)
/ txcolor = white
/ txbgcolor = red
/ erase = ""
</text>

By Dave - 10/26/2020

licka - 10/25/2020
Hi there,
I want to display an error message when the mouse movement stops for 200ms in a trial (see for what I tried below which does not work yet). I also want to add a /timeout for 4000ms. Is there a way to specify both within one trial? Thanks for all suggestions, I appreciate it.


<trial ydecrease>
/ ontrialbegin = [
       values.errortype = 2
        values.starttime = script.elapsedtime;
]
/ inputdevice = mouse
/ stimulusframes = [1 = clearscreen, left, right, stim_left, default_stim_right]
/ timeout = 200
/ validresponse = (mousemove,noresponse)
/ responsetrial = ("noresponse", trial.error) // if there is no mouse movement for 200ms show error message
/ ontrialend = [
    values.mouse_change = abs(values.mouse_y - trial.ydecrease.responsey);
]
/ branch = [
    if (expressions.ismouseinrectangle) {
        return trial.clickresponse;
        values.mouse_y = trial.ydecrease.responsey;        
    } else if (trial.ydecrease.responsey <= values.mouse_y) {
        values.mouse_y = trial.ydecrease.responsey;
        return trial.ydecrease;
    } else if (trial.ydecrease.responsey > values.mouse_y) {
        values.changedirection += 1;
        values.errortype = 1;
        return trial.error;}
]
/recorddata = true
</trial>


<trial error>
/ inputdevice = mouse
/ ontrialbegin = [
        values.starttime = script.elapsedtime;
        if(values.errortype == 1)
        trial.error.insertstimulustime(text.error_moved_down, 0)
        else if(values.errortype == 2)
        trial.error.insertstimulustime(text.error_movement_stopped, 0)
        else if(values.errortype == 3)
        trial.error.insertstimulustime(text.error_no_click, 0)
]
/ stimulusframes = [1 = clearscreen]
/ validresponse = (0)
/ timeout = 1000
/ branch = [
        values.mouse_y = trial.error.responsey;
        values.finalresponse = "aborted";
        trial.pressstart
]
/ recorddata = true
</trial>


<text error_moved_down>
/ items = ("Mouse moved down!")
/ position = (50%, 50%)
/ fontstyle = ("Arial", 5%, true, false, false, false, 5, 0)
/ txcolor = white
/ txbgcolor = red
/ erase = ""
</text>

<text error_movement_stopped>
/ items = ("Mouse movement stopped!")
/ position = (50%, 50%)
/ fontstyle = ("Arial", 5%, true, false, false, false, 5, 0)
/ txcolor = white
/ txbgcolor = red
/ erase = ""
</text>

<text error_no_click>
/ items = ("Response too slow!")
/ position = (50%, 50%)
/ fontstyle = ("Arial", 5%, true, false, false, false, 5, 0)
/ txcolor = white
/ txbgcolor = red
/ erase = ""
</text>


You'll want to do something like this:

<values>
/ starttime = 0
/ mouse_y = 0
/ errortype = 0
/ mouse_change = 0
/ finalresponse = ""
/ changedirection = 0
/ timeremaining = 0
/ trialcount = 0
</values>

<expressions>
/ set_timeout = if (values.timeremaining >= 200) {
        200;
    } else {
        values.timeremaining;
    };
/ ismouseinrectangle = ((trial.ydecrease.responsey <= shape.left.bottom)
        && (trial.ydecrease.responsey >= shape.left.top)
        && (trial.ydecrease.responsex <= shape.left.right)
        && (trial.ydecrease.responsex >= shape.left.left)

        || (trial.ydecrease.responsey <= shape.right.bottom)
        && (trial.ydecrease.responsey >= shape.right.top)
        && (trial.ydecrease.responsex <= shape.right.right)
        && (trial.ydecrease.responsex >= shape.right.left));
</expressions>

<block example>
/ trials = [1-2 = pressstart]
</block>


<trial pressstart>
/ ontrialbegin = [
    values.trialcount = 0;
    values.timeremaining = 4000;
]
/ ontrialend = [
    values.mouse_y = trial.pressstart.responsey;
]
/ stimulusframes = [1=clearscreen, mytext]
/ validresponse = (lbuttondown)
/ inputdevice = mouse
/ branch = [
    trial.ydecrease;
]
</trial>

<trial ydecrease>
/ ontrialbegin = [
    values.trialcount += 1;
    values.errortype = 0;
    values.starttime = script.elapsedtime;
]
/ inputdevice = mouse
/ stimulusframes = [1 = clearscreen, mytext, left, right]
/ timeout = expressions.set_timeout
/ validresponse = (mousemove,noresponse)
/ ontrialend = [
  values.mouse_change = abs(values.mouse_y - trial.ydecrease.responsey);
    values.timeremaining -= trial.ydecrease.elapsedtime;
]
/ branch = [
  if (expressions.ismouseinrectangle) {
   return trial.clickresponse;
   values.mouse_y = trial.ydecrease.responsey;  
  } else if (trial.ydecrease.responsey <= values.mouse_y && values.timeremaining > 0 && trial.ydecrease.response != 0) {
   values.mouse_y = trial.ydecrease.responsey;
   return trial.ydecrease;
  } else if (trial.ydecrease.responsey > values.mouse_y) {
   values.changedirection += 1;
   values.errortype = 1;
   return trial.error;
    } else if (trial.ydecrease.response == 0 && values.timeremaining > 0) {
        values.errortype = 2;
        return trial.error;    
    } else if (trial.ydecrease.response == 0 && values.timeremaining <= 0) {
        values.errortype = 4;
        return trial.error;
    };
]
/recorddata = true
</trial>

<trial error>
/ inputdevice = mouse
/ ontrialbegin = [
        trial.error.resetstimulusframes();
   values.starttime = script.elapsedtime;
   if(values.errortype == 1)
   trial.error.insertstimulustime(text.error_moved_down, 0)
   else if(values.errortype == 2)
   trial.error.insertstimulustime(text.error_movement_stopped, 0)
   else if(values.errortype == 3)
   trial.error.insertstimulustime(text.error_no_click, 0)
        else if(values.errortype == 4)
   trial.error.insertstimulustime(text.error_timed_out, 0)
]
/ stimulusframes = [1 = clearscreen]
/ validresponse = (0)
/ timeout = 1000
/ branch = [
   values.mouse_y = trial.error.responsey;
   values.finalresponse = "aborted";
   trial.pressstart;
]
/ recorddata = true
</trial>

<text error_moved_down>
/ items = ("Mouse moved down!")
/ position = (50%, 50%)
/ fontstyle = ("Arial", 5%, true, false, false, false, 5, 0)
/ txcolor = white
/ txbgcolor = red
/ erase = ""
</text>

<text error_movement_stopped>
/ items = ("Mouse movement stopped!")
/ position = (50%, 50%)
/ fontstyle = ("Arial", 5%, true, false, false, false, 5, 0)
/ txcolor = white
/ txbgcolor = red
/ erase = ""
</text>

<text error_no_click>
/ items = ("Response too slow!")
/ position = (50%, 50%)
/ fontstyle = ("Arial", 5%, true, false, false, false, 5, 0)
/ txcolor = white
/ txbgcolor = red
/ erase = ""
</text>

<text error_timed_out>
/ items = ("Timed out!")
/ position = (50%, 50%)
/ fontstyle = ("Arial", 5%, true, false, false, false, 5, 0)
/ txcolor = white
/ txbgcolor = red
/ erase = ""
</text>

<trial clickresponse>
/ stimulusframes = [1=clearscreen, mytext]
/ validresponse = (lbuttondown)
/ inputdevice = mouse
</trial>

<text mytext>
/ items = ("<%script.currenttrial%>|<%expressions.set_timeout%>|<%values.timeremaining%>")
/ erase = false
</text>

<shape left>
/ shape = rectangle
/ color = blue
/ size = (4%, 3%)
/ position = (5%, 5%)
/ erase = false
</shape>

<shape right>
/ shape = rectangle
/ color = red
/ size = (4%, 3%)
/ position = (95%, 5%)
/ erase = false
</shape>