Howdy, Stranger!

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

Supported by

Building new log - stuck with one variable

edited November 2017 in OpenSesame

Hello all,

I am trying to log a new variable. But I don't have enough knowledge in OpenSesame to be able to do this.
Could you please help?

I don't know where to write the definition of this variable : [correct_response] + 1200 - [cursor_x]
The output I am trying to get, in .csv file, is this:
A column in .csv of a new variable that takes the var.correct_response add 1200 and reduce from it the X coordinates of where the participant clicked with the mouse button 1.

This is what I have done so far but it doesn't work:
I have wrote it in python inline_script but it gave me an error:

prepare phase:

    def difference(correct_response, cursor_x):
        [correct_response] + 1200 - [cursor_x]
        return difference

At the run phase I tried to build a new log file in Py_inline_script
Run phase:

    log.write(u'My custom log message')
    log.var.anchor_pos_H8
    log.var.anchor_pos_M8
    log.var.average_response_time
    log.var.avg_rt
    log.var.correct_reponse
    log.var.cursor_x
    log.var.cursor_y
    log.var.exercise_pos
    log.var.response_time_new_mouse_response_3
    log.var.response_time_new_mouse_response_3_1
    log.var.response_time_new_mouse_response_3_1_1
    log.var.difference

The error:

     Inline script, line 5, in <module>
    AttributeError: 'csv' object has no attribute 'var

I know there are many misteks here but I don't know where they are.
I would like to understand what is the correct syntax for building a custom log
and where and how to write my new variable [difference].

Many thanks,
Matanel.

Comments

  • Hi Matanel,

    Why do you want to write a new logfile? To be precise, you are describing two issues that are unrelated: 1) How to define a new variable based others, 2) How to make anew logfile

    To solve your issue, remove the brackets [ ] in your function definition. Or, even simpler, just write:
    var.difference = var.correct_response + 1200 - var.cursor_x or var.difference = var.correct_response + 1200 - cursor_x if cursor_x is the variable name. Just make sure you do that after var.correct_response will be defined.

    See also here: http://osdoc.cogsci.nl/3.1/manual/variables/#using-variables-in-python

    Eduard

    Buy Me A Coffee

  • Thanks a lot! It was much more simple then I thoght! But I have another question if I may:
    I Just did this :
    (x,y), timestamp = my_mouse.get_pos()
    var.difference = var.correct_response + 1200 - x

    And it worked - I don't need to re-write the Logger thank god.

    But I am confused because this code: my_mouse.get_pos() gives me other coodinates then this variable: cursor_x. I am Using the most updated version of Opensesame. 3. +

    I need this variable cursor_x - this variable I can only find in the Log item (it looks like it is a built in variable cursor_x in open sesame). The problem is - the variable cursor_x gives different coordinates then
    this my_mouse = mouse()
    (x, y), timestamp = my_mouse.get_pos()

    I need this one cursor_x - because it works better for me when I use the sketchpad item (I use the sketchpad coordinates - cursor_x relates to the sketchpad coordinates but my_mouse = mouse()
    (x, y), timestamp = my_mouse.get_pos() - does not.)

    I tried to look at the log item what is the source of cursor_x

  • edited November 2017

    ignore the previous comment.
    .

    1)In short I don't understand what is the output of Cursor_x - a variable one can only find at the log item.
    and to what coordinates it relates to ?

    2)my_mouse = mouse()
    (x,y), timestamp = my_mouse.get_pos()
    to what coordinates it relates to ?

    3)Why Cursor_x and (x,y), timestamp = my_mouse.get_pos() = why they give different output?

    I use a sketchpad - so I need the coordinates of the sketchpad- wich I know the scketch pad starts at (0,0) of the display.

  • Hi,

    2) (x,y), timestamp = my_mouse.get_pos() to what coordinates it relates to ?

    Like explained here: http://osdoc.cogsci.nl/3.1/manual/python/mouse/#function-mouse46get95pos4041

    mouse.get_pos() returns the current position of the mouse on the screen. I'm not sure what the coordinate system is. Probably with (0,0) in the center of the screen. Note: it does not wait for a click! If you want the position of a click, you have to use ms.get_click()

    What is cursor_x exactly? If it is a variable defined by yourself, you should know how it relates to the position returned by ms.get_pos(). I'm not aware that there is a default variable in Opensesame called that. So, you probably created it yourself.

    Does that make sense?
    Eduard

    Buy Me A Coffee

  • Thanks Eduard for your reply and answers.

    I didn't define my self the var.cursor_x
    I think that ones you use the item: mouse_response.
    I challenge you to check it out - put the item mouse_response and then go to variable inspector - and you will find it without self defining it.

  • 3)Why Cursor_x and (x,y), timestamp = my_mouse.get_pos() = why they give different output?

    Ok, cursor_x is written by the mouse response item, and is the mouse position's x coordinate in the moment of a mouse click. my_mouse.get_pos() however, returns the current mouse position irrespective of whether it was clicked or not. They just don't measure the same thing.

    Is that clearer?

    Eduard

    Buy Me A Coffee

Sign In or Register to comment.