Howdy, Stranger!

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

Supported by

Moving Objects

Hello everyone!


I have you used Open Sesame -> OSWeb -> JATOS for one experiment already, and it worked perfectly.

I want to say thanks to all the contributors for working on this; it is highly appreciated! 😊

Now I am trying to do something more complicated, and I encountered a couple of problems:


1: I am aware of the Timing limitations when looping Sketchpads in Sequences, but I was wondering, is there a way to go around that? For example, if I loop Sketchpads in Loops, there is no timing limitation, but I cannot have any other item inside. Can I somehow squeeze a bit of code inside of Loop or something similar?

2: Let's say I am creating a horizontally moving square at the top of the screen by manually putting Sketchpads one after the other in a Sequence. After a specific time, I make a target appear, and I want a person to react to it with a keyboard press WHILE the square still keeps moving. When playing with keyboard responses, I couldn't find a solution to it, it always had to wait for a keypress, and objects could not move while this was happening. Do you know a solution to this problem?


Thanks,


Saša

Comments

  • Hi Saša,

    1

    The timing limitation only refers to transitions between prepare and run phases. So, even if there is a little code in the run phase (in between sketchpads) timing should largely be unaffected. But of course that depends on your specific experiment. So, either way, best to test your timing to know for sure.

    When playing with keyboard responses, I couldn't find a solution to it, it always had to wait for a keypress, and objects could not move while this was happening. Do you know a solution to this problem?

    Working with sketchpads and keyboard items this is indeed a bit tricky. I think it should be possible if you set the duration of the keyboard to some small value (< 5), and untick the box "Flash pending responses". This should essentially do the trick. However, it should be much easier to accomplish by applying a coding approach. Since the latest release, Opensesame supports quite a bit of javascript and interaction with canvases, etc. So you could essentially built a while loop (similar to your current loop), in which you update the position and visibility of your box and your target, while also polling key presses. This part of the documentation should be of particular interest to you.

    I hope this helps.

    Eduard

    Buy Me A Coffee

  • edited October 2021

    Hi @eduard,

    Thank you for your answer. I believe I will try to code everything instead of playing with the elements. It seems like a better approach, and the new release made it more accessible!

    I will post here in the next couple of days if I have any problems.

    Cheers,

    Saša

  • Hi @eduard

    It wasn't a problem to build a loop, but how to "poll key presses" in inline javascript?

    Cheers,

    Saša

  • Hi Saša,

    Oh sorry, I assumed the keyboard item would also be available in Osweb, but as far as I can see it isn't. However, there are some code snippets around in the forum that do collect responses. For example, see here:

    I haven't check the implementation though, so I can't tell you, whether it is applicable to your situation. You might be able to also use javascript event handlers, but how exactly, I don't know unfortunately. Perhaps @Fab can share his js wisdom? :)

    Good luck,

    Eduard

    Buy Me A Coffee

  • Hi @SaleSarma & @eduard,

    Can't really say I've achieved any wisdom in Javascript yet (only just begun to try to use it). Hopefully some day! 😉

    I do not know whether you can create keyboard objects directly from Javascript within OSWeb. I think you can access and change a lot of stuff that features in browser's debugger if you can work out your way around it, but I'm not sure creating a keyboard object directly from code is possible (you might want to consult @sebastiaan on this).

    Digging around a little on the internet, I did come across something that might be of use to you, though I don't know how your task is actually set up, so maybe it isn't... There is a function in Javascript called addlistener that allows you to listen to a series of events (mouse clicks, keydown, keyup etc.).

    I think that sticking it into the loop presenting your stimuli might be a way to go:

    window.addEventListener('keydown', (event) => {
    // your code here
    });
    

    I've had a quick go at trying it out with a task containing a loop running 1000 times and displaying a random number on the screen (just to see something happening on the screen; in your case I understand it would be an object being moved to a different position).

    I can get key presses detected and the key displayed on the screen, as well as the time stamp for the response. I tried to implement a response counter but for some reason that isn't working as I'd like (I think it might be because the code is executed so fast that pressing a response key probably generates not one but several consecutive keydown detection events and so the response counter is incremented multiple times in quick succession when a key is down). Might make it tricky to log the responses...

    Anyway... Don't know if that can be of help to you but that's what I could find out based on my limited experience with Javascript.

    Best,

    Fabrice.

    Buy Me A Coffee

  • I'm not sure creating a keyboard object directly from code is possible 

    There is indeed currently no Keyboard object in JavaScript as there is in Python. If you want to implement custom key-press handling, the way to go is (as @Fab already pointed out) to implement a custom event listener for keydown events!

  • Hi @eduard, @Fab, and @sebastiaan,

    You have been of great help, and it works like a charm. Thank you very much!

    I have one more question that I didn't find a solution to, is there a way to play a simple sound (like a "beep") inside of an inline javascript?

  • @SaleSarma Yes. Assuming that there's a sound file called bark.ogg in the file pool, then you can play it like this:

    pool['bark.ogg'].data.play()
    
Sign In or Register to comment.