Howdy, Stranger!

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

Supported by

Replacing one variable list with the values of another variable list using inline script

Hello,

I have prepared an experiment in Open Sesame in which participant's self-relevant information (e.g., name, surname, city, month of birth) is paired with a particular image stimuli (e.g., happy face) and as control I have used other-information (other names, surnames, cities and months) that are paired with different image stimuli (e.g., happy, neutral and sad faces). The words (self-relevant/other-information) are presented at random in different quadrants on the screen and after the participant clicks on those words, a face image appears on the same quadrant (happy face for self-relevant information/ sad, neutral or happy face for other-information). All of these trials belongs to the same block, and I have in total 240 trials.

I have the following inquiry though. Since sometimes participant's personal information might coincide with the control words (e.g., if input variable is Dave and I have Dave as a control word), I would like to use another variable list with different control words (e.g., Oscar) as cavnas text. So, for that purpose, I have created another variable (called alterantive_word_stimuli ) with the input variables (the responses given by the participants) and other control words. I have also created two other variables, one (called Responses) only with the input variables (responses given by participants) and another variable (called words_var ) only with the control words (the ones used originally). With this variables in mind I added an inline script in the beginning of the sequence (before fixation dot, word presentation, touch response and image presentation). I am not an expert in Python, but I have tried many if functions and none of them worked (Open Sesame did not send any error message, it just keep showing the original text variable (called word_stimuli). I have tried codes such as: if var.words_var == var.Responses: var.word_stimuli = var.alternative_word_stimuli.

I am attaching images of the inline script, and of the structure of the block with their respective variables.

I would highly appreciate if someone in this forum could provide me with some insight on how to proceed with this problem.


Thanks in advance.

Best, Anton

https://forum.cogsci.nl/uploads/320/0QIM51HCVJ41.jpg

https://forum.cogsci.nl/uploads/031/JIF6NCC7LZ04.jpg

https://forum.cogsci.nl/uploads/785/KG8JIS2Q0OOU.jpg - clear

Comments

  • Hi Anton,

    If I understand correctly, you want to check the loop table for whether any of the values under Responses matches any of the values under words_var . And if so, you want to use values from alternative_word_stimuli instead of word_stimuli (by assigning the former to the latter). Is that correct?

    If so, then it's important to first realize that you shouldn't check individual values, which is what you're doing now. This …

    if var.Responses == var.words_var:
    

    … checks whether on that particular trial, Responses and words_var are the same value. But it doesn't consider the columns as a whole. And this …

    if any(var.Responses) == any(var.words_var):
    

    … checks whether any of the characters in Responses are True , which will be the case for anything other than an empty string, and then does the same for words_var , and finally compares if both either are or are not empty strings . Also very different from what you want to do!

    Below I added a function (any_match() ) that checks what I believe you want to check, namely whether any values under two columns match, also taking into account variable references:

    def eval_col(col, loop_item):
        
        """Gives a list of all values from col, which should be a column
        from loop_item, and evaluates the variable references in all those
        values.
        """
    
        return [exp.syntax.eval_text(val) for val in items[loop_item].dm[col]]
    
    
    def any_match(col1, col2, loop_item):
        
        """Checks whether any value from col1 matches any value from col2,
        which should both be columns from loop_item.
        """
        
        for val1 in eval_col(col1, loop_item):
            for val2 in eval_col(col2, loop_item):
                if val1 == val2:
                    return True
        return False
    

    I'll leave it as an exercise to figure out how to actually use any_match() in your code!

    Cheers!

    Sebastiaan

  • Hi Sebastiaan,

    Thank you very much for your help! It's highly appreciated.

    Indeed what I want to do is what you have addressed in the beggining of your response (check the loop table for whether any of the values under Responses matches any of the values under words_var . And if so, you want to use values from alternative_word_stimuli instead of word_stimuli (by assigning the former to the latter)).

    I have tried run and exercise with the code you have provided me. But I am still getting the same word stimuli (word_stimuli) instead of the stimuli I want to use (alternative_word_stimuli).

    My knowledge regarding python is quite limited. Thus I am assuming that I am doing something wrong with the code you have provided me.

    I am attaching the code to see if you can help me again with this.

    Thanks in advance.

    Cheers!

    Anton

  • Hi Anton,

    I wasn't very clear about that, but the arguments to any_match() should be strings, like so:

    if any_match('Response', 'words_var_Block_1_Exp_St'):

    Cheers!

    Sebastiaan

  • Hi Sebastiaan!

    Thank you very much for your help!!

    The any_match() function is working so far! I've tested this by adding an if function and ask to print me TRUE or FALSE if the condition is satisfied ( I can see it on the debug window) .

    However, I am still having troubles regarding the second part of my question (replacing one variable - word_stimuli - with another variable -alternative_word_stimuli -) .


    I have tried with many code lines, such as:

    if any_match('words_var','Responses','Block_1_Exp_ST'):

                   my_canvas.text(text= "alternative_word_stimuli")

    else:

                   my_canvas.text(text= "word_stimuli")

    Or:

    if any_match('words_var','Responses','Block_1_Exp_ST'):

                   var.word_stimuli[0:47] = var.alternative_word_stimuli[0:47]

    else:

                   var.word_stimuli[0:47] = var.word_stimuli[0:47]

    Or:

    if any_match('words_var','Responses','Block_1_Exp_ST'):

                   var.word_stimuli[0:47] = var.alternative_word_stimuli[0:47]

    else:

                   var.word_stimuli = var.word_stimuli


    But none of these codes seem to work ( I enter information that satisfies the any_match function, and the program still shows me the items from word_stimuli). As I have stated earlier, I am not a python expert nor a programmer expert. So there must be something I am doing wrong.


    I would highly appreciate if you can help me again with this.

    Thanks in advance!

    Best,

    Anton

  • Hi Anton,

    The reason that nothing has an effect is probably that you're doing it in the Run phase of the script, whereas most items (including sketchpad s) are prepared during the Prepare phase.

    So the first thing to do is move the code to the Prepare phase. Then, this should (I think) do the trick:

    if any_match('Response', 'words_var_Block_1_Exp_St'):
        var.word_stimuli = var.alternative_word_stimuli
    

    That being said, looking at all the things that you've tried, it seems that you're randomly trying things without understanding what they mean! That's frustrating, and also unlikely to result in success. So I would say: Why not familiarize yourself with at least the basics of Python? This will take a bit of time, but you will easily win this back in the medium-to-long term.

    Cheers!

    Sebastiaan

  • Hi Sebastiaan!


    Thank you so much for your help! Everything is working great now!!

    I will follow your advice and keep learning about python.

    Cheers!


    Anton

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