Forum

Sending strings between subpatches

I’m trying to pass strings out from several subpatches so that they can be put into another subpatch and displayed. My idea is to put the message string in one output from the subpatch, and a bang in another so the receiver can know when to grab the message.

I have a bunch of bools I can use to know which message to send, but I don’t know how to use them to select the right message. My first thought was to use a switch, but I can’t figure out how to use it for this purpose, it feels like it would be cumbersome even if I could figure it out.

image

In the languages I’m used to I could create a list at the beginning of the function, and when I want to add a message I could just do message_list.append("A thing happened");, and at the end of the function I would return the list. I’m hoping to find a solution at that level of simplicity.

What technique is appropriate for this situation?

you can do this with the StringBuilder… it has an Append or AppendLine node that you can call.

when finished you can call ToString to get the end result:
image

1 Like

That looks like a good way to do it, I’ll try that out!


Got an answer from iorec in the Element chat, will look at this as well:


Thanks a lot for the quick and useful responses! :D

I’ve tried these two methods now and both work well. Which one to choose depends on if you prefer looking handling the messages as a String or a for instance Spread<String>.

Thanks again!