psychopy.org | Reference | Downloads | Github

TypeError for uppercase text input Pavlovia

URL of experiment: W. David Stahlman / Version-2 · GitLab

Description of the problem: I wrote a lot of python code to modify the text display of what participants write, and when I try piloting on pavlovia, I am getting some errors. I used a code component and set it to Auto->JS, but I’m getting the error “TypeError: keys[0].upper is not a function” I included the auto translated JS code below, does anyone know how to fix this? I have no experience with JS and therefore don’t know how to debug this.

var _pj;
function _pj_snippets(container) {
    function in_es6(left, right) {
        if (((right instanceof Array) || ((typeof right) === "string"))) {
            return (right.indexOf(left) > (- 1));
        } else {
            if (((right instanceof Map) || (right instanceof Set) || (right instanceof WeakMap) || (right instanceof WeakSet))) {
                return right.has(left);
            } else {
                return (left in right);
            }
        }
    }
    container["in_es6"] = in_es6;
    return container;
}
_pj = {};
_pj_snippets(_pj);
keys = event.getKeys();
if (keys.length) {
    if (_pj.in_es6("space", keys)) {
        input_text.text = (input_text.text + " ");
    } else {
        if (_pj.in_es6("backspace", keys)) {
            input_text.text = input_text.text.slice(0, (- 1));
        } else {
            if (_pj.in_es6("period", keys)) {
                input_text.text = (input_text.text + ".");
            } else {
                if (_pj.in_es6("comma", keys)) {
                    input_text.text = (input_text.text + ",");
                } else {
                    if (_pj.in_es6("apostrophe", keys)) {
                        input_text.text = (input_text.text + "'");
                    } else {
                        if (_pj.in_es6("question", keys)) {
                            input_text.text = (input_text.text + "?");
                        } else {
                            if (_pj.in_es6("exclamation", keys)) {
                                input_text.text = (input_text.text + "");
                            } else {
                                if (_pj.in_es6("at", keys)) {
                                    input_text.text = (input_text.text + "");
                                } else {
                                    if (_pj.in_es6("pound", keys)) {
                                        input_text.text = (input_text.text + "");
                                    } else {
                                        if (_pj.in_es6("dollar", keys)) {
                                            input_text.text = (input_text.text + "");
                                        } else {
                                            if (_pj.in_es6("percent", keys)) {
                                                input_text.text = (input_text.text + "");
                                            } else {
                                                if (_pj.in_es6("asciicircum", keys)) {
                                                    input_text.text = (input_text.text + "");
                                                } else {
                                                    if (_pj.in_es6("ampersand", keys)) {
                                                        input_text.text = (input_text.text + "");
                                                    } else {
                                                        if (_pj.in_es6("asterisk", keys)) {
                                                            input_text.text = (input_text.text + "");
                                                        } else {
                                                            if (_pj.in_es6("parenleft", keys)) {
                                                                input_text.text = (input_text.text + "");
                                                            } else {
                                                                if (_pj.in_es6("parenright", keys)) {
                                                                    input_text.text = (input_text.text + "");
                                                                } else {
                                                                    if (_pj.in_es6("underscore", keys)) {
                                                                        input_text.text = (input_text.text + "");
                                                                    } else {
                                                                        if (_pj.in_es6("minus", keys)) {
                                                                            input_text.text = (input_text.text + "");
                                                                        } else {
                                                                            if (_pj.in_es6("equal", keys)) {
                                                                                input_text.text = (input_text.text + "");
                                                                            } else {
                                                                                if (_pj.in_es6("plus", keys)) {
                                                                                    input_text.text = (input_text.text + "");
                                                                                } else {
                                                                                    if (_pj.in_es6("bracketleft", keys)) {
                                                                                        input_text.text = (input_text.text + "");
                                                                                    } else {
                                                                                        if (_pj.in_es6("bracketright", keys)) {
                                                                                            input_text.text = (input_text.text + "");
                                                                                        } else {
                                                                                            if (_pj.in_es6("braceleft", keys)) {
                                                                                                input_text.text = (input_text.text + "");
                                                                                            } else {
                                                                                                if (_pj.in_es6("braceright", keys)) {
                                                                                                    input_text.text = (input_text.text + "");
                                                                                                } else {
                                                                                                    if (_pj.in_es6("semicolon", keys)) {
                                                                                                        input_text.text = (input_text.text + ";");
                                                                                                    } else {
                                                                                                        if (_pj.in_es6("colon", keys)) {
                                                                                                            input_text.text = (input_text.text + ":");
                                                                                                        } else {
                                                                                                            if (_pj.in_es6("doublequote", keys)) {
                                                                                                                input_text.text = (input_text.text + "");
                                                                                                            } else {
                                                                                                                if (_pj.in_es6("backslash", keys)) {
                                                                                                                    input_text.text = (input_text.text + "");
                                                                                                                } else {
                                                                                                                    if (_pj.in_es6("slash", keys)) {
                                                                                                                        input_text.text = (input_text.text + "");
                                                                                                                    } else {
                                                                                                                        if (_pj.in_es6("greater", keys)) {
                                                                                                                            input_text.text = (input_text.text + "");
                                                                                                                        } else {
                                                                                                                            if (_pj.in_es6("less", keys)) {
                                                                                                                                input_text.text = (input_text.text + "");
                                                                                                                            } else {
                                                                                                                                if (_pj.in_es6("quoteleft", keys)) {
                                                                                                                                    input_text.text = (input_text.text + "");
                                                                                                                                } else {
                                                                                                                                    if (_pj.in_es6("asciitilde", keys)) {
                                                                                                                                        input_text.text = (input_text.text + "");
                                                                                                                                    } else {
                                                                                                                                        if ((_pj.in_es6("lshift", keys) || _pj.in_es6("rshift", keys))) {
                                                                                                                                            modify = true;
                                                                                                                                        } else {
                                                                                                                                            if (_pj.in_es6("return", keys)) {
                                                                                                                                                continueRoutine = false;
                                                                                                                                            } else {
                                                                                                                                                if (modify) {
                                                                                                                                                    input_text.text = (input_text.text + keys[0].upper());
                                                                                                                                                    modify = false;
                                                                                                                                                } else {
                                                                                                                                                    input_text.text = (input_text.text + keys[0]);
                                                                                                                                                }
                                                                                                                                            }
                                                                                                                                        }
                                                                                                                                    }
                                                                                                                                }
                                                                                                                            }
                                                                                                                        }
                                                                                                                    }
                                                                                                                }
                                                                                                            }
                                                                                                        }
                                                                                                    }
                                                                                                }
                                                                                            }
                                                                                        }
                                                                                    }
                                                                                }
                                                                            }
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}

.upper has to be manually translated to .toUpperCase.

Everything else should work with the auto translate.

Please see my crib sheet

thank you!