Howdy, Stranger!

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

Supported by

Variable Feedback

Hi, since I am still a beginner, I struggle with some of the (supposedly basic) stuff: I want to show the text "Wrong!" when the wrong key was pressed and "Too slow!" when nothing was pressed, but if I use [correct] as variable for "Wrong" it is shown when nothing was pressed as well, so what variable do I have to use, to make it work?

Additionally, I want to use a custom keyboard, is there an easy way to implement this?

Comments

  • Hi,

    If a timeout occurred, the response variable will be set to None. So for the sketchpad with the text "Wrong!" you would use the following run-if statement:

    [correct] = 0 and [response] != None
    

    Whereas for the "Too slow!" sketchpad you would use the following run-if statement:

    [response] = None
    

    Additionally, I want to use a custom keyboard, is there an easy way to implement this?

    What do you mean with a 'custom keyboard'?

    Cheers!

    Sebastiaan

  • edited January 2020

    Hi, thanks for the help.

    With 'custom keyboard' I mean a response pad with 4 buttons, which can be accessed via ports, so I can't just use the normal keyboard response, but had to write an inline script where I access the port. I tried the following code, but I get an 'invalid syntax' (I think for the if condition), do you know why, and if the code would be working as intended?


    timeout_start = clock.time()
    timeout = 2000
    while clock.time() < timeout_start + timeout:
    	var.response = io.DlPortReadPortUchar(port+1)
    	if var.response == (4 or 5 or 6 or 7)
    		var.response_time = clock.time() - timeout_start
    		break
    
  • Hi,

    There are a few things wrong with this line:

    if var.response == (4 or 5 or 6 or 7)
    

    First, it should end with a : . So that's where the SyntaxError comes from. (Without the colon it's not valid Python).

    Then, the expression (4 or 5 or 6 or 7) means something different from what you intend. Specifically, x or y evaluates to x if x is True , and to y otherwise. To Python, any number that is not 0 is True , and thus (4 or 5 or 6 or 7) evaluates to 4. And thus you're asking whether the response is 4! (This is admittedly not a very intuitive property of Python.)

    What you mean instead is whether the response is in a tuple of values:

    if var.response in (4, 5, 6, 7):
    

    In general, I would recommend walking through a basic Python tutorial first. This will take a little bit of time (but not much), and it will save a lot of frustration in the medium-to-long term because you will have a better grasp on the code that you're writing!

    Cheers!

    Sebastiaan

  • Thank you for your help, my experiment is working now.

    Only one thing is bothering me, I tried the following line in an inline script to determine how long it takes and it takes more than 400 ms, is this normal? Is there anything I can do?

    DlPortWritePortUchar(port,trigger)

    I don't understand why writing to a port takes that much time. Maybe Opensesame waits until the EEG received the value?

  • Hi,

    Are you sure the delay doesn't come from code before or after that line? How did you measure the delay? Normally sending things via the port is not taking a lot of time.


    Eduard

    Buy Me A Coffee

  • edited February 2020

    Hi Eduard,

    I used the measurements from the keylogger. In the picture you can see the structure of the experiment, I just subtracted the times from script 8 and 11.

    Script 11 Only contains the line: "DlPortWritePortUchar(port,trigger)".


    Edit:

    Regarding your suggestion with codes before or after, I deleted everything, except the inline scripts for the ports, and the result is even worse:


  • Hi,

    You better test it directly like this:

    t0=clock.time()
    DlPortWritePortUchar(port,trigger)
    t1 = clock.time()
    var.duration = t1-t0
    

    Otherwise there might be other processes that run in the background or things that also occur in these two inline_scripts that will cause the delay. If you try it like that, does the delay still occur?

    Eduard

    Buy Me A Coffee

  • edited February 2020

    Hi, thanks for the suggestion. With your code, the resulting duration for the write operation is just about 0.03 ms. Though that doesn't make it any clearer to me. I don't know if your additional lines made a difference, but on average a trial now needs 150 ms (with the two inline scripts and the logger). So what is causing this huge duration, if its not the port write operation? Does Opensesame need time to go to the next trial?

    Additionally here is a picture of the tasks running in the background, if that helps.


  • I suppose the reason is the run/prepare strategy of Opensesame: https://osdoc.cogsci.nl/3.2/manual/prepare-run/

    I don't know what your code does, but some things take time, such as drawing onto a canvas. The more you draw the longer it takes. To find out you can do what I did. Measuring the duration of a piece of your code one at a time, until you find the process that causes the delay. If you are lucky, you'll be able to fix it by programming more efficiently.

    Good luck,

    Eudard

    Buy Me A Coffee

  • edited February 2020

    Hi, thanks for the quick response.

    I did another test with my initial experiment and on average it takes 372 ms longer, than expected with 290 ms of that coming from the logger at the end of the trial and 65 ms from the inline script reading the port for the response and consequently sending the value to the EEG. I suppose I can disregard the logger time, as its not a time critical part. I read through the run-prepare documentation, but don't really understand what exactly I can put in prepare, so could you take a look at the critical code and tell me if there is a part I could put in the prepare section?

    If there isn't anything to improve the duration I suppose I would subtract the duration of the duration of the successive object. (Edit: Why does "~~~" not work to post code?)

    ~~~

    io.DlPortWritePortUchar(port+2,1)

    clock.sleep(1)

    io.DlPortWritePortUchar(port+2,0)

    clock.sleep(1)

    timeout_start = clock.time()

    timeout = 2000

    while clock.time() < timeout_start + timeout:

    var.response = io.DlPortReadPortUchar(port+1)

    if var.response == 64 or var.response == 160 or var.response == 136 or var.response == 144:

    if var.response == 160:

    io.DlPortWritePortUchar(port,1)

    elif var.response == 64:

    io.DlPortWritePortUchar(port,2)

    elif var.response == 136:

    io.DlPortWritePortUchar(port,3)

    elif var.response == 144:

    io.DlPortWritePortUchar(port,4)

    timeout = clock.time() - timeout_start

    break


    var.star_dur = 2500 - timeout

    ~~~

Sign In or Register to comment.