Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

How to use ROI to get a right 'good' response

edited April 2018 in OpenSesame

Hi all,
New with you since few days. Coming from Java world, Python is somehow tricky for me !
Here is my problem (question)
I have a sketchpad with 2 named fields ('Diff' and 'Ident') on which the participant clicks depending he have distinguished two identical or different Phonemes (here is the e and the è, in french)
I have an inline script running before "mouse response" to set the correct response (son1 and son2 are the 2 variables containing the name of the ogg files to be heard)

         if (var.son1 == var.son2):
            var.roi_correct_response = "Ident"
        else:
            var.roi_correct_response = "Diff"

And then the following inline script after "mouse response"

        if var.roi_correct_response == var.cursor_roi:
            var.correct = var.correct + 1

It gives TypeError: coercing to Unicode: need string or buffer, int found

Any clue ? And another question, is it the right thing to do to calculate the acc value, because I think I should work with correct_response and response, too, shouldn't I ? Or any simpliest solution !

Important remark : there is no feedback inside the loop

Thanks a lot

Comments

  • Hi,

    If you get an error like that, you always get a 'stacktrace', which tells you exactly which line in your code the error comes from. So in the future make sure you include that in your question. In your case, I'm guessing this line is the culprit:

    var.correct = var.correct + 1
    

    There are two things wrong with this:

    First, this will crash if var.correct is not a number (int or float), and in some cases it won't be. For example var.correct can be 'undefined', i.e. a str object. So that's probably what's happening here.

    Second, the consensus is that var.correct is 1 after a correct response, and 0 after an incorrect response. Whereas you appear to want to use it as an incremental variable that keeps track of the total number of correct responses.

    The following would make more sense to me (in the process illustrating the concept of an if expression):

    var.correct = 1 if var.roi_correct_response == var.cursor_roi else 0
    

    Cheers!
    Sebastiaan

  • Thank you Sebastian,
    That's fine. I do not have the problem anymore (I was thinking that initializing correct in a previous inline script was OK but I understand your code)
    Can you confirm that :

    • we can not directly use the ROI in the mouse response definition (saying that a correct response is a name of a field in the linked sketchpad)
      And another recurrent question I have : how can I restrict the click on only the ROI (ignoring a click on "nothing") ?
      Thanks another time for your great work. It will help me (as a french teacher for foreign people wit phonetics complexity) and my wife ( as a Orthophonist)
      Greetings Christophe
  • how can I restrict the click on only the ROI (ignoring a click on "nothing") ... was quite obvious using 'repeat cycle' with ''[cursor_roi] != 'Diff' and [cursor_roi] != 'Ident'' ..

  • we can not directly use the ROI in the mouse response definition (saying that a correct response is a name of a field in the linked sketchpad)

    That's right. The correct response refers to the mouse button, and not to the ROI.

    Good to hear that you got things working!

  • Thanks a lot! Going further how to have a full experience available for my Adults Students working on phonetics complexity with French !
    Building dynamic content for table in loop block is very powerfull .. when understood !
    I really like openSesame (usability, open to advanced programming, and availability of the team).
    Thanks

  • This is the way I did

    to initialize the counters
    var.myAcc = None
    var.totalCorrect = 0
    var.totalNoTrials = 0

    to calculate the needed info for feedback (var.cursor_roi contains the roi cliked on, and var.roi_correct_response contains the correct ROI) :
    if var.roi_correct_response == var.cursor_roi:
    var.totalCorrect += 1
    else:
    var.totalCorrect
    if var.cursor_roi != '':
    var.totalNoTrials += 1
    var.myAcc = (float(var.totalCorrect)/var.totalNoTrials)*100

    I do not know if this is the best choice ... At least it works !!!

  • @cleroux1998


    Hey there.

    I'm new to OS and have a similar problem. I have 9 ROI on my Sketchpad, of which one ist the target. I want the variable totalCorrect (as you defined it) count the correct responses what does not seem to work. Only if all 5 responses in my practice set are correct, the variable counts 1. If one is false it counts 0. Same with totalNoTrials. This is my inline script (run after mouse_response) I copied from here using your variables as well except correct_cursor_roi:


    if var.correct_cursor_roi == var.cursor_roi:

    var.totalCorrect += 1 

    else:

    var.totalCorrect

    if var.cursor_roi != '':

    var.totalNoTrials += 1


    I don't get any Error Messages with that.

  • I managed the counting problem now.

    @cleroux1998

    I too want nothing to happen if subjects miss the ROI, meaning my target and distractors. How did you manage that? I couldn’t figure it out through your comment.

  • Hi,

    I think this part of Cleroux's response is relevant:

    how can I restrict the click on only the ROI (ignoring a click on "nothing") ... was quite obvious using 'repeat cycle' with ''[cursor_roi] != 'Diff' and [cursor_roi] != 'Ident'' ..

    So, basically in the repeat_cycle field of the loop, specify conditions that will repeat the loops unless the response has been one of the buttons. Does that make sense?

    Eudard

    Buy Me A Coffee

  • I tried to implement this solution but it is not really perfect for me. is there any way to restrict mouse clicks completely if not on predefined ROI?

    Thanks a lot!

  • I don't know whether and how this would be possible. Can you maybe elaborate in how far this would be a problem?

    Thanks,

    Eduard

    Buy Me A Coffee

Sign In or Register to comment.