Return a value from a <group>

asked 2018-12-09 23:47:45 -0500

KenYN gravatar image

If we have a launch file like this:

    <arg name="foo" value="2"/>
    <group if="$(eval (foo == 1"))">
        <arg name="bar" value="foo is one"/>
    <group if="$(eval (foo == 2"))">
        <arg name="bar" value="foo is two"/>
    <group if="$(eval (foo == 3"))">
        <arg name="bar" value="foo is three"/>
    <!-- next line fails -->
    <arg name="wibble" value="$(arg bar)"/>

Basically I have a bunch of complicated logic that sets up a variable bar, then from outside the <group> scope I wish to access it again, rather than repeating all the logic. However, this gives the error:

arg 'bar' is not defined
Arg xml is <arg name="wibble" value="$(arg bar)"/>

I understand that <group> opens a new scope, but is there a workaround for this? I could use <param> to save bar, but I cannot see a way to read it back from the parameter server.

edit retag flag offensive close merge delete


I assume this is a simplified example? As putting if and unless directly on arg elements is supported.

gvdhoorn gravatar image gvdhoorn  ( 2018-12-10 00:34:29 -0500 )edit

Yes, it is simplified - I can of course do that, but there will be duplicated logic.

KenYN gravatar image KenYN  ( 2018-12-10 00:48:44 -0500 )edit