Mouse click not registering online?

URL of experiment: Pavlovia

Description of the problem:
When I run my experiment online, I get this error message:

The image file used for ‘cond2Image’ is determined by the variable, ‘actionOnset’, like so:

if actionOnset >0 and actionOnset < 0.15: #0-14
    letterClickedImage= nums0
    letterClickedTime = '0'
    if cond == 2 or cond ==4:
        dummyLetter1= nums1
        dummyLetter1Time = '0.15' 
        dummyLetter2= nums2
        dummyLetter2Time = '0.3'
        dummyLetter3= nums3
        dummyLetter3Time = '0.45'
        dummyLetter4= nums4
        dummyLetter4Time = '0.6'
elif actionOnset > 0.14 and actionOnset < 0.3: #15-29
    letterClickedImage= nums1
    letterClickedTime = '0.15'
    if cond == 2 or cond ==4:
        dummyLetter1= nums0
        dummyLetter1Time = '0'
        dummyLetter2= nums2
        dummyLetter2Time = '0.3'
        dummyLetter3= nums3
        dummyLetter3Time = '0.45'
        dummyLetter4= nums4
        dummyLetter4Time = '0.6'

and so on…
So, actionOnset is basically the time that the participant makes a mouse click during the experiment. It is determined using this code:

if cond == 1 or cond == 2:
    if checkResp == 1:
        if timer.getTime() < trialEnd:
            if mouse.getPressed()[0]==1:
                actionOnset = timer.getTime()
                toneOnset = actionOnset + 0.25
        elif timer.getTime() > trialEnd:
            continueRoutine = False   
    elif tonePlayed>0 and (t>(tonePlayed+trialEndGap)):
        continueRoutine = False

However, the error message suggests that actionOnset remains null (it’s set to null at the beginning of the routine) and hence, a mouse click is never registered.

What is going on here? How do I fix this?

Thank you!

Please could you show code/components more closely linked to the error message? How do you get from actionOnset to the image file name? Have you tried logging the value?

I had a quick look at your JS code and you seem to be converting strings extracted from a list to string, which seems odd – but could be just a JS quirk.

Hi, thank you for your reply!

Depending on the time assigned to actionOnset, letterClickedImage is set to a particular variable, such as nums0.
The image files names are assigned to these variables (like nums0) using this code in the begin routine tab:

nums = [["images/letters/zero.jpeg"], ["images/letters/one.jpeg"], ["images/letters/two.jpeg"], ["images/letters/three.jpeg"], ["images/letters/four.jpeg"], ["images/letters/five.jpeg"], ["images/letters/six.jpeg"], ["images/letters/seven.jpeg"], ["images/letters/eight.jpeg"], ["images/letters/nine.jpeg"]];
nums0 = nums[0].toString();
nums1 = nums[1].toString();
nums2 = nums[2].toString();
nums3 = nums[3].toString();
nums4 = nums[4].toString();
nums5 = nums[5].toString();
nums6 = nums[6].toString();
nums7 = nums[7].toString();
nums8 = nums[8].toString();
nums9 = nums[9].toString();
letters1 = [["images/letters/D.jpeg"], ["images/letters/M.jpeg"], ["images/letters/P.jpeg"], ["images/letters/X.jpeg"], ["images/letters/V.jpeg"], ["images/letters/S.jpeg"], ["images/letters/Q.jpeg"], ["images/letters/T.jpeg"], ["images/letters/B.jpeg"], ["images/letters/C.jpeg"], ["images/letters/F.jpeg"], ["images/letters/G.jpeg"], ["images/letters/H.jpeg"], ["images/letters/J.jpeg"], ["images/letters/K.jpeg"], ["images/letters/L.jpeg"], ["images/letters/N.jpeg"], ["images/letters/R.jpeg"], ["images/letters/W.jpeg"], ["images/letters/Y.jpeg"], ["images/letters/Z.jpeg"]];
letters1L0 = letters1[0].toString();
letters1L1 = letters1[1].toString();
letters1L2 = letters1[2].toString();
letters1L3 = letters1[3].toString();
letters1L4 = letters1[4].toString();
letters1L5 = letters1[5].toString();
letters1L6 = letters1[6].toString();
letters1L7 = letters1[7].toString();
letters1L8 = letters1[8].toString();
letters1L9 = letters1[9].toString();
letters1L10 = letters1[10].toString();
letters1L11 = letters1[11].toString();
letters1L12 = letters1[12].toString();
letters1L13 = letters1[13].toString();
letters1L14 = letters1[14].toString();
letters1L15 = letters1[15].toString();
letters1L16 = letters1[16].toString();
letters1L17 = letters1[17].toString();
letters1L18 = letters1[18].toString();
letters1L19 = letters1[19].toString();
letters1L20 = letters1[20].toString();

I am converting strings extracted from a list to back to strings. I think this is a JS quirk, as before, I didn’t have .toString() and I got an error message saying that it couldn’t find images/letters/one.jpeg , etc with no quotation marks, so it appeared to not be reading them as strings.

If it can’t find the image that doesn’t sound like it has a problem with the string – that would give a Type Error.

Are your images in html/resources/images/letters?

Yes, they are all there in the html/resources/images/letters folder. I think the issue isn’t that it can’t find the image, I think that an image is never assigned to cond2Image, though I’m unsure why that is happening.

I think I may have the answer.

I just looked at your JS code and you are defining cond2Image twice (lines 1610 and 2755).

Thank you for your reply!

I changed the code so that cond2Image is only defined once, but sadly, the error message is still there.

Ah, I was mistaken. So I am still using cond2Image twice, but this is because I use the ‘response’ routine twice. Once during the practice trials and once during the real trials. Would making a new response routine for the practice trials fix the issue?

Using the same routine in two locations in the flow is good practice. Creating two similar routines with identical code components which create objects is not.

Ah, okay, so what I was doing already was right. I wonder what was causing the error message?

I’ve just downloaded your psyexp file and I can’t find the code setting $letterClickedImage

Which routine is it in?

You also have an awful lot of cond=cond, etc. which is unnecessary.

letterClickedImage is first defined in the practTrial routine, in code_17 component (begin experiment tab). It’s set to None here. It’s then given a new value in code_18 on the same routine in the each frame tab.
The letterClickedImage is also used in the trial routine for the same purpose.

Then in the response routine, the image files used in cond2Image and cond4Image are set using letterClickedImage

I would replace letterClickedImage=letterClickedImage with print(letterClickedImage) in the endRoutine of code_18 and then check the console. The Each Frame of code_18 is way too long for me to check, and I think is based on a misapprehension. You should be dealing with this is a loop, but I’m also wondering whether you are setting values afresh every Frame.

Thank you for your help. I added print(letterClickedImage) as suggested. The image seems to be being set as intended. But this is offline, where things were working fine. I’ll try online - will things print to the developer console?

Ah, okay so online, it looks like the letterClickedImage variable isn’t being set with an image file name.