| Reference | Downloads | Github

ReferenceError: num_items is not defined

URL of experiment:
Description of the problem:
Hello, after uploading an experiment to Pavlovia I have got ReferenceError: num_items is not defined.

As I understand from other topics, the problem is that I only wrote a Pyton code.

Begin Experiment part

import random, xlrd


in_file = “stimuli_1.xlsx”

num_items = 10

cur_image1 = 0
cur_image2 = 0
cur_image3 = 0

Begin Routine part

inbook = xlrd.open_workbook(in_file)
insheet = inbook.sheet_by_index(0)

image1_stim =
image2_stim =
image3_stim =

for rowx in range (1, num_items + 1):

row = insheet.row_values(rowx)



End Routine part

thisExp.addData(“image1_stim”, image1_stim[cur_image1])
thisExp.addData(“image2_stim”, image2_stim[cur_image2])
thisExp.addData(“image3_stim”, image3_stim[cur_image3])

cur_image1 = cur_image1 + 1
cur_image2 = cur_image2 + 1
cur_image3 = cur_image3 + 1

And if I want to run this experiment online I need to write
a similar code in Java?
Thank you, Roman.

  • Yes, but the language you need is JavaScript, not Java (one of the most confusing naming decisions in the history of programming…))
  • Just select “both” as the code type in your code component so you can see the original Python code to translate into JavaScript in the other pane.