#### Howdy, Stranger!

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

#### Categories

Supported by

edited October 17

I am trying to do the AMP on OpenSesame but I can’t seem to figure out how to randomly present the target stimuli for each prime.

I have 30 primes and 10 target stimuli but I’m not sure how to get the target stimuli to be randomly presented after each of the 30 primes. Need a little help with this thank you!

• Hi @Ashleigh,

Could you be a little more specific or upload a basic version of your task? Are you using an orthogonal design in which each target is to be presented with a fixed set of 3 primes with trials in a random order? Or are you trying to pair purely randomly (and in a different random arrangement for each subject) targets and primes? Are you presented 10 trials (10 targets) and want to select a prime at random? Selection with or without replacement? What have you tried so far?

A clearer description of what you're trying to achieve would be great in order to try to help you.

Best,

Fabrice.

• Hi Fabrice,

Thanks for the reply! To explain more specifically, I am hoping to have

• 4 blocks of 30 trials each
• Within each block of 30 trials, there are 30 primes, 15 for each of 2 prime conditions
• Within each block of 30 trails, there are 30 targets. The pairing of targets and primes to be completely random (i.e., each target does not need to be paired with each prime). Since the targets and trials are equal, each target should appear once.

I am stuck with the third point above. Hope this description helps.

Regards,

Ashleigh

• Hi @Ashleigh,

Thanks for the clarification. I think I understand what you want to do now: you have 30 trials per block, and you want 30 targets to be presented in random order and randomly paired with primes.

There may be several ways of achieving this. I'll suggesting one involving some coding. the coding could be done in Python or in Javascript. Here, I've used Javascript (if you're planning to run your experiment in a browser or online with OSWeb, you'd have to opt for the latter).

Since you want a random pairing of the targets and primes, you can't put the details of both into a loop, because the pairing would then be fixed. So here's what I'm suggesting:

In the loop, only specify the primes and leave targets blank. Store the list of targets in an array, shuffle the array, then pull data from the array using the trial counter as index.

Here is some Javascript code that declares a shuffling function (which will work regardless of the length of your array), and then code that declares the array (where you can see I declared targets as target1, target2, ..., target 30).

```// defines function to shuffle the content of an array
function shuffleArray(array) {
let curId = array.length;
// There remain elements to shuffle
while (0 !== curId) {
// Pick a remaining element
let randId = Math.floor(Math.random() * curId);
curId -= 1;
// Swap it with the current element.
let tmp = array[curId];
array[curId] = array[randId];
array[randId] = tmp;
}
return array;
}
// Usage of shuffle
// arr contains the list of targets
let arr = ["target1", "target2", "target3", "target4", "target5","target6", "target7", "target8", "target9", "target10","target11", "target12", "target13", "target14", "target15","target16", "target17", "target18", "target19", "target20","target21", "target22", "target23", "target24", "target25","target26", "target27", "target28", "target29", "target30"];
arr = shuffleArray(arr);
console.log("Shuffled order :"+arr);
console.log ("arr[0]:"+arr[0]);
// passing arr to vars.arr in order to be able to use it outside this inline_javascript object
vars.arr=arr;
// ressting trial number to 0
vars.trial_counter=0;

console.log ("vars.arr[0]:"+vars.arr[0]);
```

This is to be executed in ahead of running the block of trials.

Next, you'd simply have to retrieve the a target from the vars.arr array, using the trial number as index, so if the shuffled list of targets starts with target26, target2, target9,..., the task will show target26 in trial 1, target2 in trial 2, target 9 in trial 3 and so on.

I attach the little task I put together here, so you can try it out:

Now, beware that I only implemented one block. It's just to show you the method; you'll have to adapt it to your task. Also, for simplicity, I just used text stimuli for primes and targets. In your case, you'd have to adapt it to whatever you're using (pictures, for example).

I included various console commands to help track what's going on. I recommend you do the same in your task as you adapt it to use the code above.

Hope this helps. Good luck!

Best,

Fabrice.

PS: when replying in the forum, it's better if you use user handles by typing "@" and the first letters of your correspondent's handle, then selecting from the list. That way, your correspond gets a notification about your message (otherwise, they won't see it unless they happened to revisit a conversation). So, for example, if you type "@F", you'll see this:

_____________________________________________________________________________________

If you found my reply helpful and wish to invite me to a coffee, you can do so here 😉: https://www.buymeacoffee.com/psyfab

• Hi @Fab,

This was really helpful, thank you!

Just a follow up question, if I would like to use pictures as my targets, how should I do it in the javascript? Apologies as I am very unfamiliar with javascript.

Regards,

Ashleigh

• edited August 14

Hi @Ashleigh,

The Javascript code simply randomizes alphanumerical strings. It is not what defines whether your stimuli are text, picture, sounds etc.

It is worth familiarizing yourself a little with the Javascript code to understand what each bit does (that way you'll find it easier to modify the code if needed or to debug possible problems). If you look carefully at the code, you'll see that all it does is to shuffle the order of the elements of the arr array, and later on to allocate each element of the shuffled array to the target variable (vars.target). From then on, the objects in the task can access the content of that variable using [target]. In a nutshell, the Javascript creates a randomized list of elements that are then inserted into the loop as each trial runs.

So, all the Javascript code does is to randomize strings that you can replace with filenames or use as part of a filename if you prefer. The same way as the random selection randomizes the order of the trials in the loop:

So, you can use these strings to refer to pictures in the same way as you would in the loop. Obviously, you'll have to refer to [target] and [prime] when you define the picture objects on the relevant sketchpads in your task. You can do that in two ways.

Method 1: change the strings to "target1.jpg", "target2.jpg", etc., and "primeA1.jpg", "primeA2.jpg", etc.

Step 1: edit the Javascript code to change the content of the arr array to add the ".jp" suffix to every element of the array:

Step 2: in the loop, make sure to use the complete filenames:

Using this method, the information you'll find in your output data will be the filenames (target1.jpg, primeA1.jpg, etc.).

Method 2: don't change anything to the Javascript code but simply add the file suffix in the script of the sketchpads to tell OS where to get the filenames from:

You'd have to do that for the sketchpad containing your prime and for the sketchpad containing your target. I'm assuming you're familiar with the sketchpad script and know how to insert pictures in sketchpads.

Of course, with either method, make sure that all your pictures are loaded into OS's file pool.

Good luck!

Fabrice.

_____________________________________________________________________________________

If you found my reply helpful and wish to invite me to a coffee, you can do so here 😉: https://www.buymeacoffee.com/psyfab

• Hi @Fab,

That was really helpful, thanks so much!

Regards,

Ashleigh

• Hi @Fab

I did the same proccedure im my experiment.

First of all, thank you for this response.

Second, in my experiment the images are not pull from the pool. I followed every single step but when i run the experiment i get "target.jpg" text in the sketchpad and not the image.

Do you have any idea how to solve it?

Zohar.

• Hi @zohar ,

It sounds like you are drawing text rather than an image on top of your background. Instead of having a line such as this

```draw textline center=1 color=white font_bold=no font_family=serif font_italic=no font_size=32 html=yes show_if=always text="[target]" x=0 y=0 z_index=0
```

in your OpenSesame script, you should have something like this:

```draw image center=1 file=[target] scale=1 show_if=always x=0 y=0 z_index=0
```

Do you see the difference?

Good luck!

Cheers,

Lotje

Did you like my answer? Feel free to

• YES!! It works graet.

thank you!