show error when mouse moves outside of image


Author
Message
peter.k.p
peter.k.p
Respected Member (378 reputation)Respected Member (378 reputation)Respected Member (378 reputation)Respected Member (378 reputation)Respected Member (378 reputation)Respected Member (378 reputation)Respected Member (378 reputation)Respected Member (378 reputation)Respected Member (378 reputation)
Group: Forum Members
Posts: 13, Visits: 307
Hi there,
I am having the following setup: Two images are displayed on the screen and one of them is to be selected by clicking on it. Once the mouse has moved over one of the images I want to restrict the mouse movement. The mouse is not supposed to move out of the image and when it does an error message is supposed to be displayed. So far I have the following which does not work:

<trial clickresponse>
/ ontrialbegin = [
        values.starttime = script.elapsedtime;
        values.errortype = 1]
/ stimulusframes = [1=left, right, stim_left, default_stim_right]
/ inputdevice = mouse
// validresponse = (left,right)
/ isvalidresponse = [
    if(trial.clickresponse.responsey > shape.left.bottom) {
        return trial.error
    }
]
</trial>


Any help is appreciated, thank you :)

peter.k.p
peter.k.p
Respected Member (378 reputation)Respected Member (378 reputation)Respected Member (378 reputation)Respected Member (378 reputation)Respected Member (378 reputation)Respected Member (378 reputation)Respected Member (378 reputation)Respected Member (378 reputation)Respected Member (378 reputation)
Group: Forum Members
Posts: 13, Visits: 307
licka - 10/25/2020
Hi there,
I am having the following setup: Two images are displayed on the screen and one of them is to be selected by clicking on it. Once the mouse has moved over one of the images I want to restrict the mouse movement. The mouse is not supposed to move out of the image and when it does an error message is supposed to be displayed. So far I have the following which does not work:

<trial clickresponse>
/ ontrialbegin = [
        values.starttime = script.elapsedtime;
        values.errortype = 1]
/ stimulusframes = [1=left, right, stim_left, default_stim_right]
/ inputdevice = mouse
// validresponse = (left,right)
/ isvalidresponse = [
    if(trial.clickresponse.responsey > shape.left.bottom) {
        return trial.error
    }
]
</trial>


Any help is appreciated, thank you :)

I have not found an edit option thus I am going to add something to my question by replying to my own post.
I added the code below that leads to the "clickresponse" trial. As you can see I used the expression "ismouseinrectangle" to determine that the "clickresponse" trial should start. Therefore with respect to my intital question the mouse is already over one of the images when the "clickresponse" trial starts.

<trial ydecrease>
/ ontrialbegin = [
   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 once they entered the box, there is no response –> 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>

<expressions>
/ 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>



GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Reading This Topic

Explore
Messages
Mentions
Search