| Reference | Downloads | Github

TextStim' object is not callable

If this template helps then use it. If not then just delete and start from scratch.

OS Win7:
PsychoPy version 1.90.1:
**Standard Standalone? yes:
What are you trying to achieve?:
Produce an outcome that results in ‘20’ in 5% of trials, and ‘0’ in 95% of trials as a text stimulus.

What did you try to make it work?:
I tried to make as it’s suggested here in “Indivisibility” chapter.

  import random
  propRare = 0.05
  propCommon = 1-propRare
  numTrials = 40
  points = ['0']*int(round(numTrials*propCommon)) + \
  pointswon = points[1]

What specifically went wrong when you tried that?:
I get this error:

points = ['0']*int(round(numTrials*propCommon)) + \

TypeError: ‘TextStim’ object is not callable

I ran this code in Jetbrains and it works fine, but not in PsychoPy. What am I missing here?

  1. The error is not in the highlighted code, which does what is expected (although you could drop the \ line continuation character perhaps).
    The error is pointing to a TextStim object, which does not exist in the code you provided. You should list the entire text of the error message.
  2. You don’t need to import random as Builder imports various random functions from the numpy.random library. In particular, it imports numpy's shuffle() function directly, so you can just type shuffle(points), rather than random.shuffle(points), and then you’ll be consistent with Builder in using numpy rather than the Python standard library’s randomisation functions.

Thank you for your reply, Michael!

The code that I use:

propRare = 0.05
propCommon = 1-propRare
numTrials = 40

points = ['0']*int(round(numTrials*propCommon)) + ['20']*int(round(numTrials*propRare))


if key_resp_4.keys == 'left':
        hpos = [-0.5,0]
        unchosen_door= doorList[13]
        unchosenpos = [0.5, 0]
        pointswon = points[1] #"%.0f" %points
        DoorChosen = 'Risky'

elif key_resp_4.keys == 'right':
        hpos = [0.5,0]
        unchosen_door = doorList[12]
        unchosenpos = [-0.5, 0]
        pointswon = 1
        DoorChosen = 'Safe'

I use ‘pointswon’ as a text stimulus (feedback) in the same routine:

And this is the whole error message I get:

I tried to move the code to the previous routine as I thought it’s a timing problem, but it didn’t help.

pointswon isn’t a textstim, it should be just a character string, like '1'. The only textstim you’ve shown is called text_5.

I’m a bit mystified by this. Perhaps you should post your .psyexp file so we can check the generated code.

Sorry for the delay in my response…

I still haven’t figured out what causing this issue. Here is my builder code file:
Exp_2_DfSE_observes_first.psyexp (344.9 KB)

I have many loops that represent different lotteries - it’s a dumb way I could come up with to get randomisation right. I get error from the loop “lot2” in “code_9” (I set the random seed so I start from this loop).

The code that includes TextStim of the stimulus from the coder view:

text_5 = visual.TextStim(win=win, name='text_5',
    text='default text',
    pos=[0,0], height=0.3, wrapWidth=None, ori=0, 
    color='black', colorSpace='rgb', opacity=1,