Passing variables to search array
Hello!
I am helping a friend and am looking for a way to pass a GUI experimental value into an inline script and then search an array for that variable in order to access associated sound files. I am not sure I am passing the variable correctly, but I also am not sure if the index feature works in OpenSesame?
My array stimlist would contain target_word1, word1sound1, word1sound2, word1sound3, word2, word2sound1, word2sound2,word2sound3 etc. My goal would be to have the GUI loop randomly select the target_word, and then I use the inline script to randomly select one of the 3 sound files to play while the target_word is displayed using the sketchpad. I thought to use the index feature of python to identify what place in the array target_word can be found, then generate a random number 1-3 to add to the place in the array to call the sound file. Of course, if someone has a more elegant way to achieve this, I am also all ears. I am not super familiar with Python and it's been 10 years since I was actively programming (in Java and Perl).

Comments
Not sure whether I perfectly understand what you want to accomplish, but if it to generate a path to a sound file based on a randomly generated target word, I highly recommend using intuitive file names. For example, if the target word variables are called
target_word_X, you can name all the sound filestarget_word_X_sound, so that you can simply retrieve the target word, add the sound part and load the sound.Does that make sense?
Eduard
I need to generate a path to a sound file, but it is ALSO a randomly selected sound file.
So if my Primary list is
Sun
Moon
Star
I need to randomly select one of those 3 words in the Sound list. THEN each word has 3 sound files associated with it
Sun (Big, ball, yellow)
Moon (Circle, white, small)
Star (dark, shine, tiny)
The program needs to run through ALL of the primary list, but only ONE of each of the Sound files are played.
So one participant will be presented with
Sun - Big
Star - Dark
Moon - Circle
And another might be presented with
Star - Tiny
Moon - White
Sun - Ball
So every primary needs to be listed, but only 1 randomly selected sound.
So, what I thought was to have a stimuli list stored as an array such as
Sun
Big.wav
Ball.wav
yellow.wav
Moon
circle.wav
white.wav
small.wav
Star
dark.wav
shine.wav
tiny.wave
And then if the program selects "Moon" I search the list for "Moon" using the index which would return an integer 4 (since Moon is in position 4). Then, I random 1-3 to get which of the 3 sound files to pull. I could then add Moon's position (4) to the random option (2) and get 6 - so I will then access List[6] and it will pull the sound file name white.wav which I then load into Sampler to play the sound while the target (moon) is displayed.
Actually, I could probably do that.
But I still can't pass the target_word variable from the GUI. The help file is very unclear about how the var.get works - is var the actual file name? Is it a module? I really don't understand.
I think the rest of my code will work for it, so thanks for the way more elegant idea. I have no idea why I didn't think of concatenating the string before. Probably because when I originally designed it, I was just working off what my friend gave me, and was making the program fit her stuff rather than adjusting her stuff to make the program easier.
Hi,
You don't have to get the variable. You can simple use is it by prepending the
var.. So if in your loop table you have the variabletarget_word, you can access its value by writingvar.target_wordin an inline_script. Does that work?Eduard