psychopy.org | Reference | Downloads | Github

Anchoring experiment won't run on pavlovia

Hello,

I am trying to run an anchoring experiment on pavlovia. While it runs in offline mode, it chrashes on pavolvia.

URL of experiment: https://run.pavlovia.org/jens.boelte/ankereffekt/html (still in piloting mode)

Description of the problem:
The experiment stops with an error message when a participant has to hit the left or right cursor key as a response to a question. An error message pops up saying that a TypeError occurred: event undefinded. See screenshot.

Zwischenablage01

I have no idea what causes the error given that the program runs offline without problems.

Suggestions?

Best wishes Jens

Hi Jen,

You probably need to define event as event=psychoJS.eventManager; in code_JS.

Have a look at my crib sheet (see pinned post) for more details.

Best wishes,

Wakefield

Hello wakecater

that solved the problem.

Cheers Jens

Any idea how to resolve the following error?

Zwischenablage01

I guess I have to define a function at the experiment beginning. But I do not know JS.

Cheers Jens

If you look at my Brookes Template experiment you’ll see that I just used a separate line for each possible digit in my Age question.

Hello,

ok, this help somewhat. I am able to enter digits. However, the experiment runs only one trial. But I don’t get any further. On the second trial, when I am about to enter a digit, an error message pops up. The answer I typed in (“65”) is displayed in the error message below. So I guess I have to clear my answer it but I found no way and place to clear it.

Zwischenablage01

Cheers Jens

At the beginning of the routine you could set your variables to [] (empty list) or 0.

Hello,

good tip. I tried clearing all variables at routine start but it did not work. The error message I get when running offline is

AnkerEffekt_lastrun.py, line 743, in
thisComponent.tStart = None
AttributeError: ‘str’ object has no attribute ‘tStart’
#####Experiment ended.#####

        SchaetzTrialComponents = [InstSchaetz, SchaetzFrage, Antwort]
        for thisComponent in SchaetzTrialComponents:
            thisComponent.tStart = None
            thisComponent.tStop = None
            thisComponent.tStartRefresh = None
            thisComponent.tStopRefresh = None
            if hasattr(thisComponent, 'status'):
                thisComponent.status = NOT_STARTED
        # reset timers

line 743 is thisComponent.tStop = None

I strongly assume that both error message ar related.

Never thought that it is so “difficult” to get typed input :wink:

Cheers Jens

Hello,

I am a step further in getting typed input online (and offline). The experiment now runs on Pavlovia but to make it really nice it need to record three more keys, the minus-key on the keyboard, the subtract on the numpad and the enter-key on the numpad, online which I can register offline. I assume that I am using the wrong names for the keys (and/or keycodes).

keys = event.getKeys()

if len(keys):
    if 'backspace' in keys:
        text.text = text.text[:-1]
    elif 'return' in keys or 'num_enter' in keys and len(text.text >= 1):
        continueRoutine = False
    elif 'minus' in keys or '-' in keys or 'NumpadSubtract' in keys or 'Minus' in keys:
        text.text = text.text+'-'
    elif '1' in keys or 'num_1' in keys:
        text.text = text.text+'1'
    elif '2' in keys or 'num_2' in keys:
        text.text = text.text+'2'
    elif '3' in keys or 'num_3' in keys:
        text.text = text.text+'3'
    elif '4' in keys or 'num_4' in keys:
        text.text = text.text+'4'
    elif '5' in keys or 'num_5' in keys:
        text.text = text.text+'5'
    elif '6' in keys or 'num_6' in keys:
        text.text = text.text+'6'
    elif '7' in keys or 'num_7' in keys:
        text.text = text.text+'7'
    elif '8' in keys or 'num_8' in keys:
        text.text = text.text+'8'
    elif '9' in keys or 'num_9' in keys:
        text.text = text.text+'9'
    elif '0' in keys or 'num_0' in keys:
        text.text = text.text+'0'

Suggestions are welcome.

Cheers Jens

Hello,

I found the problem. First some key-names were wrong. Using a German keyboard it is slash and not minus for the keybod-minus. In addition, the elif-condition ending the routine had an error. So here is the code that finally worked online and offline.

keys = event.getKeys()

if len(keys):
    if 'backspace' in keys:
        text.text = text.text[:-1]
    elif ('return' in keys or 'num_enter' in keys) and text.text != '':
        continueRoutine = False
    elif 'minus' in keys or '-' in keys or 'num_subtract' in keys or 'Minus' in keys or 'slash' in keys:
        text.text = text.text+'-'
    elif '1' in keys or 'num_1' in keys:
        text.text = text.text+'1'
    elif '2' in keys or 'num_2' in keys:
        text.text = text.text+'2'
    elif '3' in keys or 'num_3' in keys:
        text.text = text.text+'3'
    elif '4' in keys or 'num_4' in keys:
        text.text = text.text+'4'
    elif '5' in keys or 'num_5' in keys:
        text.text = text.text+'5'
    elif '6' in keys or 'num_6' in keys:
        text.text = text.text+'6'
    elif '7' in keys or 'num_7' in keys:
        text.text = text.text+'7'
    elif '8' in keys or 'num_8' in keys:
        text.text = text.text+'8'
    elif '9' in keys or 'num_9' in keys:
        text.text = text.text+'9'
    elif '0' in keys or 'num_0' in keys:
        text.text = text.text+'0'

Cheers Jens

1 Like