Repository: psychopy/psychopy

Issue:
Failure to convert nDots (of Dots component) and texRes (of Noise component) into integer
Psychopy (at least version 2021.1.2 and 2021.1.4) for Noise auto-translates the texRes parameter, which is written as “128” in the Builder parameters, into “128.0”, and for Dots auto-translates the “100” nDots as “100.0”. But texRes and nDots must be integers, so this creates an error. People seem to have also reported this here 1 and here 1 (without identifying the underlying problem). For an example, see test.psyexp [here](https://discourse.psychopy.org/t/psychopy-builder-erroneously-codes-texres-as-a-float-instead-of-an-integer/22802).

Somehow the magic that is the PsychoPy Builder → Python code generation previously seems to have known that the texRes parameter should be an integer, but no longer knows that.

While we wait for a fix, people with this problem can fix it manually by going to the auto-generated Python code and removing the decimal point from nDots or texRes.

Note that the Builder’s Noise demo works, even though creating a psyexp with Noise from scratch does not. I don't know enough about PsychoPy Builder to be confident about the implications of this fact. 


Discussion:
Thanks @alexholcombe 
We did some refactoring of params in 2021.1 to to make for more flexible inputs in the dialogs. The logic being that if a parameter knows what type of entry to expect then it can offer better options to the user (like browse buttons, number spinners etc) but that refactoring has produced some rough edges. They're relatively easy fixes once we know though so thanks for reporting

Resolving patch:
diff --git a/psychopy/app/builder/dialogs/paramCtrls.py b/psychopy/app/builder/dialogs/paramCtrls.py
--- a/psychopy/app/builder/dialogs/paramCtrls.py
+++ b/psychopy/app/builder/dialogs/paramCtrls.py
@@ -459,7 +459,7 @@ def validate(obj, valType):
         # For now, ignore
         pass
     # Validate num
-    if valType == "num":
+    if valType in ["num", "int"]:
         try:
             # Try to convert value to a float
             float(val)
diff --git a/psychopy/experiment/components/dots/__init__.py b/psychopy/experiment/components/dots/__init__.py
--- a/psychopy/experiment/components/dots/__init__.py
+++ b/psychopy/experiment/components/dots/__init__.py
@@ -69,7 +69,7 @@ def __init__(self, exp, parentName, name='dots',
         msg = _translate("Number of dots in the field (for circular fields"
                          " this will be average number of dots)")
         self.params['nDots'] = Param(
-            nDots, valType='num', inputType="spin", categ='Dots',
+            nDots, valType='int', inputType="spin", categ='Dots',
             updates='constant',
             hint=msg,
             label=_localized['nDots'])
diff --git a/psychopy/experiment/components/noise/__init__.py b/psychopy/experiment/components/noise/__init__.py
--- a/psychopy/experiment/components/noise/__init__.py
+++ b/psychopy/experiment/components/noise/__init__.py
@@ -136,7 +136,7 @@ def __init__(self, exp, parentName, name='noise', noiseImage='None',
             "etc. For most cases a value of 256 pixels will suffice")
         self.params['texture resolution'] = Param(
             texRes, categ='Texture',
-            valType='num', inputType="single", allowedVals=['32', '64', '128', '256', '512','1024'],
+            valType='int', inputType="single", allowedVals=['32', '64', '128', '256', '512','1024'],
             updates='constant', allowedUpdates=[],
             hint=msg,
             label=_localized['texture resolution'])


Test patch: