| Reference | Downloads | Github

Trouble loading csv files

URL of experiment: Sign in · GitLab

When I run the experiment online it does not load the csv files. I have 3 csv files defining different trial sequences for different conditions. Participants are randomly assigned to different conditions using a code component

In python:

resp_mode = np.random.randint(2)
if resp_mode==0:
    # ----- Unimanual -----
    resp_mode2 = np.random.randint(2)    
    if resp_mode2==0:
        # --- LHand ---
        cond_file = 'seq_uL.csv'
        intro_btext = "Press D for acw, C for cw"
    elif resp_mode2==1:
        # --- RHand ---
        cond_file = 'seq_uR.csv'
        intro_btext = "Press M for acw, K for cw"
    # ----- Bimanual -----
    cond_file = 'seq_b.csv'
    intro_btext = "Bimanual"

& in javascript

resp_mode = np.random.randint(2);
if ((resp_mode === 0)) {
    resp_mode2 = np.random.randint(2);
    if ((resp_mode2 === 0)) {
        cond_file = "seq_uL.csv";
        intro_btext = "Press D for acw, C for cw";
    } else {
        if ((resp_mode2 === 1)) {
            cond_file = "seq_uR.csv";
            intro_btext = "Press M for acw, K for cw";
} else {
    cond_file = "seq_b.csv";
    intro_btext = "Bimanual";

In builder, in trials Properties dialogue, I set the conditions to be $cond_file.

This works when running it in python - I am randomly assigned to different conditions.

But - when running it online I get the following error message:

(Langle is the first variable to be called that is defined in the csv files) - this suggests that I am not loading the csv file correctly. I thought it might be because the csv files were not in the “resources” folder in the html - but this didn’t work either. Neither did specifying the file by hand (i.e. instead of it being random, replacing $cond_file with seq_b.csv. Neither did specifying the path (resources/seq.csv).

Any thoughts?

Thanks for your time!

1 Like

I’m not sure you can do that in a code component. You can do that in a nested loop structure in the builder, that is, have the condition file for a lower-level loop be controlled by a higher-level loop, but I don’t know that you can use a code component to load a conditions file after the experiment has initialized like that.

1 Like

I am no expert but from my own experience trying to get things running online, you first of all need to address that numpy does not exist in Javascript. You need to use Javascript Maths functions. Search the forum for those to implement. This means that in general your if conditions wouldn’t have worked.


Thanks @Julia_Landsiedel - the np thing was definitely part of the problem, I have replaced the JS code component with this:

resp_mode = Math.ceil(Math.random() * 2);
if ((resp_mode === 1)) {
    resp_mode2 = Math.ceil(Math.random() * 2);
    if ((resp_mode2 === 1)) {
        r_mode = 0;
        intro_btext = "Press D for acw, C for cw";
    } else {
        if ((resp_mode2 === 2)) {
            r_mode = 1;
            intro_btext = "Press M for acw, K for cw";
} else {
    r_mode = 2;
    intro_btext = "Bimanual";

This bit is now working! Thanks!

(I still have the error - but am working on also including @jonathan.kominsky 's suggestion - also thanks Jonathan! - hopefully together you have solved my bug.)