about array usage

  • Please see the codes.

    Code
    <array name="inventory" />
    	<action name="action1">
    	        set(array[inventory]['item_type'].value, get(item_index));
            	js(console.info(get(array[inventory]['item_type'].value);</action>
            
            <action name="action2">
            	js(console.info(get(array[inventory]['item_type'].value);
            </action>


    action1 and action2 has different array[inventory][get(item_type)].value.

    the original code is more complicated, but the concept is like the above.
    Any idea?

  • 1)
    do not use
    js(console.info(get(....)));
    just use
    debug(....);

    2)
    array[...][...] is not possible

    you can do it like this
    set(inventory['apple'].item_type, 'fruit');
    set(inventory['apple'].weight, '150g');
    set(inventory['apple'].price, '1$');

    or:
    <inventory name="apple" item_type="fruit" weight="150g" price="1$" />
    <inventory name="orange" item_type="fruit" weight="170g" price="1.2$" />
    ... etc

    then try
    debug(inventory[0]);
    debug(inventory['apple']);
    debugvar(inventory);

Jetzt mitmachen!

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