Cabbage Logo
Back to Cabbage Site

Strange trigger output behavior cabbageGetValue

Hey all,

I’m trying to figure out why exactly I’m seeing this behavior. Basically I am trying to monitor when a widget value changes. I’m unable to use cabbageChanged because my array changes size, has many empty slots and it seems if you pass in an array containing blank/empty strings to cabbageChanged there is a memory leak that occurs, as I notice my memory consumption steadily ticking upwards

So, I’m trying to simply loop through and utilize the optional ktrig output from cabbageGetValue. However, for some reason after a single modification to the widget the kTrig output returned by cabbageGetValue never seems to reset, and the triggered index and the index after return a positive trigger value. So if I modify widget at index 2, after that modification cabbageGetValue is returning a positive value for its trigger output for index 2 and 3.

Here’s my code:

kIndex = 0
kValue = 0
while kIndex < gkVSliderLastIndex do
        kTrig = 0
        kValue, kTrig cabbageGetValue gSVActiveSliders[kIndex]
        if kTrig == 1 then          
            printk2 kIndex
        endif
        kIndex = kIndex + 1
od

I’ve ensured that the proper channel values are being to the cabbageGetValue call

This isn’t going to work because cabbageGetValue has internal state. So it will end up comparing the newest value with the last value from the previous channel. This is why I added the array variation, but you’re right about it not being that useful if you are changing array sizes, although the leak sounds like a bug. How many channels are you looking to monitor?

Ahhh okay, that explains why I’m getting some strange behavior

I’m looking to monitor between 8-50. Max may be somewhere around 150 but currently the most in a single array has been about 50. However I’m monitoring changes for a few different arrays with different types of widgets, but realistically maximum I’m looking at polling 120-150 widgets.

For my reference, could you provide a link to the source for that opcode? I figure I may as well to start familiarizing myself with the source as I foresee myself using Cabbage quite a bit. May as well start opening the door to the possibility of contributing once I wrap my head around it.

One other question I had, if I am polling for a change in value from a widget in one part of the code and then forcibly set the value of a widget in another, would the portion of the code that is awaiting a change get triggered or does manually setting a widgets value not set its internal state in the same way as modifying the widget via UI does?

You can find source to all the opcodes included in Cabbage here:
https://github.com/rorywalsh/cabbage/tree/develop/Source/Opcodes
:+1:

If you’re monitoring a widget for a change, then setting it manually will still trigger the change. So you might end up in an kind of recursive mess.

Ahh okay, so probably need a global state variable of some sort to prevent this