Howdy, Stranger!

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

Supported by

Possibility of converting inline_script (Python) in OpenSesame interface

Hello!

I would like to know if there is a chance to use this script in OpenSesame without Python (to be able to run the experiment in OSWeb and Jatos).

My structure is that I have in block loop set of pictures as Pic1 and Pic2 and also two positions - Pos1 and Pos2. Positions are shaffled, so I can not suggest that press 'w' will always be the right answer and etc.

And also I have a timeout for a participant response.

my_keyboard = Keyboard(keylist=[u'w', u'p'], timeout=2000)
start_time = clock.time()
key, end_time = my_keyboard.get_key()
var.response = key
var.response_time = end_time - start_time

var.response_timeout = int(var.response is None)

if var.pos1 == "centerleft":
    correct_answer = "w"
else:
    correct_answer = "p"

if correct_answer == var.response:
    var.total_correct  += 1

Thank you all in advance!

Comments

  • Hi @Daria ,

    Based on this code, it doesn't seem to me that you need any script at all. You can simply use a keyboard_response to replace the first part of the code, which collects a key press and does some basic bookkeeping. And then, in the block_loop (or wherever pos1 is defined) also create a column for the variable correct_response and set it to 'w' whenever pos1 is 'centerleft', and to 'p' if pos1 has a different value.

    Hope this helps!

    -- Sebastiaan

  • Thank you, @sebastiaan . Still can not understand completely.

    Right now my block_loop looks like this.

    I am shuffling pos1 and pos2 randomly.

    You suggesting creating just pos instead of pos1 and pos2? and it will be centertight and centerleft and so on? and create correct_response with 'w' and 'p'?

    pic1 is always the correct answer in my experiment.


    Thank you!

  • edited July 2021

    Hi @Daria ,

    I am shuffling pos1 and pos2 randomly.

    If you mean that you're shuffling these columns independently, with a shuffle operation in the script of the loop item, then my suggestion indeed won't work because the shuffling will break the correspondence between the columns. (Or, to put it differently, values from the same row won't be kept together.)

    In that case, you can use a simple inline_javascript item the start of the trial sequence with the following code in the prepare phase:

    if (vars.pos1 === "centerleft") {
        vars.correct_response = "w"
    } else {
        vars.scorrect_response = "p"
    }
    

    This will set the correct_response variable based on pos1 with the same logic as your previous script.

    -- Sebastiaan

  • @sebastiaan

    Yes, but that would mean that I won't be able to run my experiment online :(


    Thank you

  • Yes, but that would mean that I won't be able to run my experiment online :(

    No you would be able to do that! You can include JavaScript in an OSWeb experiment as described on this page:

Sign In or Register to comment.