# Wakefield's Daily Tips

**URL:** <https://discourse.psychopy.org/t/wakefields-daily-tips/43371>\
**Category:** Blog\
**Tags:** online, pavlovia\
**Created:** [January 1, 2025, 3:36pm UTC](https://discourse.psychopy.org/t/wakefields-daily-tips/43371 "2025-01-01T15:36:55Z")\
**Posts on this page:** 20\
**Page:** 4

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [March 2, 2025, 10:28am UTC](https://discourse.psychopy.org/t/wakefields-daily-tips/43371/62 "2025-03-02T10:28:35Z")

</div>

## Use the topic template

I’ve just updated the topic template for the Builder category and copied it (with minor edits) to the Online category.

Please answer the questions on the template.

**OS** (e.g. Win10): Macs can be particularly tricky. Older versions of Windows may need older versions of PsychoPy.

**PsychoPy version** (e.g. 2024.2.4 Py 3.8): Your issue may have been fixed in a later version, or may work better in an earlier version.

**Standard Standalone Installation? (y/n)** If not then what?: Custom installations or VPNs may bring their own problems.

**Do you want it to also run online? (y/n)** Some solutions only work locally (or only work online) so it is useful to know whether you want it to work in PsychoPy and PsychoJS or just one of the two.

**What are you trying to achieve?:** Be brief.

**What did you try to make it work?:** Include custom Python code and/or screen shots of your flow and relevant routines/components.

**Link to the most relevant existing thread you have found:** Search for your error message if you have one, and use the advanced options to find solved topics.

**What specifically went wrong when you tried that?:** Give the error message and/or clear details of what went wrong.

> [@What do you think of the new Discourse forum?](https://discourse.psychopy.org/t/what-do-you-think-of-the-new-discourse-forum/22):
>
> We’re pretty excited about the possibilities of the new forum. Are these the categories you’re expecting to see? More? Fewer? Any other suggestions?

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [March 3, 2025, 5:51pm UTC](https://discourse.psychopy.org/t/wakefields-daily-tips/43371/63 "2025-03-03T17:51:37Z")

</div>

## Use HTTPS to connect to GitLab not SSH

While GitLab gives instructions for using [SSH keys](https://docs.gitlab.com/user/ssh/), this method does not work with [gitlab.pavlovia.org](http://gitlab.pavlovia.org).

Most users should be able to sync directly from PsychoPy Builder without needed to choose between HTTPS and SSH at all.

However, if you do need to make a choice, for example because you are cloning a repository, use HTTPS

 ![](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/9/6/968548c390cf069f06ffd0e59a51f7e24e631a77.png)  
If you have already cloned a repository using SSH, open the hidden `.git/config` file within the project and replace all mentions of `git@gitlab.pavlovia.org:` with `https://gitlab.pavlovia.org/` (or fetch the URL from GitLab site and paste the HTTPS URLs one-by-one.

If you have a reason why you cannot use HTTPS, please give details on the following thread.

> [@Pavlovia GitLab SSH Access Completely Broken](https://discourse.psychopy.org/t/urgent-pavlovia-gitlab-ssh-and-https-access-completely-broken/44086):
>
> Issue Summary: I successfully pushed one version of a PsychoPy experiment to Pavlovia yesterday (2/27/15). Every time I do so, I automatically do the following (which is frustrating but has seemed to work without fail for the past couple of months): Error 500 upon initial sync: In terminal, type cd and drag the hidden .git folder, press enter Then, type git config http.postBuffer 524288000 Then git push -u origin master [See here](https://discourse.psychopy.org/t/500-error-synching-with-pavlovia/41435/4) for more Previously, these steps successfully synced my loc…

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [March 4, 2025, 1:11pm UTC](https://discourse.psychopy.org/t/wakefields-daily-tips/43371/64 "2025-03-04T13:11:59Z")

</div>

## Compare elements not lists

Lists can’t be compared directly.

So, while locally if a = [1, 1] and b = [1, 1] then a == b is True, online a == b will be false.

If you want to check that two lists are identical, check a[0] == b[0] and a[1] == b[1].

Alternatively, if your arrays contain string variables you could join the lists and compare the results. Happily, `"".join(a) == "".join(b)` successfully auto translates to `a.join("") === b.join("")`

> [@Issues with Transferring PsychoPy Experiment to Pavlovia: Array Comparison and Stimulus Material](https://discourse.psychopy.org/t/issues-with-transferring-psychopy-experiment-to-pavlovia-array-comparison-and-stimulus-material/34990):
>
> URL of experiment: Matvey/cat\_learning\_nameability/ Description of the problem: We are currently facing some challenges while transferring our experiment from PsychoPy to Pavlovia. Our Python code was written with the intention of converting it accurately to JavaScript, including the comparison of two arrays in string format with feedback. However, when running the experiment in Pavlovia, the specific code segment we modified to work in Pavlovia does not function as intended. The arrays are be…

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [March 5, 2025, 11:51am UTC](https://discourse.psychopy.org/t/wakefields-daily-tips/43371/65 "2025-03-05T11:51:53Z")

</div>

## Use relative paths

Locally you can specify locations of your resources using absolute paths so which means that, for example, you can keep your stimulus sets separate from your experiments.

Online, all resources need to be in the experiment folder or one of its subfolders. Even when you test on your own computer you can’t ask the browser to look for images on your desktop.

> [@Unknown resource error /object error](https://discourse.psychopy.org/t/unknown-resource-error-object-error/43694):
>
> For my online task I am getting unknown resource error and a few others… I’ve checked the repository and all the image/scene files are being loaded in. I have see most of these topics on unknown resource error and also tried the option to delete the project and all js files and upload it again but no luck. below is my error message

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [March 6, 2025, 10:52am UTC](https://discourse.psychopy.org/t/wakefields-daily-tips/43371/66 "2025-03-06T10:52:21Z")

</div>

## Sound components should start after the routine has started

If you are playing sounds online, then I would recommend setting the start time of any sound files in loops at .1 seconds or later. Since 2023.2 sounds often fail to play online after the first iteration of a loop. It seems to be that if the sound isn’t ready when it is supposed to start it “misses the boat”.

If your sound component has a start condition then I would recommend adding a time component to it. For example:  
**Begin Routine**

```auto
playSound = False

```

**Each Frame**

```auto
if not playSound and t > .1 and showAudio:
     playSound = True

```

Then use playSound as the start condition instead of showAudio (in this example).

Larger sound files may need longer to load, in which case it would be worth including an ITI at the start of the trial routine (rather than having it as a separate routine, which is my usual approach).

> [@Sound component with empty duration won't play after first iteration of loop—changed behavior in 2023.2.0](https://discourse.psychopy.org/t/sound-component-with-empty-duration-wont-play-after-first-iteration-of-loop-changed-behavior-in-2023-2-0/35974):
>
> I recently installed the standalone package of 2023.2.0 (on a Mac), and have an issue that wasn’t present in 2023.1.3. The experiment loops over a single trial routine. In that routine is a sound component trial\_beep that has a specified time (s) Start time, and an empty Stop time. (There’s also a text component and a keyboard component) In 2023.2.0, the sound trial\_beep plays on the first iteration of the loop, but no sound plays on any subsequent iterations of the loop.…

Another solution is to load the audio file in a static period in an earlier routine (within the loop).

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [March 7, 2025, 7:56pm UTC](https://discourse.psychopy.org/t/wakefields-daily-tips/43371/67 "2025-03-07T19:56:43Z")

</div>

## Spreadsheets

One of the aspects I love about PsychoPy is its use of spreadsheets. Before I switched to PsychoPy I used to user SuperLab 2. At the time, you had to enter all of the trial specifications directly into the software. I used to set up the framework of an experiment and then leave the student (whose project I was working on) to laboriously enter the stimuli and then connect each item to the corresponding trial. With SuperLab 4 this aspect was made much easier, but that effectively meant that I no longer had any aspects to delegate to the student.

On the other hand, in PsychoPy I can show the student a template spreadsheet and then ask them to send me an updated one with their stimuli / conditions / file names, etc.

A PsychoPy spreadsheet needs to have variable names in the first row and then conditions the values for those variables in the following rows. There should not be any [empty rows](https://discourse.psychopy.org/t/wakefields-daily-tips/43371/28) and the variable names must not contain spaces. The format can be CSV or Excel xlsx, but in the latter case only the first sheet is used.

What types of variables go in a PsychoPy spreadsheet?

**Information:** So long as ‘is trials’ is ticked in the loop then the values of each variable in the spreadsheet will be copied into the data file. This means that you might include variables such as **ItemType** which have no effect on the experiment, but will be useful at the analysis stage.

**Text:** You can set the text of a text or textbox component to come from a spreadsheet. This is usually used for text stimuli, but it can also be used for longer text, such as instructions. The cells can contain newlines, but their behaviour can be different online compared with locally and Excel vs CSV.

 ![Text component showing a variable called "digit".](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/2/8/28471276355554c501a6a88506e8fac5b193aef1.png)

**File names:** Media cannot be embedded into a PsychoPy spreadsheet. Instead, you can include the file name, including the [relative path](https://discourse.psychopy.org/t/wakefields-daily-tips/43371/65) and extension, such as `images/hat.png`.

**Parameters:** Many numeric parameters can be updated via a spreadsheet. Lists don’t always work so one option is to set the values (for example of positions or colour channels) separately.

**Correct Answer:** Keyboard components (and mouse components in the most recent versions) can accept a variable as the correct answer. If the response matches the given answer, the .corr value is set to 1, otherwise it is set to 0.

**Spreadsheet names:** If you set up concentric loops, the spreadsheet for the outer loop can specify which spreadsheet to use in an inner loop. However, in [another tip](https://discourse.psychopy.org/t/wakefields-daily-tips/43371/23), I recommend setting the selected rows instead.

> [@PsychoPy task will not run when synced to Pavlovia (stuck at initialising)](https://discourse.psychopy.org/t/psychopy-task-will-not-run-when-synced-to-pavlovia-stuck-at-initialising/44137):
>
> Hello hope all is well! I have synced my PsychoPy experiment to Pavlovia, but when I try to pilot the experiment, I get stuck at initialising. I have figured out how to determine where the problem is, and have found the problematic line of code (illegal return error). It is not a builder coding error its in the javascript that is generated. I am not sure where to fix this, or how to fix this. Thank you for your help in advance!

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [March 8, 2025, 8:13pm UTC](https://discourse.psychopy.org/t/wakefields-daily-tips/43371/68 "2025-03-08T20:13:53Z")

</div>

## WordHTML

If you are using an HTML question in Pavlovia Surveys or [embedded HTML](https://discourse.psychopy.org/t/custom-web-component-for-online-experiments-forms-surveys-questionnaires-and-other-web-based-content/14423) in PsychoPy then you will need to convert your formatted text into HTML.

Although I can write HTML from scratch, it is much easier to start with a formatted document or use a WYSIWYG editor. The one I now use all the time is [WordHTML.com](https://wordhtml.com/).

1. Paste formatted text into the Word side.
2. Press the clean button on the HTML side. If this removes too much formatting, click on the undo icon.
3. Make any edits you need on the Word side.
4. Highlight the HTML code.
5. Copy and paste into the HTML markup of a Pavlovia Survey question.

If you are starting with existing HTML, then you can paste into the HTML side, edit on the Word side and then copy and paste the new HTML.

> [@Demo-Code - Converting TextComponent To HTML - textStimToHTML - Highly Experimental](https://discourse.psychopy.org/t/demo-code-converting-textcomponent-to-html-textstimtohtml-highly-experimental/26826):
>
> Dear all, Our lab was frequently running into problems regarding the design and readibility of online-instructions. Especially, colored highlighting inline words were problematic using several independent textComponents, styling them depending on condition etc… One Option is often to use Images of e.g. PPTX to display instructions but this does not really work for instructions that need to be partially edited depending on conditions/experiment block. After another long fight with TextComponent…

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [March 9, 2025, 11:34am UTC](https://discourse.psychopy.org/t/wakefields-daily-tips/43371/69 "2025-03-09T11:34:08Z")

</div>

## Saving incomplete results

When I create a new study on Pavlovia, one of the first things I do is turn off “save incomplete results”.

 ![image](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/9/c/9c9c8669ea209f6ddac85233543e8c77db7ab3f1.png)

 ![image](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/2/2/22bba464d7868734c26295007519451187b7fa35.png)

The reason I do this is to avoid having lots of data files getting created while I build and test the experiment. This is especially important if you use credits rather than a licence, since each data file will cost a credit.

Even when turned on, saving incomplete results can be a bit hit and miss. The data is always saved if you press escape to exit full screen and then press escape again. It also seems to work if you press escape and then close the tab, but not if you press escape and then navigate to another web page within the same tab.

The other issue is that if you have saving incomplete results turned on, you will get near empty data files from anyone who exits near the start of the experiment, for example before consenting or while reading the instructions.

My recommendation is to turn on incomplete data saving in code at the point where enough results have been collected that you would consider using them. Be mindful of research ethics. If you have told your participants that they have the right to withdraw at any point in the study and the only way to withdraw is by pressing escape, then ethically you should not use their data.

With this in mind, the code to turn on incomplete data saving is:

```auto
psychoJS._config.experiment.saveIncompleteResults = true;

```

It should appear in a JavaScript code component or on the JS side of a Both code component.

In the [example](https://run.pavlovia.org/test-suite/incomplete-results) I wrote to test this today, I turn on saving incomplete results on the fourth iteration of the loop with:

```auto
if ((trials.thisN === 3)) {
    psychoJS._config.experiment.saveIncompleteResults = true; // enable partial data collection
}

```

As noted in the linked thread, this code may not work in Firefox, but I don’t know if that means that incomplete data saving doesn’t work at all, whether the value can’t be changed in code, or whether changing the value after the start of the experiment has no affect.

> [@Disabling partial data collection midway through an experiment](https://discourse.psychopy.org/t/disabling-partial-data-collection-midway-through-an-experiment/20461):
>
> I found a way to disable partial data collection midway. This is especially useful because credits are consumed even when very little data is generated. So we can enable partial data collection only after a certain amount of blocks have been performed and disable it until those blocks are completed. I needed this especially because my practice and main experiment are on the same link however the practice data is not needed and furthermore we ask the participant to abort the experiment when they…

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [March 10, 2025, 4:57pm UTC](https://discourse.psychopy.org/t/wakefields-daily-tips/43371/70 "2025-03-10T16:57:47Z")

</div>

## Extending lists

In Python you can extend lists using the addition sign or the extend function.

```auto
a = [1, 2]
b = [3, 4]
a = a + b
print('a1', a)
a.extend(b)
print('a2', a)
b = b.extend(b)
print('b1', b)

```

**Output**  
a1 [1, 2, 3, 4]  
a2 [1, 2, 3, 4, 3, 4]  
b1 None

For PsychoJS this code is auto translated to:

```auto
a = [1, 2];
b = [3, 4];
a = (a + b);
console.log("a1", a);
a.concat(b);
console.log("a2", a);
b = b.concat(b);
console.log("b1", b);

```

**Output**  
a1 1,23,4  
a2 1,23,4  
b1 [3, 4, 3, 4]

Two things are going wrong here.

1. a + b is concatenating the two lists as strings.
2. a.concat(b); doesn’t alter list a

As per [Wakefield's Daily Tips - #27 by wakecarter](https://discourse.psychopy.org/t/wakefields-daily-tips/43371/27), here is a custom function for joining two lists.

 ![image](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/f/5/f5225e5b23fad363b1fccf46e7a74ab903af6e30.png)

**Python**

```auto
def concat(a, b):
    return a + b

```

**JavaScript**

```auto
function concat(a, b) {
    return a.concat(b);
}

```

Then in your code component, write `c = concat(a, b)` instead of `c = a + b`.

This could be exended to three (or more) lists using a+b+c+etc. and a.concat(b, c, etc.) in the function. If would also be possible to set up a more complex function which checks the number of arguments, but unless you are regularly concatenating a chain of lists, it would probably be easier to just call the simple function more than once.

> [@Select subset of stimuli – nothing is displayed](https://discourse.psychopy.org/t/select-subset-of-stimuli-nothing-is-displayed/29301):
>
> URL of experiment: [Sign in · GitLab](https://gitlab.pavlovia.org/inga.lueck/fadeoutdt2_livk-mi) Description of the problem: I try to create individual stimulus lists for each participant. There are four different stimulus categories and all stimuli of each category should be divided into biased (14 items/category) and unbiased (3 items/category) sets. Begin experiment – Python exp\_block = 0 myTrialCounter\_baseline\_size = -1 # create list with all stimuli all\_la\_stim = ['Stimuli/bear.jpg', 'Stimuli/dog.jpg', 'Stimuli/donkey.jpg', 'Stimuli/elephant.jpg…

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [March 11, 2025, 7:44pm UTC](https://discourse.psychopy.org/t/wakefields-daily-tips/43371/71 "2025-03-11T19:44:18Z")

</div>

## Saving screenshots

I haven’t managed to get this working online, but locally you can take a screenshot with `win.getMovieFrame()` and then save it with the name file name as the rest of your data files using `win.saveMovieFrames(thisExp.dataFileName+'.png')`. You might want to have the get code in Each Frame but make sure it doesn’t run every frame.

The closest I’ve got with saving a screenshot online is `saveScreenshot("screenshot");` where saveScreenshot is defined in Before Experiment as:

```auto
function saveScreenshot(filename, scale = 0.5) {
    let canvas = document.querySelector('canvas'); // Get the PsychoJS canvas

    // Create a smaller offscreen canvas
    let scaledCanvas = document.createElement('canvas');
    let ctx = scaledCanvas.getContext('2d');
    
    // Set new dimensions (50% of original size)
    scaledCanvas.width = canvas.width * scale;
    scaledCanvas.height = canvas.height * scale;
    
    // Draw original canvas onto the smaller canvas
    ctx.drawImage(canvas, 0, 0, scaledCanvas.width, scaledCanvas.height);

    // Convert to Base64 PNG
    let imageData = scaledCanvas.toDataURL("image/png");
    let base64Data = imageData.split(',')[1]; // Remove metadata

    // Store Base64 image data in experiment file
    psychoJS.experiment.addData(filename, imageData);

    console.log("Screenshot saved at reduced resolution:", filename);
}

```

This should save the base64 image data into a cell in the CSV file at 50% resolution to reduce the amount of data. However, when I pasted the resulting code into a web browser, I got a white rectangle. Suggestions welcome.

> [@Export frames to images](https://discourse.psychopy.org/t/export-frames-to-images/10535):
>
> Hi, Very new to PsychoPy. I’m trying to export every frame within my looped routine as an image (preferably jpeg) so that I can upload the task to Mturq. I tried entering code into the “each frame” tab on the code component in builder, but it doesn’t seem to be working. Any idea what the best/simplest line of code to use for this would be? Do I need to add anything else? Thank you!!

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [March 12, 2025, 9:57am UTC](https://discourse.psychopy.org/t/wakefields-daily-tips/43371/72 "2025-03-12T09:57:49Z")

</div>

## Random functions

Do not import random in Builder. As mentioned in [Wakefield's Daily Tips - #19 by wakecarter](https://discourse.psychopy.org/t/wakefields-daily-tips/43371/19) Builder scripts already contain the line:

```auto
from numpy.random import random, randint, normal, shuffle, choice as randchoice

```

Their usage follows:

```auto
a = random() # for a random number 0 <= a < 1
b = randint(i) # for a random integer 0 <= b < i
c = normal(m, s) # for a random sample from a Gaussian distribution of mean m and standard deviation s
shuffle(d) # to shuffle list d
e = randchoice(d) # for a random item from list c

```

These auto translate to:

```auto
a = Math.random();
b = util.randint(i);
c = normal(m, s);
util.shuffle(d);
e = util.randchoice(d);

```

However, for them all to work online, you need to define a normal function in **Before Experiment** in a JavaScript (or Both) code component.

```auto
function normal(mean=0, stdev=1) {
    const u = 1 - Math.random(); // Converting [0,1] to [1,0]
    const v = Math.random();
    const z = Math.sqrt( -2.0 * Math.log( u ) ) * Math.cos( 2.0 * Math.PI * v );
    // Transform to the desired mean and standard deviation:
    return z * stdev + mean;
}

```

This uses the [Box-Muller transform](https://en.wikipedia.org/wiki/Box%E2%80%93Muller_transform) and this Python code came from [algorithm - JavaScript Math.random Normal distribution (Gaussian bell curve)? - Stack Overflow](https://stackoverflow.com/questions/25582882/javascript-math-random-normal-distribution-gaussian-bell-curve).

In Python you can add a size parameter to some of these functions to return a list or array of random numbers, but I would advise against using this since it doesn’t translate to PsychoJS.

> [@Specify stimulus parameters according to normal distribution in loop](https://discourse.psychopy.org/t/specify-stimulus-parameters-according-to-normal-distribution-in-loop/27050):
>
> I am experiencing a mental block on how to get Builder to vary a certain stimulus parameter randomly according to a pre-defined distribution. Say I want to have 10 trials where I show a bar where the length of the bar is determined by a normal distribution with a certain mean and standard deviation, and I want to have different blocks where I vary the standard deviation (e.g. high v low variability). How can I do that in builder? I know I could hard-code some values in the conditions file, b…

> [@Pavlovia- Randchoice is not defined](https://discourse.psychopy.org/t/pavlovia-randchoice-is-not-defined/32524):
>
> URL of experiment: [Pavlovia](https://pavlovia.org/Margo/league_visualsearch) Description of the problem: Heya, I’m trying to launch my experiment online but I don’t get very far. I’m getting this error message: “ReferenceError: randchoice is not defined” I do use randchoice in my code but I’m not sure if I need to substitute it with something else. I’m a bit lost confused I’m grateful for any help! Thanks in advance. Margo

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [March 13, 2025, 9:41pm UTC](https://discourse.psychopy.org/t/wakefields-daily-tips/43371/73 "2025-03-13T21:41:42Z")

</div>

## Pilot mode

Piloting a PsychoPy experiment can mean one of three things.

Locally you can switch between Pilot and Run mode by clicking on the toggle between the two words.

 ![Pilot mode](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/6/4/64fa30c82b2667a778e189adaba0d230bda68c97.png)  
 ![Run mode](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/c/c/cc3aaa35ccc95fe7df9150299ca5d195ea52743d.png)

In pilot mode the two run buttons are orange instead of green.

Pressing the main run button will run the experiment in a window (rather than full screen) and include a and orange border and the warning **PILOTING: Switch to run mode before testing**.

 ![Running locally in pilot mode](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/7/0/704841cc30aedb728f36dad07f474d86643838a0.png)

The parameters for Pilot mode can be edited from File / Preferences

 ![Pilot mode preferences](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/3/8/38ee4ce38ddf5aa2e396647755e7d77cda7c5b7d.png)

If instead of piloting locally, you press the JS run button, the experiment will be run locally in your default browser (in full screen). To do this, a copy of the PsychoJS libraries are downloaded to a lib folder in your experiment folder.

 ![Local lib folder](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/d/6/d6ca5228397df73461e3a303a7a16cd0a3dc38af.png)

If you switch to Run mode and press the JS then you will instead be sent to the appropriate web link. However, if you haven’t already synced your experiment with Pavlovia then you will first be prompted to create a project and will the get a 404 not found error.

 ![run.pavlovia.org/test-suite/test-simple](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/5/a/5a574f8a9e7f1acd17cf4177a7edbba30940ffef.png)

Before you can run an experiment online, you must visit the project page – the link appears in the Stdout and Pavlovia tabs of the Runner every time you sync.

 ![New Pavlovia project page](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/a/9/a9f4b5b74b80fcda3c6d03fcbbeaa2a242ef35b1.png)

Online, experiments can be in one of three modes: Inactive, Piloting and Running. In this screenshot, the software platform is unknown and the platform version is 0. The experiment will not run online. To pilot the experiment online, switch the mode to Piloting by clicking on the Piloting message.

 ![pavlovia.org/test-suite/test-simple](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/9/1/91b8aab024fd64fbb11b5f5dad1c3c2f34d2c50c.png)

The experiment now has platform PSYCHOJS and version 2024.2.4 (or whatever version you are using). To pilot online, you press the Pilot button in the top right.

A pilot token will be generated so the experiment can run, e.g.

```auto
https://run.pavlovia.org/test-suite/test-simple/? __pilotToken=3c59dc048e8850243be8079a5c74d079&__ oauthToken=6204c1a913ae8582005a283175a1aa23cade068d6403dce894a26bb8b2bf5641

```

When you pilot an experiment, data is downloaded to your computer. You should therefore keep the results format set to CSV so you get spreadsheets rather than JSON data files – though you will get a JSON download after every embedded Pavlovia Survey and a sound file after each microphone component.

If the experiment is in piloting mode online and you try to run it online from Builder, you will now get a different error message.

 ![Missing pilot token](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/6/4/647ad522bfedca3c8b23355f981ea238e0a9a3a7.png)

If you switch the experiment to running mode, then it will now run if you have a licence or have assigned credits to the study. If neither of these are true, the error message will be:

 ![Not enough credits](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/7/5/75ca9bfd7bb33062fd17766cf4d6c8d07f40d710.png)

If you are using credits, don’t forget to turn off save incomplete results before you add any.

Note that the lib folder from piloting in the local browser does not get uploaded. If you view code, your Gitlab folder should look something like this.

 ![gitlab.pavlovia.org/test-suite/test-simple](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/2/c/2cbc956b1c46d19ef91660ead1172e02d9708b5e.png)

> [@New to psychpy: Failed to load resource: the server responded with a status of 404 ()](https://discourse.psychopy.org/t/new-to-psychpy-failed-to-load-resource-the-server-responded-with-a-status-of-404/43455):
>
> URL of experiment: [SDS [PsychoPy]](https://run.pavlovia.org/lvillarreal22/sds_2/? __pilotToken=e4da3b7fbbce2345d7772b0674a318d5&__ oauthToken=81949ee1f139c16f386d18b6bd63206bfa119ed8b33a910aadc4c868e85cbd1d) Description of the problem: Hi I’m brand new to pavlovia and coding in general, I’ve been having issues getting my file working online. Currently, I’ve created a brand new file with just a red triangle for stimuli just to see if I can get something up, but even this is getting the 404 error. I’ve turned the project into pilot mode, and have tried launching from both the builder and the pavlovia website. I looked around the forums and saw that switching to the …

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [March 14, 2025, 9:30pm UTC](https://discourse.psychopy.org/t/wakefields-daily-tips/43371/74 "2025-03-14T21:30:46Z")

</div>

## Submitting slider responses

The easiest way to add a slider which allows the participant to select a response but change it before submitting is to have a button component with a start condition of `showButton`.

Then create a code component with the following code:  
**Begin Routine**

```auto
showButton = False

```

**Each Frame**

```auto
if not showButton:
    try:
        if isinstance(slider.getRating(), float):
            showButton = True
    except:
        pass

```

This code is more complex than I would like because slider.getRating() can’t be checked until it exists and Auto code components translate None to null instead of undefined in this instance.

 ![image](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/1/d/1d27eed62634115d71089ef8363cb6a566f22d5e.png)

 ![image](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/8/9/89976f23a3fd1a7a8add7a4a893b81fd3d7bf3e3.png)

 ![image](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/6/7/672d3202ec32cbcc8748b3c8825717721be06a36.png)

 ![image](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/2/7/275600fdfb083ef6d47e88b5f236126f08bed0d9.png)

Locally this slider looks like:

 ![image](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/0/5/051e0e078c5b22d7909cbb652fdcd88751ae4722.png)

Online it is slightly different.

 ![image](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/0/8/084d9f9d3c7381bbf97c0f662748ac0289f80466.png)

> [@Participants cannot select 0 values in slider](https://discourse.psychopy.org/t/participants-cannot-select-0-values-in-slider/32359):
>
> Win11 PsychoPy 2022.2.4 Standard Standalone? (y) \*\*What are you trying to achieve?: I have a working experiment that runs smoothly with a 0-100 slider: While performing a pilot, participants complained that they could not select 0 values on the slider presented. They had to select another point in the scale and then click back on the 0 value so that the program allows them to select such an answer. I have no idea what is happening or what to do to make it work correctly. I am afr…

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [March 15, 2025, 5:53pm UTC](https://discourse.psychopy.org/t/wakefields-daily-tips/43371/75 "2025-03-15T17:53:44Z")

</div>

## Don’t modify spreadsheet variables

If you have a situation where you sometimes use the value of a variable from a spreadsheet in a component and sometimes want to change the value, copy the value to a different variable. Editing the spreadsheet variable causes an error online.

Locally, something like this will work:

```auto
if imageFile == 'x': # where imageFile comes from a spreadsheet
     imageFile = 'transparent.png'

```

To ensure online compatibility, do this instead:

```auto
if imageFile == 'x': # where imageFile comes from a spreadsheet
     thisImage = 'transparent.png'
else:
     thisImage = imageFile 

```

In this case, you should also put `thisImage = 'transparent.png'` in Begin Experiment

> [@Error when importing conditions in nested loops](https://discourse.psychopy.org/t/error-when-importing-conditions-in-nested-loops/14070):
>
> URL of experiment: [Pavlovia](https://pavlovia.org/bianhaan/feng2013_mindwandering) (or [Sign in · GitLab](https://gitlab.pavlovia.org/bianhaan/feng2013_mindwandering) if that’s more helpful) Description of the problem: In case it’s helpful, I am trying to create a PsychoPy/PsychoJs version of this experiment: [OSF | Feng, S., D’Mello, S., & Graesser, A. C. (2013). Wiki](https://osf.io/56m9b/wiki/home/) The experiment runs beautifully in PsychoPy, but I am having trouble getting it to run in Pavlovia. I seem to basically have the same problem as reported on [Psychojs - Inner Loop pattern - #8 by rrennert14](https://discourse.psychopy.org/t/psychojs-inner-loop-pattern/8087/8) and [Error When importing condition: ex…](https://discourse.psychopy.org/t/error-when-importing-condition-extension-currently-not-supported/12456)

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [March 16, 2025, 8:31am UTC](https://discourse.psychopy.org/t/wakefields-daily-tips/43371/76 "2025-03-16T08:31:02Z")

</div>

## Custom function: defined

In [Wakefield's Daily Tips - #74 by wakecarter](https://discourse.psychopy.org/t/wakefields-daily-tips/43371/74) I dealt with the fact that None doesn’t get translated in a component condition and gets translated to null instead of undefined in a code component by using a **try except** clause. Today’s tip is a simpler solution. The start condition of the button component can be set to a function which is defined differently in Python and JavaScript.

Add the following **Before Experiment**.  
**Python**

```auto
def defined(x):
    return x != None

```

**JavaScript**

```auto
function defined(x) {
    return (x !== undefined);
}

```

Then set the start condition for the button to `defined(slider.rating)`.

The **defined** function can be used anywhere where 0 is a valid value of **x**. In other cases (including where x can equal “0”) you can just use `if x:`

> [@Participants cannot select 0 values in slider](https://discourse.psychopy.org/t/participants-cannot-select-0-values-in-slider/32359):
>
> Win11 PsychoPy 2022.2.4 Standard Standalone? (y) \*\*What are you trying to achieve?: I have a working experiment that runs smoothly with a 0-100 slider: While performing a pilot, participants complained that they could not select 0 values on the slider presented. They had to select another point in the scale and then click back on the 0 value so that the program allows them to select such an answer. I have no idea what is happening or what to do to make it work correctly. I am afr…

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [March 17, 2025, 11:11pm UTC](https://discourse.psychopy.org/t/wakefields-daily-tips/43371/77 "2025-03-17T23:11:35Z")

</div>

## IrfanView

I have been using [IrfanView](https://www.irfanview.com/) for image resizing, cropping, etc. since 2001 when I needed to create thumbnails of over 1000 cover images when I was webmaster for the official [2000 AD](https://2000ad.com/) website. My version of the site, is now called BARNEY and can be found at [2000ad.org](https://2000ad.org/).

IrfanView is no good for drawing or layers – the closest I get to this with it is copying some background colour to paste over an unwanted feature.

Where it comes into its own is batch processing.

 ![Batch conversion](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/f/8/f8a912589ce64b58d51bd9f455cc8719cf0b2310.png)

You can convert file types, rename or both.

 ![Advanced options](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/c/e/cebee351fdc8177eb533c0dd160f922c96e077bc.png)

These settings were used most recently to reduce the size of a set of face stimuli.

 ![Batch rename settings](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/5/8/58288e91f6ec2060f93db0aa183e1444878a76ad.png)

IrfanView is Windows only I’m afraid.

> [@Different Image Sizes - Different Screen Resolutions. How to keep the same dimensions in the image as in the original jpg with different screen resolution](https://discourse.psychopy.org/t/different-image-sizes-different-screen-resolutions-how-to-keep-the-same-dimensions-in-the-image-as-in-the-original-jpg-with-different-screen-resolution/33059):
>
> (Working with psychopy builder v2022.2.4) Hello! I am a Student an i am new in using psychopy. My aim is to program an experiment where i can show my participants a folder full of images for a memory task. so i did a loop with an image trail. all good. But the problem is now, that the images ar so big (for ex. 3959x5938 pixel) and different in their sizes, that i have a problem in showing them. if i would knew the resolution of the target screen, i think i would know how (with a variable in th…

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [March 19, 2025, 12:37am UTC](https://discourse.psychopy.org/t/wakefields-daily-tips/43371/78 "2025-03-19T00:37:23Z")

</div>

## YayText bold and italic text generator

If you want to change an individual word in a text component to **bold** or _italics_ locally then you can use `<b> </b>` and `<i> </i>`html tags in a textbox component. However, the bold doesn’t work very well.

 ![image](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/f/3/f38a91b03e937df5ce7bcae0e83b4015876d955b.png)

Ironically these don’t work online. There is, however, an alternative to turning your text into an image. [YayText](https://yaytext.com/bold-italic/) is an online tool where you can create bold and italic versions of individual words using unicode. The site also has other options, but these seem the most useful. The unicode versions of the words don’t work locally but can be inserted into text or textbox components online directly, or via a spreadsheet variable.

> [@Problem with getting text to show up bold](https://discourse.psychopy.org/t/problem-with-getting-text-to-show-up-bold/18051):
>
> Hi! I’m trying to display text in bold. I’m using Builder on a Mac, Psychopy version 2020.1.2. Here’s what I’ve tried so far: (1) Typing \*\* text \*\* and \< b \> text \< /b \> (without spaces), or text.bold = True before the text. In all of these cases, the text just appeared that way in the experiment without bolding. (2) I’ve added bold = True to the TextStim arguments, but the text still didn’t appear bold when I ran the experiment. Adding other arguments worked, but not bold. (3) I downloaded …

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [March 19, 2025, 11:50am UTC](https://discourse.psychopy.org/t/wakefields-daily-tips/43371/79 "2025-03-19T11:50:54Z")

</div>

## Custom function: remove

In Python `list.remove(element)` removes the first appearance of element from list, modifying list in place.

To mimic this behaviour in PsychoPy, add the following function in the **Before Experiment** of a JavaScript code component (or the JS side of a Both component).

```auto
Array.prototype.remove = function(value) {
    let index = this.indexOf(value); // Find the first occurrence
    if (index !== -1) {
        this.splice(index, 1); // Remove it in place
    }
};

```

Note, that this function isn’t the same as the one I’ve previously recommended but that function doesn’t seem to work any more. Perhaps it never did.

> [@Urgent---Online does not work though local works](https://discourse.psychopy.org/t/urgent-online-does-not-work-though-local-works/28222):
>
> [InI.psyexp](https://discourse.psychopy.org/uploads/short-url/3Rz8DX9Bhvdqy9XJF962DJuG5uh.psyexp) (26.5 KB) Please see the relevant part of the routine attached. Example of a trial (image, word and imagery must be incongruent): 1- select an image If the image = red, then word and imagery cannot be red (.remove(1) ) 2. select a word If word = blue then imagery cannot be blue either (.remove(5)) 3. select an imagery Since the image is red word is blue imagery cannot be either. imagery = purple My custom (I do not work in coder mode) Py code is auto-translated to Js. The…

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [March 20, 2025, 8:27pm UTC](https://discourse.psychopy.org/t/wakefields-daily-tips/43371/80 "2025-03-20T20:27:06Z")

</div>

## Anonymous Participant IDs

If you would like to match participant data across multiple sessions, but do not want to break anonymity by storing a lookup table of email address to participant ID, feel free to use my [VESPR Anonymous Participant IDs](https://moryscarter.com/vespr/id.php) tool.

To use it, you would need to send your participants to the site and ask them to enter their email address and request an ID. Their address is converted into a number which is then emailed to them for use in your study. This method does, of course, rely on your participants remembering which email address they used if they go back to the site rather than checking their emails for the follow-up time points.

My site does not keep a record of what email addresses have requested IDs and it would be impossible to convert the ID number back into an email address. In theory there is a small risk that two participants could be allocated the same ID but the algorithm makes this very unlikely.

Please cite this reference if you use the tool in your research.

Morys-Carter, W.L. (2021, November 2). _Anonymous participant IDs_ . VESPR. [https://moryscarter.com/vespr/id.php](https://moryscarter.com/vespr/id.php).

> [@Linking participants repsonses in two time frame data collections](https://discourse.psychopy.org/t/linking-participants-repsonses-in-two-time-frame-data-collections/32783):
>
> Has anyone idea how do you allow participants to generate individual codes so they can access the survey at time 1 ( pre intervention) and then at time 2 (post intervention) ? Is there a way to link the participants’ responses from time 1 and 2? while keeping it all anonymous?

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [March 21, 2025, 8:26am UTC](https://discourse.psychopy.org/t/wakefields-daily-tips/43371/81 "2025-03-21T08:26:55Z")

</div>

## PsychoPy Primer

In my role as a psychology demonstrator at Oxford Brookes University, I teach and support research methods and statistics. I tend to make presentations in Google Slides and allow them to be viewed by anyone, not just members of my institution.

Today’s tip is a link to my PsychoPy Primer slides which I overhauled last year for a BPS Cognitive section workshop. The hidden slides are ones I decided to skip when I last presented them to second year undergraduates – though I think I should change my approach for that class next year.

> **[PsychoPy Primer](https://docs.google.com/presentation/d/1T66SmoiNKaDG0MjFdbnrVXE7cJYMDwldvjWVBmNPiGY/edit?usp=sharing)**
>
> PsychoPy Primer Wakefield Morys-Carter tinyurl.com/ psychopy2024

If you are really interested, here are the pre-overhaul slides.

> **[PsychoPy Primer -- old version](https://docs.google.com/presentation/d/1ooHS0rQFt28A381yWFOd6VHGiuW_RIPZiSYBIZp0e68/edit?usp=sharing)**
>
> PsychoPy Primer (old)

> [@Couldn't connect to psychopy.org - first Psychopy use](https://discourse.psychopy.org/t/couldnt-connect-to-psychopy-org-first-psychopy-use/43604):
>
> OS: win10 PsychoPy version: v2024.2.4 \*\*Standard Standalone? \*\* : yes What are you trying to achieve?: I am a first time user and am trying to run demos and simple scripts to understand how Psychopy works. What did you try to make it work?: I tried to run the colors.py demos in the Coder section but I received the following error message (my computer is connected to the internet so I don’t understand what went wrong): 522.7231 WARNING Couldn’t connect to [psychopy.org](http://psychopy.org) Check internet…

[Previous page](https://discourse.psychopy.org/t/wakefields-daily-tips/43371.md?page=3)

[Next page](https://discourse.psychopy.org/t/wakefields-daily-tips/43371.md?page=5)
