Skip the wilds at the start of the line to find the symbol it pays for, then count from the left while each symbol is that symbol or a wild. Checking against the first symbol on the line fails as soon as that symbol is a wild, because only another wild is equal to a wild. In our Godot 4.7 test W A A B C and W W A A A paid nothing that way, and over 100,000 random lines of 6 symbols plus a wild it found 7,296 wins where there were 12,638: 5,342 missed and 338 paid as fewer wilds instead of a longer run. The script found all of them.
The code
Save it as line_win.gd. line_win() takes the symbols on one line from left to right and returns the symbol and how many in a row, or an empty Dictionary for no win. Symbols here are Strings with W as the wild. With resources, compare ids, or a wild flag on the symbol, the same way.
extends RefCounted
## Count a slot line win from the left, with a wild symbol that stands in for anything.
## Symbols here are Strings and "W" is the wild. Use your own ids or resources the same way.
const WILD := "W"
static func line_win(line: Array, min_match: int = 3) -> Dictionary:
var base := WILD # a line of only wilds pays as wilds
for s in line:
if s != WILD:
base = s # the first real symbol decides what the line pays, even after wilds
break
var count := 0
for s in line:
if s != base and s != WILD:
break
count += 1
if count < min_match:
return {}
return {"symbol": base, "count": count}
What we measured
Lines of 5 symbols, a win from 3 in a row, compared with a check that takes the first symbol on the line as the one to match. Two runs gave the same numbers.
- W A A B C: first symbol check, no win. Script: A three times.
- W W A A A: no win against A five times.
- W W B C D: no win against B three times.
- A W A W B and A A W B B: both paid A four and three times. A wild after the first symbol was never the problem.
- W W W W W: both paid five wilds. A B A A A: neither paid, because the run has to start at the left.
- 100,000 random lines, each symbol one of 6 plus the wild: 7,296 wins with the first symbol check, 12,638 with the script. 5,342 were missed completely and 338 paid fewer symbols, for 24,494 symbols paid in all against 42,889.
- With min_match 2, W B C D E paid B twice.
Why it happens
A wild has no symbol of its own. When it is the first on the line, a check that matches everything to the first symbol is matching against the wild, and the only thing equal to a wild is another wild. So a line that starts with a wild only pays while the wilds last, and the real symbol behind them never counts. Looking past the wilds first gives the line the symbol it actually pays for.
What to change
- Lines in a grid: read each payline's cells from left to right into an array and pass it in. For V shapes and diagonals the cells change row, the check stays the same.
- Rolls that repeat for a daily run or a replay: give the machine its own RandomNumberGenerator. Symbol chances: weighted picks with rand_weighted().
- Reels that spin backwards or stop between symbols: tween forward to the result.
A whole machine built on this: Slot Roguelike Kit for Godot 4 finds wins on rows, V shapes and diagonals, columns and clusters, with a wild flag on any symbol and min_match to set. Its evaluate(grid) checks a grid without spinning, and every win reports its cells, symbol, count and score.
Tested in Godot 4.7 with the Compatibility renderer.
Ready-made: Slot Roguelike Kit for Godot 4 finds wins on rows, V shapes, diagonals, columns and clusters, with wild symbols that count even at the start of a line.
More how-tos: Game systems
- Hover a 3D object inside a SubViewport
- A turned building that covers the cells it stands on
- An inventory that never loses an item and never overfills a stack
- A JSON save that loads back exactly what you saved
- Fire that spreads one cell per step, in every direction
- A pooled enemy that comes back as fresh as a new one
- An enemy that stops at the dead player and finds the respawned one
- Poison, burn and bleed that keep ticking when applied again
- XP, qi and gold that keep growing without going negative
- Random directions spread evenly over a sphere or a cone
- Count a lap only when the car really went round
- Make a seed repeat: daily runs, replays and roguelike seeds
- Offline progress that counts the time the game was closed
- A chance roll without the long bad-luck streaks
- Check crafting recipes in any order, with the right counts
- Make HP and mana regen the same at any frame rate
- Damage over time with the right number of ticks
- Spawn enemies where the camera cannot see them
- Keep a chasing horde from stacking into one enemy
- Make the fish bite after the same wait at any frame rate
- Snap buildings to the right grid cell on both sides of the origin
- Make a cooking timer fire once, on time
- Pick from a weighted loot table with the right chances
- Level up as many times as the XP covers
- Walk a patrol guard to each point without overshooting
- Remove items from an Array while checking them, without skipping any
- Scatter spikes, roots or trees in a circle without overlaps
- Count and take crafting items from every stack
- Play random sounds and events without obvious repeats
- Pick the growth image so the ripe one shows exactly when the crop can be picked
- Turn a day counter into season, day and year without a day 0
- An enemy that dies once, however many hits land
- A fair shuffle you can replay
- A ghost that drives the lap at real speed
- A vision cone that does not flicker at the edge
- Move a group of units without a pile-up
- A sprinkler that waters a round patch
- A slot reel that always lands forward on the result
- A crowd of NPCs that never emote or bob in step
- A song position that moves on every frame
- Nodes your editor tool adds that stay in the scene