Howdy, Stranger!

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

Supported by

[solved] Putting "if-clauses" in the Key-response

edited November 2011 in OpenSesame
Hey,


In the experiment i designed there is no fixed correct response. Is there any possability to put a "if-clause" like in python in Open Sesame, so he logs "yes" IF the response was "districtor1" (so a number between 1 and 4). At the moment it logs the response and i can manually check if the response was correct, but if i test around 50 people it would be nice if Open Sesame would be able to just log if the response was correct.

So there are 4 pictures in random order shown and i want to log the correct response which is one of the pictures.

Comments

  • edited 11:32AM

    The easiest way to achieve this is probably to add an inline_script item (somewhere after the keyboard_response and before the logger) with something like the following code in the run phase:

    if self.get("response") in ["1", "2", "3", "4"]:
    self.experiment.set("my_response", "distractor")
    else:
    self.experiment.set("my_response", "target")

    This will create a new variable "my_response" which is set to "distractor" if the response was "1" through "4" and set to "target" otherwise.

    Hope this helps!

  • edited 11:32AM

    Hey,

    I have changed the picture_selecting so that "dist1" is the correct response. "dist1" gets shuffeled with "dist2-4" so the correct response is a number btw. 1 and 4 but the variable "dist1".

    Is there a possability to set
    correct == 0
    if "dist1" set correct = 1 ?

    Best regards and thanks again for your support

    Henrik

    P.S.: I found a bug, if you enter an "illegal" command and Run the script after you get a bugreport. If you close Open Sesame than, without removing the bug, the script can´t be opened again, because it tries to immidiatly run the script which isn´t possible. In that case you ain´t able to open the script to edit it.

  • edited 11:32AM

    I'm afraid I don't quite follow, particularly this bit:

    so the correct response is a number btw. 1 and 4 but the variable "dist1".

    Could you perhaps describe in a bit more detail what you have done and what you want to achieve?

    P.S.: I found a bug, if you enter an "illegal" command and Run the script after you get a bugreport. If you close Open Sesame than, without removing the bug, the script can´t be opened again, because it tries to immidiatly run the script which isn´t possible. In that case you ain´t able to open the script to edit it.

    Thank you! That's a serious bug indeed. It would be very helpful if you could describe the exact steps that will reproduce the problem (either here or on the issue tracker).

    Btw, perhaps it's good to know that you can open the .opensesame.tar.gz files with a program like WinRar. So even if OpenSesame fails to open the files (which it shouldn't, of course), you can still edit the experiment.

  • edited 11:32AM

    Hey,

    to part2 yes i found that out quite soon, so it wasn´t such a loss.
    The exact problem was that i entered a line in a sketchpad ,and saved it, that couldn´t be executed. After i got the bugreport i closed OpenSesame. As i tried to open the Script, OpenSesame immidiatly tried to run the Script, which wasn´t possible. It gave me the bugreport but didn´t open the script, so i couldn´t remove the false line.

    To my problem discription:

    The programm now shuffles 100 numbers, each number has 5 pictures.
    Than draws 40 of them and displays them in the 2 different phases, the pictures names are for example 41a, 41b, 41c, 41d, 41e. In the display phases Picture 41a and Picture 41b get displayed.
    In the recall phase picture 41a gets displayed on top off the other 4.
    Picture 41b gets shuffeled into the 3 distractors (41c, 41d, 41e). I defined the "correct" picture as "dist1". But since they get shuffeled it is allways a different number.
    I hope i managed it to explain it now, my english isn´t perfect ;(.

    Best regards

    Henrik

  • edited 11:32AM

    Ah, I think I understand now. There is a variable "dist1", which has a value between 1 and 4, depending on where the target picture was presented. So "response" has to match "dist1". Is that correct?

    There are two ways to do this:

    1) The easiest way is probably to enter [dist1] in the correct response field of the keyboard response.

    2) A more flexible way is using an inline scipt. Something like this should do the trick:

    if self.get("dist1") == self.get("response"):
    self.experiment.set("correct", 1)
    else:
    self.experiment.set("correct", 0)

    The exact problem was that i entered a line in a sketchpad ,and saved it, that couldn´t be executed. After i got the bugreport i closed OpenSesame. As i tried to open the Script, OpenSesame immidiatly tried to run the Script, which wasn´t possible. It gave me the bugreport but didn´t open the script, so i couldn´t remove the false line.

    Could you perhaps be even more specific? In order to address the issue I really need a step-by-step description of what you did and what happened as a result, including the exact error messages and the line of script that causes the problem. Thanks!

  • edited 11:32AM

    Okay,

    exact discription is: (Only tried it with Sketchpads so far but should happen on all in-line scripts).

    "Error: Script error
    Description: Failed to instantiate module 'sketchpad' as 'zweiterTeil': Error: Script error
    Description: Unknown command ' # cookies'"

    If you enter in a sketchpad # (text) and try to run it you will get that bug. If you saved before you run it and close the programm while the "bug-window" is open, OS will try to run the script and instead of opening your script will give you this bugdiscription:

    "Error: Failed to open 'C:/Users/Henrik Ho/Desktop/Uni/Praktika/erstes Praktikum Pulsschlag-Zeit bei Leistung/es-geht!.opensesame.tar.gz'
    Description: Error: Script error
    Description: Failed to instantiate module 'sketchpad' as 'zweiterTeil': Error: Script error
    Description: Unknown command ' # cookies'

    Make sure that the file is in .opensesame or .opensesame.tar.gz format. If you should be able to open this file, but can't, please go to http://www.cogsci.nl/opensesame to find out how to recover your experiment and file a bug report."

    Without opening the script.

    Okay and for the "if-clause" i think i havn´t defined the variable correctly.

    target = num + "a.bmp"

    dist1 = num + "b.bmp"
    dist2 = num + "c.bmp"
    dist3 = num + "d.bmp"
    dist4 = num + "e.bmp"

    That is how i have defined it. Picture with "b" is allways correct. But if i enter your suggested textline or keyboard response i get a bug, saying:

    "Error: Inline script error
    In: inline_script (prepare phase)
    File "libopensesame\item.pyo", line 302, in get

    Python traceback:
    runtime_error: Error: Runtime error
    Description: Variable 'dist1' is not set in item 'inline_script'."

    You are trying to use a variable that does not exist. Make sure that you have spelled and capitalized the variable name correctly. You may wish to use the variable inspector (Control + I) to find the intended variable.

    Full traceback in debug window"

    Best regards

    Henrik

    Once more thanks for your really good support!

  • edited 11:32AM

    It's important to know that not all Python variables are automatically recognized by OpenSesame with the "[variable]" notation. Specifically, OpenSesame only recognizes variables that are properties of the experiment object. In practice, this means that you should use the get() and set() functions to manipulate variables that you want to use elsewhere in OpenSesame.

    dist1 = num + "b.bmp" # won't work
    self.experiment.set("dist1", num + "b.bmp") # will work
    print dist1 # won't work
    print self.get("dist1") # will work

    You can find more about this here.

    Good luck and thanks for the bug-description!

  • edited 11:32AM

    Hey,

    Sorry forgot to say it, works now thank you very much!

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