How does Satoshi Dice's 'zero confirmations' transaction system work technically? The popular bitcoin betting game Satoshi Dice sends back payments very fast, they don't wait for confirmations. The user sends money to Satoshi Dice and gets back winnings a couple of seconds later. Here's a quote from their site: 


  The SatoshiDice Bitcoin game operates with zero confirmations [...] This is safe because it always builds the answering transaction with the output of your bet transaction. This means a blockchain that does not contain your bet cannot contain the site's answer.


I think I understand the theory behind this: Satoshi Dice always sends back coins from your own bet. So if your bet doesn't get confirmed then your winnings also won't get confirmed.

What I don't understand is how I could technically create these kind of transactions. Using bitcoind, how could one build these transactions?

Thanks for your suggestions.
A transaction claims some outputs from previous transactions and then creates new outputs whose summed value is equal to (or less than, in the case of fees) the sum of the claimed outputs values.

For a transaction to be valid it must be the only one that claims the outputs (no double spend) and the transaction that created the claimed outputs must be valid. Satoshi Dice can immediately send back a transaction containing the winnings because the transaction claims the output of the incoming transaction, chaining the two transactions together.

The result is that either both transactions are valid, in which case the player gets his winnings, or the first transaction is not valid, immediately invalidating the second one, and Satoshi Dice is not tricked into sending coins back without receiving the wager.