|
|
Quellcode |
1 2 3 |
<action name="def_global_var">
def(global.variable_to_count, int, 0);
</action>
|
|
|
Quellcode |
1 2 3 4 5 6 7 8 9 |
<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>
|
|
|
Quellcode |
1 |
copy(dynamic_var_name, something.matter); |
Zitat
The intention is not clear from the code
|
|
Quellcode |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
<action name="def_global_var">
def(global.variable_to_count, int, 0);
</action>
<action name="set_global_var">
txtadd(dynamic_var_name, 'variable_to', %1);
<!-- let's say %1 = '_count' in this example
so the dynamic_var_name = 'variable_to_count' -->
<!-- great we have the global variable name as generated variable
how to access the global variable through the generated variable
what's next, how to set global.variable_to_count with dynamic_var_name -->
set(global.get(dynamic_var_name), get(whatever)); <!-- NOT work -->
set(global[get(dynamic_var_name], get(whatever)); <!-- NOT work -->
set(global[get(dynamic_var_name].value, get(whatever)); <!-- NOT work -->
</action>
|
|
|
Quellcode |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
<action autorun="onstart">
set(var_int,0);
for(set(i,0), i LT 3, inc(i),
txtadd(dynamic_var_name, 'variable_to', get(i));
// and now
calc(dynamic_var_name, 'The variable no '+i);
);
<!-- checker -->
for(set(i,0), i LT 3, inc(i),
trace('Index : ',get(i),' Text: ',calc('variable_to'+i));
);
</action>
|
Zitat
This?
|
|
Quellcode |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
<action name="def_global_var">
def(global.variable_to_count, int, 0);
</action>
<action name="set_global_var">
txtadd(dynamic_var_name, 'global.variable_to', %1);
<!-- let's say %1 = '_count' in this example
so the dynamic_var_name = 'global.variable_to_count' -->
<!-- great we have the global variable name as generated variable -->
trace(get(dynamic_var_name)); <!-- INFO: 0 -->
set(current_count, get(dynamic_var_name));
inc(current_count);
set(get(dynamic_var_name), get(current_count));
trace(get(dynamic_var_name)); <!-- INFO: 1 -->
</action>
|
Dieser Beitrag wurde bereits 2 mal editiert, zuletzt von »zabelin« (17. August 2021, 16:21) aus folgendem Grund: just looks like code may be simpler
This was a working example of how to create variables dynamically and assign specific values to them. Now it's up to you to take it yourself and rewrite it your way.Don't think so)
|
|
Quellcode |
1 2 3 4 5 6 7 8 9 10 11 12 |
<!-- i think you need action.scope defined, otherwise global.var might not work -->
<action name="def_global_var" scope="local">
def(global.variable_to_count, int, 0);
</action>
<action name="set_global_var" scope="local" args="name">
calc(local.dynamic_var_name, 'global.variable_to' + name);
trace(dynamic_var_name,'=',get(dynamic_var_name));
inc(get(dynamic_var_name));
trace(dynamic_var_name,'=',get(dynamic_var_name));
</action>
|