Happy Lunar New Year, or as Vietnamese know it, Tết!
Tết is a time for family gathering, reflection, celebration, and fun and games!
In our family, we’d take our newly gifted Lì xì (or lucky money in red envelopes) and trade some of it in for change. Then we’d have some fun trying our new year luck at teensy bit of gambling.
One of the games we used to play in my household was called Bầu cua cá cọp (Gourd, Crab, Fish, Tiger).

To play, you bet your change by placing it on one of the animals. The then dealer rolls the dice. If the dice match your bet, you get to keep your money and win the same amount times the number of matching dice!
And now, you get change to try the same game!
Under The Hood
We whipped this up over the weekend with the help of Gemini and DALL-E for the art work.
I wanted to future proof the game by using a table to store the bet data and allowing for multiple columns, in case I wanted to make it multiplayer. The game has a table that has a row for each square. The first column holds the name of the square and subsequent columns could represent players. In the future I could add more columns to represent more players!
Placing bets and rolling dice were pretty straightforward, but calculating payouts was a bit trickier. In a more traditional language, you’d usually just do two nested loop to calculate payout. Loop through all of the squares, and for each square then loop through all the players (or vice-versa).
Unfortunately, GameSalad’s doesn’t support nesting loops yet. BUT, since we had 6 actors already representing each square, we just put the looping logic inside each actor, which got rid of the outer loop. Now I only had to loop through each player’s bets using Loop Over Table.
Next I had to figure out the payout based on the dice. The dice results were stored in a 3 column table, one column for each dice. I just needed to compare each dice with the square’s current value. For every match, I’d add 1 to the payout multiplier. Now the most natural way to think about doing this would be to use 3 rules, one for each dice. If there’s a match, increment the multiplier, if not, don’t. Unfortunately Rules aren’t technically Actions, so while it would likely work fine, you couldn’t guarantee that all the rules would resolve in an orderly fashion based on how GameSalad’s “language” is specified. So how do I do 3 match number checks in a row with just Actions? Why with some math! I used 3 times to set the PayoutMultipler for a given square.
self.PayoutMultiplier = self.PayoutMultiplier+(1-(min(abs(tableCellValue(tables.DiceRoll,1,1)-self.BetRow),1)))
See if you can work out what I did there…
… got it? …
… here’s rundown …
First I get the difference between the current square’s number and the dice number.
If the two numbers match, we get 0. If they don’t the combination of the abs function and the min function turn the difference into a 1.
The take that value and subtract it from 1. That turns the 0 into a 1 and the 1 into a 0.
The end result is that I add 1 if there’s a match and nothing is if there is no match!
Pretty nifty, no?
Okay enough nerding out, I hope you have fun with this little bit New Year tradition! I certainly had fun sharing it with you!
Chúc Mừng Năm Mới!