Sorry, we don't support your browser.  Install a modern browser

ToggleGroup shares function path for "onValueChanged" between all same ids#2286

When cloning an object with parsing XML code snippet to that object, if using any ToggleGroup with defined “onValueChanged” attribute and not modifying any ids, onValueChanged calls an object function which was created/cloned last and has that function.
For Example. I have an empty custom card (no lua/xml code) with guid=a00000. Then I clone the card and the result’s guid is a00001. I parse next XML to that card with function “ChangeQuantity” declared beforehand and script already updated to have this function (It’s the XML code snippet from which I caught this bug initially):

<ToggleGroup 
        onValueChanged="ChangeQuantity"
        id="quantity_options" 
        tooltip="Quantity" tooltipPosition="Below"
        height="40" fontSize="20" 
        scale="0.7 0.9 1" 
        itemHeight="40" 
        rectAlignment="UpperCenter" 
        color="#FFFFFF">
        <HorizontalLayout>
            <Toggle id="5">5</Toggle>
            <Toggle id="10">10</Toggle>
        </HorizontalLayout>
    </ToggleGroup>

Then if I declare more copies of this card, even if cloning from a00000 (let’s say. new custom card’s guid is a00002), I get that when I choose an option in a00001’s ToggleGroup, it calls a00002’s “ChangeQuality”. I have checked that by implementing ChangeQuality in parser as:

function ChangeQuality(player, option, id)
      print(self.guid)
end

It always returned last created clone/copy’s guid, a00002 in this case.
However, change I XML element to something like Dropdown:

<Dropdown 
        id="quantity_options" 
        onValueChanged="ChangeQuantity"
        tooltip="Models Quantity" tooltipPosition="Below"
        height="40" fontSize="20" 
        scale="0.7 0.9 1" 
        itemHeight="40" 
        rectAlignment="UpperLeft" 
        color="#FFFFFF">
        <Option selected="true">5</Option>
        <Option>10</Option>
    </Dropdown>

Everything works fine, and ChangeQuality returns guid of the object it was called from. The problem stands as I have no option of proactively declaring for “onValueChanged” value to have “a00001/ChangeQuality” or “a000002/ChangeQuality”

a month ago