Howdy, Stranger!

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

Supported by

Help for if conditions

Hello, everyone.

I need some help with my thesis experiment. I am a beginner here only watched available tutorials.

I could not write 'run if' conditions on my own.

I need to know the scripts on 'run if' conditions like if this picture is shown, ask this question, etc. I really do not know how to link question_sequence and picture_sequence in 'run if' conditions.

I need to write 2 different 'run if's.

First, 'run if' condition for-if this picture is shown, don't show the other two pictures.

Second, 'run if' condition for-if this picture is shown, ask this question.


Is there anyone who knows anything in general how to write run if conditions based different sequences and even among sequences?

Comments

  • Hi @Nomu,

    Welcome to the forum!

    The answer to your question really depends on your design and its complexity.

    The "Run if" property of objects in a sequence determines under what condition a given object is run. It0s handy for fairly simple decision trees, but if you have many different questions that must appear for many different pictures, you should use another approach. The simplest one is actually not to use the "Run if" property in a loop, but to define both the picture and the questions as variable in that loop. That way, you can control exactly what picture and questions come up. I think you could achieve what you want using that method, but you'd need to give a clearer description of your design to be sure.

    You could possibly also use "Run if" but then you should then program some code to set a variable that will take a certain values under the specific conditions that you want met, and then set the "Run if" property accordingly. So, for example, imagine that you set a variable called show_this to a value "yes" when a series of conditions are met, you'd then insert [show_this]="yes" in the Run if property of the object you want to show.

    Hope this helps. You may want to explore previous posts in the forum and take some time to go through some tasks published there (it's often a good way to learn). Here's just one example where "Run if" and some coding is used to run one loop rather than another: https://forum.cogsci.nl/discussion/7620/pseudorandomization-of-tasks-within-an-experiment)

    Fabrice.

    Buy Me A Coffee

  • Hello, Fabrice.


    Thank you for replying.

    Can I ask you how I can define the pictures and questions as variables in one loop? I am sorry if I am asking too simple things.

    My experiment would be like this:

    1. a participant will be shown a randomly chosen picture from total 3 pictures for 2 seconds (there are no other tasks to do with the pictures, a person should just simply see the pic)
    2. and then a participant will be asked multiple-choice questions based on the previous randomly chosen picture (questions will not be asked right after the pic, some information will be shown and then the question will be asked).

    I tried to do make them variables on my own but I think I quite lack basic knowledge and don't know what to do. I never learned Python and any other programming languages, and for that, I don't want my experiment to be so complex. Could you please tell me how to arrange these orders on OpenSesame without anything difficult?

    Sorry again for wasting your time and thank you so much for your time and effort!

  • Hi Nomu,

    in the loop you find a table. The first line is the variable name.

    Possibly you need two variables.

    Call one 'Stimulus' and fill the 3 rows below with the names of your pictures e.g. 'pic1.JPG', 'pic2.JPG', pic3.JPG'.

    Call the second variable 'Question' and fill it with whatever you need for the questions for the picture of this row in case that the questions are specific for each picture.

    Within the loop you may have a sequence that includes a sketchpad where you present a picture. Set instead of 'pic1.JPG' --> [Stimulus], so it takes the row of each picture in the loop.

    Hope I could help you out

    Stephan

  • Hello, Stephan.


    Thank you for your comment! I think I quite got what you said:)

    I set them as variables and now I have a new problem. I did as you told me but the picture_sequence is running 3 times and also it shows all the pictures. What I would like to do is only one random pic shown from 3. I attached the screenshot, please check if I did something wrong.

    Secondly, i feel like I miss something with displaying questions. I cannot display questions as I wanted to be. I mean I do not understand how to combine two sequences. One is picture_sequence while the other is question_sequence. Could you check the script that I have tried to do on my own below?

    Thank you so much for your help and your time!



  • Hi @Nomu,

    I only just saw your message (when replying to messages in the forum, it is best to use handles so that your correspondent gets notified). Just type "@" and the first letters of your correspondent's nickname and you'll see a pulldown menu. Example:

    I'd need a little bit more information about your design to give you more precise advice. Is it that case that you want each participant to see only one picture picked at random among three? Are the questions the same for all picture or do you want to present different questions for the different pictures? What kind of response are you recording from each question? A single key press, or several, or a word or even a sentence? If you can provide a little more information, I should be able to recommend one method or another.

    Regarding your loop with the pictures, if you want only one row to be selected from the three at random, set the repeat property to "each cycle 0.33 times". That will result in showing only a third of the list of trials, i.e., in this case, a single trial (single picture).

    Best,

    Fabrice.

    Buy Me A Coffee

  • Hello, @Fab!

    Thanks for your little guide here :).

    For the experiment:

    Firstly, yes each participant will see only one random picture, which is randomly chosen by the program from a total of 3 pics.

    Secondly, the questions are not different, but there are some questions which are not needed to be shown for a certain pic, in that sense the questions are different? I mean I will ask only 3 questions which all are multiple-choice questions and for 2 pics, one of the 3 questions should not be asked.

    Thirdly, a single keypress for the MCQs. Only one answer is allowed.

    One thing to add here is that between pic and questions, I need to present texts which are about information. Will it be a problem here to link pics and questions?

    Also, I have tried to make it 0.33x, but it said 'picture_sequence will never be called', so I changed it to 0.50x which it said it will be called once in random order. But it did not, which worries me why.


    Thank you so much for your time and effort! will definitely buy you a coffee☕️.

  • Hello, @Fab!

    Thanks for your little guide here :).

    For the experiment:

    Firstly, yes each participant will see only one random picture, which is randomly chosen by the program from a total of 3 pics.

    Secondly, the questions are not different, but there are some questions which are not needed to be shown for a certain pic, in that sense the questions are different? I mean I will ask only 3 questions which all are multiple-choice questions and for 2 pics, one of the 3 questions should not be asked.

    Thirdly, a single keypress for the MCQs. Only one answer is allowed.

    One thing to add here is that between pic and questions, I need to present texts which are about information. Will it be a problem here to link pics and questions?

    Also, I have tried to make it 0.33x, but it said 'picture_sequence will never be called', so I changed it to 0.50x which it said it will be called once in random order. But it did not, which worries me why.


    Thank you so much for your time and effort! will definitely buy you a coffee☕️.

  • FabFab
    edited March 2022

    Hi @Nomu,

    Thanks for the additional information. I've been very busy this last week and couldn't have a look at your task earlier.

    Based on what you described, here is what I suggest:

    Use code to pick a value between 1 and 3 at random. Use that value to indicate to the program which picture to display. Then use 3 loops, one to contain the questions for each picture, and use the same sequence (linked copy) inside each of these loops. In that sequence, use a sketchpad to display the question and multiple choice answers, and set its duration to 0 ms. Then insert a keyboard object to take the response (keys 1-3).

    This is how to implement it:

    First, let's use some code to pick a value at random between 1 and 3. Here, I do it in Javascript using thea inline_javascript object (you could of course achieve the same result in Python if you preferred to, though you'd then have to use an inline_script object instead). Here is the code that must be placed in the "prepare" section of the object (not the "Run" section; this is because we need to program to have executed that code before it runs the experiment sequence; you'll see why later):

    vars.picked=(Math.floor((Math.random() * 3) + 1))
    

    This Javascript line picked an integer value between 1 and 3 and saves it in a variable I called "picked".

    Second, we'll display the picture. Here, we simply need a sketchpad. I set its duration to 1000 ms (you can use whatever value you'd like, of course).

    We'll insert a picture on the sketcphad. You can do that by clicking on the picture tool. It'll ask you to select a picture from the stimuli pool (if your pictures are not in the pool yet, add them). We then want to edit the script of the sketchpad so that we can chose the picture dynamically depending on the content of the picked variable:

    Notice that the names of the pictures must correspond to the content of the script. My pictures in the pool are called picture1.jpg, picture2.jpg and picturr2.jpg, hence I set the script to call: "picture[picked].jpg". This will mean that if picked is equal to 1, picture1.jpg will be shown. If picked is equal to 2, then picture2.jpg will be shown. Etc. Going back to the Javascript code, the reason it has to feature in the "Prepare" section of the inline object is because Open Sesame prepares sketchpads before the sequence is executed. So, the program would look for a picture called "picture[picked].jpg" before the Javascript code creating that variable could be executed. It would generate an error.

    Next, we create three loops, one to be displayed if picked is equal to 1, another if it is equal to 2 and yet another is picked is equal to 3. You can see above that I set up the "Run if" property of the experiment sequence.

    Inside each of the loop, we define the questions and the possible answers. You can list as many questions as you want for each.

    For example, I set the first loop like this:

    I set up three questions, three possible responses, and I set the order of presentation to "sequential" so that the questions will be displayed sequentially (set it ro random if you want a random presentation).

    Within each loop, we're gonna run a sequence to display the questions and answers, and take a keyboard response. Because the structure of each trial is the same regardless of the loop, we can use the same sequence (I called it questions_sequence) for the three loops (that way, if you want to modify the sequence, you only need to do it once and the changes will be applied to all three loops). To do this, I created the sequence and then selected "Copy (linked)" before pasting it elsewhere:


    On the show_question sketchpad, we're gonna use the variables from the loop (Question, OptionA, OptionB, OptionC) to have the questions and answers displayed. the sketchpad has a duration of 0 ms, such that it'll be displayed and Open Sesame will move on to the next object right away. the next object is a keyboard object set to take a response that can be 1, 2 or 3:

    That way, there is no risk that the task will accept another response if the subject accidentally press another key.

    Note that the duration of the keyboard object is set to "infinite", so that the task will wait until a response is taken. Once it is done, it'll move to the next question until all questions from the current loop have been presented.

    After the keyboard object, we have the logger that registers the response. Because the logger is set to log all variables by default, it will also log the picked variable, so that you'll see it in your output for every trial.

    That's it!

    There are alternative ways to do what you're after but this one is simple and yet flexible (it allows you to set the questions and answers to whatever you want, independently for each possible picture.

    I did not insert some text or pause between the presentation of the picture and the questions but you can of course easily do so by simply inserting whatever you need after the show_picture sketchpad.

    You can down my working example here: https://www.dropbox.com/s/244h0zawzhstdpe/Pictues%20and%20questions.osexp?dl=0 (for some reason the forum platform does not let me upload the task directly to this post).

    I hope this is helpful. I trust that with this you should be able to complete your experiment. Before you ruin anything, always make sure to check your data output to make sure everything you'll need for the data analysis is there!

    Good luck!

    Fabrice.

    Buy Me A Coffee

  • Hi @Fab and @Nomu


    I have been reading your thread in the hope of finding an answer to my own problem and tried some things out, but I'm still running into issues.

    I have a task in which participants give 2 responses. For 1 response, they use the left or right arrow; for the second response they use the keys f, g, h, j.

    I want to give feedback on their combined response. Their first response (with the arrows) can be correct or incorrect. Their second response (with the lettres) can be Correct, DoubtCorrect, DoubtIncorrect and Incorrect.

    The combined response can thus be

    • Correct-Correct
    • Correct-DoubtCorrect
    • Correct-DoubtIncorrect
    • Correct-Incorrect
    • Incorrect-Correct
    • Incorrect-DoubtCorrect
    • Incorrect-DoubtIncorrect
    • Incorrect-Incorrect

    I wrote an inline script to make a variable that is 0 when the first answer is incorrect and a 1 when it is correct:


    print(var.response_Keyboard_Answer)
    print(var.CorrectAlternative_Side)
    
    Accuracy_Answer = 0
    
    if var.response_Keyboard_Answer == var.CorrectAlternative_Side:
    Accuracy_Answer = 1
    
    print(Accuracy_Answer)
    self.experiment.set("Accuracy_Answer", Accuracy_Answer)
    


    That script seems to work, because the variable "Accuracy_Answer" is saved. Participants see nothing during this short script. After that script, participants provide their answer to the second question. After that question, I wrote a new script, but this does not work.


    print(var.response_Keyboard_MC)
    
    print(var.Accuracy_Answer)
    
    
    
    if Accuracy_Answer == 1:
    
    while True:
    
    if var.response_Keyboard_MC == "f":
    
    Feedback = 2
    
    else:
    
    if var.response_Keyboard_MC == "g":
    
    Feedback = 4
    
    else:
    
    if var.response_Keyboard_MC == "h":
    
    Feedback = 6
    
    else:
    
    if var.response_Keyboard_MC == "j":
    
    Feedback = 8
    
    
    
    
    if Accuracy_Answer == 0:
    
    while True:
    
    if var.response_Keyboard_MC == "f":
    
    Feedback = 3
    
    else:
    
    if var.response_Keyboard_MC == "g":
    
    Feedback = 5
    
    else:
    
    if var.response_Keyboard_MC == "h":
    
    Feedback = 7
    
    else:
    
    if var.response_Keyboard_MC == "j":
    
    Feedback = 9
    
    print(Feedback)
    
    self.experiment.set("Feedback", Feedback)
    
    print(var.Feedback)
    
    


    First, the numbers 2-9 for "Feedback" were the names of the categories (e.g. Correct-Correct). I thought maybe this was the issue, but still no luck now.

    I want to create an if statement for presentation of the next stimulus based on the value of the Feedback variable. So I want to have Run if [Feedback = 9] in my trialsequence for example.


    Can you help me with this? THANKS SO MUCH!

    Elien

  • Hi Elien,

    I am not sure what is happening in your code (the formatting is not Pythonic, no indents), but here an approach that should work.

    First, you can define a mapping of responses to the feedback variable (once in the beginning of the experiment should be enough)

    labeling = dict()
    labeling[1] = dict(f=2, g=4, h=6, j=8)
    labeling[0] = dict(f=3, g=5, h=7, j=9)
    

    Then, after every response has been given, you can set the feeback variable, like this:

    # provided that your two questions are stored in these variables
    var.feedback = labeling[Accuracy_Answer][var.response_Keyboard_MC]
    

    Then the variable [feedback] should be usable as a run if statement. Does it work? If not, I suppose something else is wrong with your experiment. Then it would be nice if you could share your experiment.

    Hope it helps,

    Eduard

    ps. i havent followed the earlier discussion at all, so in case what I say does not make sense in the context of the earlier bits, sorry!

    Buy Me A Coffee

  • Hi @Fab!

    Thank you so much for your help and effort! I have been busy with my studies last week and could not reply to your message above. I have done exactly as you said and it worked!!! I am so thrilled to finish it. Thanks again!

    The thing is that I have just met my thesis supervisor today and he suggested that we should change the 'random' ordering to 'in order' ordering. For example, if the 1st person has seen picture1, the 2nd would see picture2, and the 3rd person would see picture3. Because the randomness can create imbalanced data, he said. I did not think of it until today and felt so sorry for wasting your time on this for this whole time.

    If it is possible, could you please change the javascript line in this matter?

    Thank you so much for your valuable time!

    Nomu

  • Hi @eduard


    Thank you very much for your response! This seems to be a good first step. The first item of the loop runs smoothly (The correct feedback is presented). However, for all next items, the same feedback condition is presented, no matter what the responses were. So for example, If on the first item, feedback 2 was presented, for all other items, feedback 2 will be presented.

    I guess I need to figure out a way to set the feedback variable back to 'empty' before the next trial starts? I have no idea how to do that...


    Thanks for your help!!!

    Elien

  • Hi @Nomu,

    There is no automatic way of achieving what you're after, but one easy trick is to use the subject number to allocate them to a condition. What you want to do is use a modulus operator - or more precisely, the modulo operation. It is a way to determine the remainder of a division operation. Instead of returning the result of the division, the modulo operation returns the whole number remainder. In Javascript, the modulus operator of a number A divided by a number B is noted : A%B.

    So, 1%3 = 1 (because 1/3 = 0, so there remains 1)

    2%3 = 2 (because 2/3 = 0, so there remains 2)

    3%3 = 0 (because 3/3 = 1, and there is no remainder).

    If you apply this method to all digits, you get values following a 1,2, 0 cycle:

    You can use this to your advantage here by replacing modifying the Javascript code in the pick_picture inline_javascript object:

    // Random selection of digit between 1 and 3
    // vars.picked=(Math.floor((Math.random() * 3) + 1))
    
    // counterbalancing across subjects based on subject number
    // Using MOD method
    if (vars.subject_nr%3==1){
    vars.picked=1
    } else if (vars.subject_nr%3==2) {
    vars.picked=2
    } else {
    vars.picked=3
    }
    
    console.log ("Subject number: "+vars.subject_nr)
    console.log ("Value picked: "+vars.picked)
    

    I kept the old code by neutralized it using "//" in case you have some use for it at a later date.

    Next, you can see that I'm using an if...else if... else statement to test the subject number (vars.subject_nr is a system variable containing the number you introduce when you start the experiment):

    For subjects 1, 4, 7, 10, 13, etc., vars.picked takes the value 1.

    For subjects 2, 5, 8, 11, 14, etc., vars.picked takes the value 2.

    For subjects 2, 6, 9, 12, 15, etc., vars.picked takes the value 5.

    That solves your problem as long as you make sure to number your subjects consistently. If you do, and test a number of subjects that is a multiple of 3, you'll have equivalent numbers of subjects in your three conditions.

    You can download the modified example here: https://www.dropbox.com/s/2fljeqn2a1lekdq/Pictures%20and%20questions%202.osexp?dl=0

    Hope this helps!

    Fabrice.

    Buy Me A Coffee

  • Hi @elienbellon,

    Joining this halfway through and without having taken a close look at your code, but your description makes me think that you're not redefining the feedback variable within the loop's sequence following each response. Can't say much without seeing the task itself. It is it built efficiently, there should be no need to redefine it in several places; once in the right place within the loop's sequence should work.

    Best,

    Fabrice.

    Buy Me A Coffee

  • Hi @Fab,

    Thank you for your time and response!

    One more question: How about if we do the experiment online? Then we cannot set the subject number, right? Would it need a different script line or trick?


    Thank you again for your time! I hope you're having a wonderful week.:)

    Nomu

  • Hi @Nomu,

    There is no automatic way to do it on OSWeb but there are some workarounds.

    The easiest is to set the possible subject numbers to 1,2,3 in the settings of OSWeb. However, this does not guarantee that you'll have equal numbers of participants in all three conditions. OSWeb will pick a subject number between these every time the task runs. It should not end up with widely discrepant numbers of subjects 1, 2 and 3, but it won't equate the numbers.

    Another way would be send different links to three groups of participants. You could either create three versions of the task, setting the subject number through code in each one. Alternatively, you could embed the subject number in the URL string and include code in your task to read it (see https://forum.cogsci.nl/discussion/7663/read-query-string-values-in-osweb for some pointers about query strings). This latter solution requires a little more experience; if you're new to all this, I'd recommend one of the earlier solutions.

    Finally, make sure to consult the OSWeb documentation to make sure your task does not contain objects or properties that are not supported (not all features of OS are compatible with OSWeb). You'll also need to see the logger manually.

    Hope this helps.

    Fabrice.

    Buy Me A Coffee

  • Hi, @Fab,

    Thanks so much for your help over the past 4 to 5 weeks! It works very well!!!

    Finally met my supervisor, and now I am ready to launch the experiment to the public!

    I could not have done anything without your effort and help.

    Thank you so much again and wish you the best.


    Kindly,

    Nomu

  • Hi @Nomu,

    Glad your experiment is now ready to go and that my help was useful.

    Good luck with your experiment!

    Fabrice.

    Buy Me A Coffee

  • Hi @eduard and @Fab

    Thank you both very much for the help! It works :-)

    Best

    elien

  • @elienbellon

    Hi Elien,

    Great! Glad that you got it to work.

    Good luck with your experiment!

    Fabrice.

    Buy Me A Coffee

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