how to set global.variable with dynamically created name

  • Hi, let's say we define a global variable:

    Code
    <action name="def_global_var">
        def(global.variable_to_count,  int, 0);
    </action>


    which we want to set by picking with dynamically created name:

    Code
    <action name="set_global_var">
        txtadd(dynamic_var_name, 'variable_to', '_count');
        
        <!-- what's next, how to set var -->
    
    
        set(global.get(dynamic_var_name), get(something.matter));          <!-- NOT work -->
        set(global[get(dynamic_var_name], get(something.matter));          <!-- NOT work -->
        set(global[get(dynamic_var_name].value, get(something.matter));    <!-- NOT work -->
    </action>


    The question is, which syntax should be in order to set the global value?

    By the way, which way to define a global.variable outside of the action tag.

    Thx,

  • Thank you pacerywirtualne and indexofrefraction.

    Zitat

    The intention is not clear from the code


    The point is to set global variable with accessing to it through the generated name.

    something.matter as well as whatever it's just for example )

  • This?

    Trace:


    INFO: Index : 0 Text: variable_to0
    INFO: Index : 1 Text: variable_to1
    INFO: Index : 2 Text: variable_to2

    Piotr

  • Zitat

    This?


    Don't think so)

    spacerywirtualne and indexofrefraction thanks to you a solution founded.
    Not the most graceful, but works:



    Still hope that someone will find the better syntax's solution.

    2 Mal editiert, zuletzt von zabelin (17. August 2021 um 16:21) aus folgendem Grund: just looks like code may be simpler

Jetzt mitmachen!

Sie haben noch kein Benutzerkonto auf unserer Seite? Registrieren Sie sich kostenlos und nehmen Sie an unserer Community teil!