Function Definitions possible in multiple Gen Codeboxes?

Sym's icon

Hello, I have written two different Processes in Codebox that I would like to combine in a larger Patch.

I'd like to optimally have both Codeboxes seperately in the new Patch.

The Issue -> They work great by themselves, but if I copy both in the same Patch one stops working. The overall Gen Patcher still compiles but does not include the full Code from both Boxes anymore.

Both codeboxes have specific function definitions inside of them and it looks to me like the error has something to do with it when moving both to the same patch.

Are function definitions in multiple Codeboxes in the same Gen Patcher not supported?

testcase's icon

I don't think this is supported. You should look at making a GenExpr file and using the require operator. See example here https://cycling74.com/tutorials/gen~-for-beginners-part-7-creating-reusable-tools

Graham Wakefield's icon

I was a bit confused by the question, but I can offer two different answers:

1. You certainly can have multiple codeboxes with functions in them; they can even have the same name, and different definitions (see patcher below).
2. If what you want is to define a function once and use it in several different codeboxes, then you can do this by putting them in a separate .genexpr file and using a `require` statement in each codebox that needs it. See the Moog ladder filter example in the gen examples folder.

Max Patch
Copy patch and select New From Clipboard in Max.

Sym's icon

Thanks alot Graham, yes my question was to part 1. of your answer. Good to hear that this is supported and won't cause problems, this will make integrating both Codeboxes a lot easier.

Then the issue I'm currently having must be caused by something else, will try pasting the second Codebox in one step at a time and see where it breaks.