OS (e.g. Win10): MacOs 11.2.2 PsychoPy version (e.g. 1.84.x): 2021.1.2 Standard Standalone? (y/n) If not then what?: y
Hi,
I have several text component in which the Letter height is set to a variable, TextHeight, at every repeat.
In some of them, but not systematically the code inserts a call to asarray
Yep. tried both, to no avail. Very irritating, specially given that I think it did not happen earlier today. Cant understand what could have caused it.
I think i tried with 2021.1.3 at some point also, no success.
Out of despair, I added a python function definition in a code block before experiment, as you proposed for the javascript version :
def asarray(something):
return(something)
and it works for me. So definitely these calls to asarray() seem to serve no use.
asarray is added when the value of the input box can’t be easily converted to a float, for example if it’s a variable name rather than a constant. The reason we do this is to make sure that the input is capable of matrix calculations - for example, if you gave a list of values and the component needed to multiply each by something.
I think what’s probably happening is that asarray is added because the variable name itself isn’t a number, but because of this it isn’t converted to a float within the array, so the array ends up being array('1') rather than array(1), hence the error. If your variable is just one value at a time, you could set the value to float(textHeight), which will compile as asarray(float(textHeight)) and give you an array with one numeric value, as intended.
I tried entering float(textHeight) as advised (if I got it right), and it does not solve the problem.
Also, unclear why asarray is added at compilation in some places but not in other.
For info, here is the error Traceback
Traceback (most recent call last):
File "/Users/ac/Documents/LetterWidth/Script/WidthEstimation_V3_lastrun.py", line 529, in <module>
Hello.setHeight(asarray(float(textHeight)))
File "/Applications/PsychoPy/PsychoPy2021.1.2.app/Contents/Resources/lib/python3.6/psychopy/visual/text.py", line 270, in setHeight
setAttribute(self, 'height', height, log)
File "/Applications/PsychoPy/PsychoPy2021.1.2.app/Contents/Resources/lib/python3.6/psychopy/tools/attributetools.py", line 141, in setAttribute
setattr(self, attrib, value)
File "/Applications/PsychoPy/PsychoPy2021.1.2.app/Contents/Resources/lib/python3.6/psychopy/tools/attributetools.py", line 35, in __set__
value=value)
File "/Applications/PsychoPy/PsychoPy2021.1.2.app/Contents/Resources/lib/python3.6/psychopy/tools/attributetools.py", line 160, in logAttrib
and (value.ndim > 2 or len(value) > 2):
TypeError: len() of unsized object
Ah, giving us that error traceback makes a huge difference - Todd and Wakefield were assuming (naturally) you had a different bug to the one you’ve got but we can look into this different one.