Tuples inconsistently misbehaving

Hello!

I have a patch I’ve written (which I’ll post the scripting of in a second) which, if you dial knob 4 up to max, cycles through the colours of the rainbow in increments that are scaled by the position of knob 2.

The patch is designed to run the colour change each time audio_trig is true (I’m linking this up to midi clock)

NORMALLY the patch runs completely fine, but if I leave it running for a while it hits an error:

error with draw: Traceback (most recent call last):
File “main.py”, line 195, in
mode.draw(screen, etc)
File “/sdcard/Modes/Python/T - Dancing Man//main.py”, line 193, in draw
colourthisburst[2] += (0 - colourincrement)
TypeError: ‘tuple’ object does not support item assignment

(more below - just gonna paste my script in next so if you have the inclination you could run it on your eyesy and see what it’s doing :slight_smile: )

import os
import pygame
import time
import random
import math

def setup(screen, etc):
    global xr,yr, xr2,yr2,manparts,burstmultiplier,colourthisburst, pose, xoffset, yoffset, flipyn, colourshiftdirection
    xr = etc.xres
    yr = etc.yres
    yr2 = yr*0.5
    xr2 = xr*0.5
    pose = 1
    flipyn = random.choice([-1,1])
    xoffset = 0
    yoffset = 0
    colourthisburst = [255,0,255]
    colourshiftdirection = 'pink to red'
    manparts =  [
                [[0,-0.50,0.05], 
                [0,-0.31,0.03],
                [0,-0.23,0.03],
                [0,-0.15,0.03],
                [0.15,-0.3,0.02],
                [0.175,-0.275,0.02],
                [0.2,-0.25,0.02],
                [0.25,-0.2,0.02],
                [-0.15,-0.3,0.02],
                [-0.175,-0.275,0.02],
                [-0.2,-0.25,0.02],
                [-0.25,-0.2,0.02],
                [0.05,0.05,0.02],
                [0.06,0.13,0.02],
                [0.07,0.21,0.02],
                [0.08,0.29,0.02],
                [-0.05,0.05,0.02],
                [-0.06,0.13,0.02],
                [-0.07,0.21,0.02],
                [-0.08,0.29,0.02]
                ],
                
                [[-0.09,-0.40,0.05], 
                [0.025,-0.26,0.03],
                [0.075,-0.20,0.03],
                [0.095,-0.16,0.03],
                [0.085,-0.445,0.02],
                [0.095,-0.49,0.02],
                [0.105,-0.535,0.02],
                [0.105,-0.62,0.02],
                [-0.05,-0.13,0.02],
                [-0.06,-0.08,0.02],
                [-0.07,-0.03,0.02],
                [-0.11,0.03,0.02],
                [0.25,-0.1,0.02],
                [0.325,-0.15,0.02],
                [0.375,-0.05,0.02],
                [0.4,0.025,0.02],
                [0.15,0.02,0.02],
                [0.19,0.1,0.02],
                [0.14,0.22,0.02],
                [0.1,0.29,0.02]
                ],
                
                [[0.3,0.29,0.05], 
                [0.16,0.32,0.03],
                [0.1,0.28,0.03],
                [0.06,0.20,0.03],
                [0.12,0.45,0.02],
                [0.09,0.48,0.02],
                [0.06,0.51,0.02],
                [0,0.57,0.02],
                [0.25,0.12,0.02],
                [0.27,0.1,0.02],
                [0.29,0.08,0.02],
                [0.35,0.12,0.02],
                [0,0.005,0.02],
                [0.0,-0.09,0.02],
                [0,-0.180,0.02],
                [0,-0.27,0.02],
                [-0.05,0.15,0.02],
                [-0.1,0.10,0.02],
                [-0.13,0.23,0.02],
                [-0.15,0.31,0.02]
                ],
                
                [[0,-0.50,0.05], 
                [0,-0.31,0.03],
                [0,-0.23,0.03],
                [0,-0.15,0.03],
                [0.04,-0.64,0.02],
                [-0.0,-0.64,0.02],
                [-0.04,-0.64,0.02],
                [-0.1,-0.57,0.02],
                [-0.13,-0.31,0.02],
                [-0.17,-0.31,0.02],
                [-0.21,-0.31,0.02],
                [-0.27,-0.37,0.02],
                [0.09,-0.07,0.02],
                [0.15,-0.03,0.02],
                [0.12,0.06,0.02],
                [0.06,0.09,0.02],
                [-0.02,0.05,0.02],
                [-0.02,0.13,0.02],
                [-0.02,0.21,0.02],
                [-0.02,0.29,0.02]
                ],
                
                [[0,-0.50,0.05], 
                [0,-0.31,0.03],
                [0,-0.23,0.03],
                [0,-0.15,0.03],
                [0.13,-0.5,0.02],
                [0.13,-0.55,0.02],
                [0.13,-0.6,0.02],
                [0.15,-0.68,0.02],
                [-0.13,-0.23,0.02],
                [-0.13,-0.18,0.02],
                [-0.13,-0.13,0.02],
                [-0.15,-0.05,0.02],
                [0.11,-0.08,0.02],
                [0.175,-0.08,0.02],
                [0.22,-0.0,0.02],
                [0.22,0.085,0.02],
                [-0.02,0.05,0.02],
                [-0.02,0.13,0.02],
                [-0.02,0.21,0.02],
                [-0.02,0.29,0.02]
                ],
                
                [[0,-0.50,0.05], 
                [0,-0.31,0.03],
                [0,-0.23,0.03],
                [0,-0.15,0.03],
                [0.15,-0.3,0.02],
                [0.19,-0.3,0.02],
                [0.23,-0.3,0.02],
                [0.3,-0.3,0.02],
                [-0.15,-0.45,0.02],
                [-0.15,-0.5,0.02],
                [-0.15,-0.55,0.02],
                [-0.15,-0.63,0.02],
                [0.12,-0.09,0.02],
                [0.18,-0.04,0.02],
                [0.11,0.02,0.02],
                [0.05,0.07,0.02],
                [-0.1,-0.05,0.02],
                [-0.16,-0.01,0.02],
                [-0.22,0.03,0.02],
                [-0.28,0.07,0.02]
                ],

                [[0,-0.50,0.05], 
                [0,-0.31,0.03],
                [-0.02,-0.23,0.03],
                [-0.06,-0.15,0.03],
                [0.12,-0.4,0.02],
                [0.135,-0.45,0.02],
                [0.145,-0.5,0.02],
                [0.18,-0.562,0.02],
                [-0.12,-0.4,0.02],
                [-0.135,-0.45,0.02],
                [-0.145,-0.5,0.02],
                [-0.18,-0.562,0.02],
                [0.03,0.02,0.02],
                [0.07,0.09,0.02],
                [0.07,0.18,0.02],
                [0.07,0.26,0.02],
                [-0.14,0.02,0.02],
                [-0.14,0.10,0.02],
                [-0.14,0.18,0.02],
                [-0.14,0.26,0.02]
                ]
                
                ]
    burstmultiplier = 1


def draw(screen, etc):
    global burstmultiplier, colourthisburst, pose, xoffset, yoffset, flipyn, colourshiftdirection
    if etc.audio_trig == True:
        burstmultiplier = 1
        
        collowmin = 0
        collowmax = 50
        colhighmin = 195
        colhighmax = 255
        
        flipyn = random.choice([-1,1])
        
        if etc.knob2 > 0:
            colourincrement = 85 * etc.knob2
        else:
            colourincrement = 85 * 0.01
        
        if colourshiftdirection == 'pink to red' and (colourthisburst[2] - colourincrement) > 0:
            colourthisburst[2] += (0 - colourincrement)
        elif colourshiftdirection == 'pink to red' and (colourthisburst[2] - colourincrement) <= 0:
            colourthisburst[2] = 0
            colourshiftdirection = 'red to yellow'
            
        elif colourshiftdirection == 'red to yellow' and (colourthisburst[1] + colourincrement) < 255:
            colourthisburst[1] += colourincrement
        elif colourshiftdirection == 'red to yellow' and (colourthisburst[1] + colourincrement) >= 255:
            colourthisburst[1] = 255
            colourshiftdirection = 'yellow to green'
        
        elif colourshiftdirection == 'yellow to green' and (colourthisburst[0] - colourincrement) > 0:
            colourthisburst[0] += (0 - colourincrement)
        elif colourshiftdirection == 'yellow to green' and (colourthisburst[0] - colourincrement) <= 0:
            colourthisburst[0] = 0
            colourshiftdirection = 'green to light blue'
        
        elif colourshiftdirection == 'green to light blue' and (colourthisburst[2] + colourincrement) < 255:
            colourthisburst[2] += colourincrement
        elif colourshiftdirection == 'green to light blue' and (colourthisburst[2] + colourincrement) >= 255:
            colourthisburst[2] = 255
            colourshiftdirection = 'light blue to blue'

        elif colourshiftdirection == 'light blue to blue' and (colourthisburst[1] - colourincrement) > 0:
            colourthisburst[1] += (0 - colourincrement)
        elif colourshiftdirection == 'light blue to blue' and (colourthisburst[1] - colourincrement) <= 0:
            colourthisburst[1] = 0
            colourshiftdirection = 'blue to pink'
            
        elif colourshiftdirection == 'blue to pink' and (colourthisburst[0] + colourincrement) < 255:
            colourthisburst[0] += colourincrement
        elif colourshiftdirection == 'blue to pink' and (colourthisburst[0] + colourincrement) >= 255:
            colourthisburst[0] = 255
            colourshiftdirection = 'pink to red'
        
        pose = random.randint(0,(len(manparts))-1)
        xoffset = int(etc.knob3 * (random.randint(int(0-(xr2/1.2)),int(xr2/1.2))))
        yoffset = int(etc.knob3 * (random.randint(int(0-(yr2/1.2)),int(yr2/1.2))))
        
        #pose = 6
        #flipyn = 1
        #xoffset = 0
        #yoffset = 0
        
    else:
        burstmultiplier = burstmultiplier * (1 + (etc.knob1*0.19))
    
    if etc.knob4 < 1:
        colourthisburst = etc.color_picker(etc.knob4)
    
    etc.color_picker_bg(etc.knob5)
    for i in range (0,len(manparts[pose])):
        xloc = xoffset + (int((xr2+flipyn*((xr2*manparts[pose][i][0])*(burstmultiplier)))))
        yloc = yoffset + int((yr2+(yr2*manparts[pose][i][1])*(burstmultiplier)))
        csize = int(manparts[pose][i][2]*yr)
        pygame.draw.circle(screen,colourthisburst,(xloc,yloc),csize,0)
    
    #font = pygame.font.SysFont(None, 24)
    #img = font.render(str(xloc), True, [255,255,255])
    #screen.blit(img, (20, 20))

Now it’s not always the same line where it complains, so I know it’s not specifically that one instance.

BUT it IS always in one of the places where I assign a value to one of the positions of colourthisburst

I don’t know how to properly debug this and find out what’s going on… I don’t know why the patch is able to run for a while without hitting this bug… If it was incorrect syntax I’d’ve thought it’d NEVER be able to run?

I thought at first it was to do with changing the position of the knobs (or even the speed of the incoming clock) that tipped it up, but I can’t make it happen on purpose in those ways.

Please let me know if you can see where I’ve blundered in the above script! Or if you have good ways to debug when writing patches for the eyesy!

Just for context, this is my first ever piece of python scripting so I am learning the language at the same time as the eyesy - so it’s really possible that I’ve made an obvious basic error and have no idea what I should even be looking for!

Thank you!

Not sure if this would be helpful:

Thanks!

I hadn’t understood the difference between lists and tuples! Maybe I’ve got something that is setting it’s type wrong somewhere! I’ll have a rummage!

Annoyingly I couldn’t spot anywhere where I was treating the list like a tuple and getting it confused…

Anyone else ever experiences the eyesy spontaneously changing a list to a tuple?