Return a value from a <group>

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

KenYN gravatar image

If we have a launch file like this:

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

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

Comments

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

gvdhoorn gravatar imagegvdhoorn ( 2018-12-10 00:34:29 -0600 )edit

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

KenYN gravatar imageKenYN ( 2018-12-10 00:48:44 -0600 )edit