Howdy, Stranger!

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

Supported by

OpenSesame: VAS scale slider bar using keypress

Hi there,

I've come across a few solutions for slider bars using mouse click but I'm trying to set up one using an fMRI button box (keypress) whereby multiple keypresses can move the slider during a set duration (12 sec) and at the end record the final slider position. However, I'm stuck and would appreciate some help.

This is what my canvas looks like:


And this is my code below. It displays the scales but the slider doesn't move (I have gotten it to move by one increment if there's no while loop). Also, I'm using 'm' and 'n' but ideally I'll set these to the keys triggered by our button box.

from openexp.canvas import canvas

from openexp.keyboard import keyboard

my_canvas = canvas(self.experiment)

my_keyboard = keyboard(self.experiment)

resp = "" # Here we store the response

timeout = 5000

score = 0

step_size = .2

start_time = clock.time()

while True:

if clock.time() - start_time >= timeout:

response_time = timeout

response = u'timeout'

key, time = my_keyboard.get_key()

if my_keyboard.to_chr(key) == "m":

score +=step_size

increment = score*200

my_canvas['slider'].x += increment

my_canvas['slider'].show()

elif my_keyboard.to_chr(key) == 'n':

my_canvas['slider'].x -= increment

my_canvas['slider'].show()

score = max(0, min(1, score))

exp.set('score', score)

set_response(response=response, response_time=response_time)


The osexp file is also attached.

Thanks,

Melanie


Comments

  • Hi Melanie,

    I took the freedom to adapt your experiment somewhat. I am not entirely sure whether I get all the details of what you need, but I think the attached experiment will bring you a nice step forward in achieving it.

    Good luck,

    Eduard


    Buy Me A Coffee

  • Hi Eduard - that worked, thanks so much! I have two more question about timing:

    How can I ensure that after the initial keypress to start the experiment, that the timings are absolute?

    For example, in my practice run I present 5 scales each with a timeout = 4950ms (to approximate 5s), but when I use a stop watch the whole trial is 50s, more than double what I was expecting it to be. Timing is very critical for my fMRI study because patients will also have deep brain stimulation delivering electrical impulses during certain blocks.

    Do I need another inline script after my "Get Ready" sketchpad message, to tell the program to wait for a USB trigger from the scanner (e.g. '5' or '=') ?

    I can't seem to find any solution for this in the forum.

    Thanks,

    Melanie

  • Hi Melanie,

    I am not sure I fully get your goal here.

    How can I ensure that after the initial keypress to start the experiment, that the timings are absolute?

    Absolute relative to what?

    but when I use a stop watch the whole trial is 50s, more than double what I was expecting it to be

    The reason for that is that you poll the response twice. Once in the inline_script itself (kb.get_key()) and once with the keyboard_response item. You don't need the second if you have it in the inline_script. For this reason you currently should have to press twice to continue each scale I think.


    Do I need another inline script after my "Get Ready" sketchpad message, to tell the program to wait for a USB trigger from the scanner (e.g. '5' or '=')

    If you know that the trigger that the scanner sends is either a 5 or a =, you can simply change the duration of your sketchpad to 0 and add a keyboard response after it that has as allowed keys only 5 or = (separated by a semicolon). Does this make sense?

    . Timing is very critical for my fMRI study

    If timing is important you have to be really careful that you won't make Opensesame unresponsive for a while, for example, by having clock.sleep commands, or similar. The approach with the while loop that is used in define should be the way to go. But irrespective of all that, there is only one way to know for sure. Testing, testing and testing :) Without running pilots to make sure your procedure works as expected, you almost certainly will find something later that could have been done somewhat better.


    Good luck,

    Eduard

    Buy Me A Coffee

  • That all makes sense. Thanks very much Eduard!!


    Melanie

Sign In or Register to comment.

agen judi bola , sportbook, casino, togel, number game, singapore, tangkas, basket, slot, poker, dominoqq, agen bola. Semua permainan bisa dimainkan hanya dengan 1 ID. minimal deposit 50.000 ,- bonus cashback hingga 10% , diskon togel hingga 66% bisa bermain di android dan IOS kapanpun dan dimana pun. poker , bandarq , aduq, domino qq , dominobet. Semua permainan bisa dimainkan hanya dengan 1 ID. minimal deposit 10.000 ,- bonus turnover 0.5% dan bonus referral 20%. Bonus - bonus yang dihadirkan bisa terbilang cukup tinggi dan memuaskan, anda hanya perlu memasang pada situs yang memberikan bursa pasaran terbaik yaitu http://45.77.173.118/ Bola168. Situs penyedia segala jenis permainan poker online kini semakin banyak ditemukan di Internet, salah satunya TahunQQ merupakan situs Agen Judi Domino66 Dan BandarQ Terpercaya yang mampu memberikan banyak provit bagi bettornya. Permainan Yang Di Sediakan Dewi365 Juga sangat banyak Dan menarik dan Peluang untuk memenangkan Taruhan Judi online ini juga sangat mudah . Mainkan Segera Taruhan Sportbook anda bersama Agen Judi Bola Bersama Dewi365 Kemenangan Anda Berapa pun akan Terbayarkan. Tersedia 9 macam permainan seru yang bisa kamu mainkan hanya di dalam 1 ID saja. Permainan seru yang tersedia seperti Poker, Domino QQ Dan juga BandarQ Online. Semuanya tersedia lengkap hanya di ABGQQ. Situs ABGQQ sangat mudah dimenangkan, kamu juga akan mendapatkan mega bonus dan setiap pemain berhak mendapatkan cashback mingguan. ABGQQ juga telah diakui sebagai Bandar Domino Online yang menjamin sistem FAIR PLAY disetiap permainan yang bisa dimainkan dengan deposit minimal hanya Rp.25.000. DEWI365 adalah Bandar Judi Bola Terpercaya & resmi dan terpercaya di indonesia. Situs judi bola ini menyediakan fasilitas bagi anda untuk dapat bermain memainkan permainan judi bola. Didalam situs ini memiliki berbagai permainan taruhan bola terlengkap seperti Sbobet, yang membuat DEWI365 menjadi situs judi bola terbaik dan terpercaya di Indonesia. Tentunya sebagai situs yang bertugas sebagai Bandar Poker Online pastinya akan berusaha untuk menjaga semua informasi dan keamanan yang terdapat di POKERQQ13. Kotakqq adalah situs Judi Poker Online Terpercayayang menyediakan 9 jenis permainan sakong online, dominoqq, domino99, bandarq, bandar ceme, aduq, poker online, bandar poker, balak66, perang baccarat, dan capsa susun. Dengan minimal deposit withdraw 15.000 Anda sudah bisa memainkan semua permaina pkv games di situs kami. Jackpot besar,Win rate tinggi, Fair play, PKV Games