Changing rgbPicker color from code?

Is there a way to change the color in a rgbPicker from code? Running it manually from another function works in that it runs the code in the picker, but it doesn’t update the color of the picker. I’m working on a light dome where I can override the default color of certain spokes, and I want to be able to make the changed one snap back to the original color on command. I’ve figured out the logic, but it would be a lot cleaner if I could override the color picker color correctly from code.

A follow-on question here is “when is the code in a color picker actually run?”, because the answer is definitely not “only when you interact with the color picker”. For example, if I have two color pickers, and I use the second one to pick a new color, it runs the code in the first one even though I’m not interacting with that color picker at the moment. So I think the answer is “every time you use a color picker to pick a new color, the all the color pickers are called, but you can’t usually tell because their colors don’t change.” If that’s not how it’s supposed to work, then maybe I found a bug.

Here’s a repro case:

// It seems like *every* color picker is run every time someone interacts with *any* color picker.

export var pixelR = array(pixelCount)
export var pixelG = array(pixelCount)
export var pixelB = array(pixelCount)

// Both color pickers are run when *either one* is clicked.
// Whichever one is second in the source code is the last to write pixel 5
// no matter which one the user interacts with. I.E. both color pickers are run
// every time any of them is interacted with. I'd prefer that not to be true at all
// but if this is by design and not a bug, then please document it and any other 
// interface elements that deviate from the expected "it only runs when I interact with it"
// behavior. :)

export function rgbPickerA(r,g,b) // Left and middle pixel
{                                 
  pixelR[0]=r
  pixelG[0]=g
  pixelB[0]=b
  
  pixelR[5]=r
  pixelG[5]=g
  pixelB[5]=b
}
export function rgbPickerB(r,g,b) // Right and middle pixel
{
  pixelR[10]=r
  pixelG[10]=g
  pixelB[10]=b

  pixelR[5]=r
  pixelG[5]=g
  pixelB[5]=b
}

export function render(index) {
 rgb(pixelR[index],pixelG[index],pixelB[index])
}

This is a known behavior. I’ve linked the original discussion thread below. What I usually do to work around it is, use additional variables to track the values passed in to the UI functions, set flags when they change, then test and clear these flags at beforeRender time.

1 Like

@zranger1 Thanks for the info and the link to the other post. That info is very useful and helped me understand how the system works.

However, I still don’t have an answer to the question “how do I set the color of a color picker from code?” I have a picker on the screen, it’s been selected to yellow. I want to change both the appearance of that color and the underlying value from code, i.e. not by interacting with the interface in a web browser.

As far as I know, you can’t set the saved/displayed value of any control from pattern code right now. I wish you could. It’d be a useful improvement, and maybe we’ll see it in a future version.

There’s some discussion about controls, and issues around saving/restoring persistent variables from patterns in general here:

1 Like