kellyelton/OCTGN — Issue #110: Card animation (?) can delay or disrupt scripts running. AKA the rnd(100, 1000) hackaround.
Author: db0
Created: 2012-02-09 06:43:03+00:00
State: open

Originally reported [as a problem with the shuffle function on the OCTGN2 bug reports](https://octgn.16bugs.com/projects/3602/bugs/102681) we've since experienced it with other scenarios as well.

Basically what happens is that if you do something that animates a card, and then immediately run a command that further affects or reads from the card, if the animation is not yet complete, you might not get the correct result.

Some classic examples:

* Moving your discard pile into your deck and then shuffling the deck will not work. The deck will remain unshuffled
* Flipping a card face up and reading a property immediately afterwards

game developers like me and brine have hacked around it by adding an arbitrary rnd() calculation to force octgn to "wait" a bit before moving on to the next line of the script. The time one needs to wait seems to vary depending on the animation done.

Example

```python
def reshuffle(group = me.piles['Discard Pile']):
mute()
Deck = me.Deck
for c in group: c.moveTo(Deck)
random = rnd(100, 10000)
Deck.shuffle()
notify("{} moved his {} into his Deck.".format(me, group.name))
```

If the rnd() function is removed in this instance, the deck will never shuffle.