Forums > MaxMSP

Formatting messages

October 10, 2011 | 2:03 pm

Hi all,

This has been driving me mad for the past hour or so, so I thought I’d ask for some help.

I have a number and a list.

Lets say the number is 4 and the list is 1 2 3 4

I want to format this for use with [forward] so i need it to read:

send actor4, 1 2 3 4

I’ve been trying to adapt some [sprintf] and [regexp] examples from other posts but don’t understand these enough to get this right.

Any help would be appreciated,

Mark


October 10, 2011 | 2:18 pm

Here you go :)

– Pasted Max Patch, click to expand. –

October 10, 2011 | 2:22 pm

Here’s a way to do it, using [sprintf] and [zl join]:

– Pasted Max Patch, click to expand. –

Where did you get stuck? Was it in creating the "send actorX," or in joining that to the list? If it is always ever going to be numbers you can simplify it, so it depends of course on the application.

Hope this helps :) (remember that when needing to format in a comma, you need to add a forward slash before the comma)


October 10, 2011 | 2:24 pm

Hmm, mine doesn’t work when feeding [forward] – use laonikoss’s


October 10, 2011 | 2:29 pm

Thanks Tim,

So simple when you know how!

If anyone knows of some good tutorials to help understand sprintf, I’d love hear about them.


October 10, 2011 | 2:38 pm

Aah yes, thanks for your version laonikoss.

I got stuck with adding the comma to the word actor. I could only get actor4,

Really through my lack of understanding when it comes to sprintf though…


October 10, 2011 | 2:52 pm

Just a note: You don’t need to mess with a comma at all. The commas in the message boxes in the forward.help file are just there in order to combine two messages in a single clickable message box. But you can just use sprintf to construct the desired receiver name (such as "actor4"), then tell forward what you want to send.

By the way, the help file for sprintf has a link to an informative Wikipedia page (can’t get much more helpful than that!), although that’s probably way more information than you want or need, so GIYF.

– Pasted Max Patch, click to expand. –

October 10, 2011 | 5:01 pm

@ Christopher, Thanks for pointing that out… I can’t believe I didn’t notice that! Actually I didn’t realize message boxes worked in this way, so that’s probably the most useful thing learned today.

As for the sprintF commands, Probably there’s no shortcuts to learning that stuff, just a shame Google can’t break it up and feed it to me a bit at a time, perhaps while I’m sleeping?


October 10, 2011 | 5:46 pm

What Christopher said. The comma in message boxes has been the stumbling block of many a Max user. Once you know that it’s just a shorthand for combining messages into a single message box, things get a lot easier.


October 11, 2011 | 8:35 am

When not using the comma, you just need to make sure the order in which the messages arrive at [forward] is correct – i.e. you must first send the [send actor4] message, and then the list you want to send to "actor4", or whatever.

sprintf comes from C (programming language) – as the help page for [sprintf] says, "For complete documentation, refer to a standard C library reference manual." which I guess answers your question as to where to find more information.


Viewing 10 posts - 1 through 10 (of 10 total)