Class 4 — Custom Code Components
Part I
Write your own logic for the first time using a PsychoPy Code Component — dictionary-based accuracy scoring, dynamic feedback, and a trial counter that enforces the course’s minimum-observations rule.
PART I · CLASS 4
Class 3 was about reading and lightly editing Builder’s generated Python. Today you write your own logic — using a Code Component, the Builder-safe way to add custom Python that survives Builder regenerating the script. You’ll build a dictionary-based accuracy check with feedback text, then a trial counter that enforces this course’s rule of at least 5 observations per condition, and finally wire a minimal version of both into your own HW1 task.
Reading due: Think Python ch. 10–11 · Due today: —
What you’ll be able to do
- Build and index a Python dictionary, and count occurrences of a value in a list, reinforced through a Colab warm-up.
- Explain what a PsychoPy Code Component is, where its four code tabs (Before Experiment / Begin Routine / Each Frame / End Routine) run relative to a routine’s lifecycle, and why it’s the Builder-safe alternative to Class 3’s direct script edits.
- Add a code component to the shared Stroop task that scores accuracy and/or produces dynamic feedback, using a dictionary lookup rather than hard-coded per-trial logic.
- Add a running trial counter (using a dictionary or simple tally) that enforces a minimum-observations rule per condition, and explain why this course requires at least 5 observations per level for any manipulated factor.
- Connect today’s dictionary-based scoring back to Class 3’s discovery of the correct-answer conditional in the generated code — recognize that a code component is where you now write the kind of logic Builder was writing for you automatically.
- (PSY 0210 only) Write a standalone Python script — run via PsychoPy’s Coder view, not inside a Builder experiment — that validates a conditions file against the minimum-observations rule.