It seems that Flow variables are not properly shared between the "Main" flow and subflows. I can't find any documentation that describes if a flow variable should be available to a sub flow? Should it? I can see arguments on both sides. Perhaps I need a new type of shared variable between Flow and Global?
In the meantime, is there a technique I can use to set a variable in a subflow and access it from the main flow and vice versa? I can't use Global, as the whole point of subflows are that they are reusable by other main flows.
--
http://nodered.org
Join us on Slack to continue the conversation: http://nodered.org/slack
---
You received this message because you are subscribed to the Google Groups "Node-RED" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+unsubscribe@googlegroups.com.
To post to this group, send email to node...@googlegroups.com.
Visit this group at https://groups.google.com/group/node-red.
To view this discussion on the web, visit https://groups.google.com/d/msgid/node-red/37ae8e90-0df0-4949-82c7-7632b42c3d34%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Don't currently have an answer for this - its a tricky problem to solve.The challenge is deciding how best to allow the main flow reference the subflow's context, or vice versa. And that depends on the specific scenario you're trying to build.If a subflow instance could access the 'parent' flow's context, it solves some problems, but doesn't solve everything as you could have multiple instances in the same parent flow. In which case you'd have the same issues as if you were using global - clashing names.If there was a way for the parent flow to dig into the subflow instance's context, then that would help. But the challenge is how to do that; each subflow instance has a unique id which could be used to reference its context... but then the developer would have to know what those ids were and it would potentially be brittle as you copy and pasted nodes around (generating new ids along the way).The workaround is to pass parent context variables into and out of the subflow by way of the messages you pass in and send out. Use a Change node on either side of the subflow instance to retrieve the values you want from flow context and attach them to the message, and vice versa on the output of the subflow.Nick
On 18 November 2016 at 11:26, Anthony McDonald <ajr.mc...@gmail.com> wrote:
It seems that Flow variables are not properly shared between the "Main" flow and subflows. I can't find any documentation that describes if a flow variable should be available to a sub flow? Should it? I can see arguments on both sides. Perhaps I need a new type of shared variable between Flow and Global?
In the meantime, is there a technique I can use to set a variable in a subflow and access it from the main flow and vice versa? I can't use Global, as the whole point of subflows are that they are reusable by other main flows.
--
http://nodered.org
Join us on Slack to continue the conversation: http://nodered.org/slack
---
You received this message because you are subscribed to the Google Groups "Node-RED" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+u...@googlegroups.com.
I was going to ask about scope of flow variables and found this thread.Having read it, am I right in thinking that if i define/use say flow.test in a subflow, then it will be local to that subflow and not interfere with a flow.test in the main flow I use it in? (Its the behaviour I'm hoping for BTW)
--
http://nodered.org
Join us on Slack to continue the conversation: http://nodered.org/slack
---
You received this message because you are subscribed to the Google Groups "Node-RED" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+unsubscribe@googlegroups.com.
To post to this group, send email to node...@googlegroups.com.
Visit this group at https://groups.google.com/group/node-red.
To view this discussion on the web, visit https://groups.google.com/d/msgid/node-red/94e551f5-74ef-4db1-bbe5-231d823df851%40googlegroups.com.