Some c++ help for the noob please

if some one could set me straight on how to turn this into an array id much appreciate it trying hard to change over from xojo to juice + C++

// So i want to have 10 buttons and send them to my function setMchan() when clicked
i tried to make a for loop and just ended up with errors on each attempt i could not work out how to clear them

// my plugineditor.h under private:
TextButton chanButton01{“Ch01”};

//my plugineditor.cpp under TutorialPluginAudioProcessorEditor::TutorialPluginAudioProcessorEditor (TutorialPluginAudioProcessor& p)
: AudioProcessorEditor (&p), processor §

chanButton01.onClick =&{processor.setMchan();};
addAndMakeVisible(chanButton01);

// and my function in pluginprocessor.cpp – here i wasnt sure how to read which button was pressed …

void** TutorialPluginAudioProcessor::setMchan( )
{
// detect which button was pushed here
}

// really appreciate some help if possible its hard being such a noob i really want to get in the groove with juice n c++

OwnedArray is a great class for managing an array of widgets:

OwnedArray<TextButton> myWidgets;

for (int i = 0; i < 10; i++)
    myWidgets.add(new TextButton("Button " + String(i + 1)));

The syntax of your lamba function there is wrong:
chanButton01.onClick =&{processor.setMchan();};
Change it to:

chanButton01.onClick = [this]() {
    processor.setMchan();
};

Lastly, you need to be careful about what code you put in your setMchan() function… Audio code and GUI code are run on different threads so trying to change something that’s used on the audio thread from the GUI thread can cause issues. There are tricks you can use to avoid any issues such as using atomics or locks, but thinking carefully about your plug-ins logic and workflow is very important.
Hope that helps!

Thanks for the help could I ask a question

Since u made my buttons into the widget array

How do I call them

This would be differant right ?
chanButton01.onClick = this {
processor.setMchan();
};
It won’t be chanButton01 any more but what will it be sorry for the noob questions

Can you please surround your code with three backticks? ```
it’s the character on the same key as the tilde.

```
like this
```

like this

Your syntax for lambdas is still wrong. This is the best article I found about them when I was learning. You should get familiar with them because they’re a great feature in C++.

To access the object stored in an Array, you’ll have to using the [] operator, like this:

OwnedArray<TextButton> myWidgets;

for (int i = 0; i < 10; i++)
    myWidgets.add(new TextButton("Button " + String(i + 1)));

myWidgets[0]->onClick = [this]()    // <<<<
{ processor.setMchan(); };

Notice that [] gives you a pointer, so you have to use -> to access the member instead of the dot(.)

You can also iterate through the array to access all of the buttons at once:

for (auto button : myWidgets)
    button->onClick = [this]()
        { processor.setMchan(); };

Chances are, the OP used the [ and ], but since he doesn’t use the suggested ``` around his/her code, it got interpreted as markup and doesn’t show.
Until the markup is fixed, there is no point in commenting his/her code…

when I copy paste the code I just get errors …I understand what your doing but there’s something up with the naming of the buttons preventing me from trying it also is the code supposed to be sitting in the header or the cpp my code was originaly in both

yes was missing the [ ]
chanButton01.onClick =[&](){processor.setMchan(1);};

my main grief is getting chanButton01.onClick. to an array like chanButton(1).onClick