Weighted tables
Lesson 16 of 16 · GDev.Micro
Not every outcome should be equally likely. A weighted table gives each result a share: here, a new spawn is a coin 75% of the time and an enemy 25%.
Weights are a design dial. At 50/50 the ground fills with enemies and the game turns into survival; at 75/25 the player mostly collects, with enough danger to stay alert.
Preview both tables and watch Enemy instances in the debugger. Keep the one that fits the game you want.
In GDevelop, a common pattern is to store RandomInRange(1, 100) in a variable and compare it with thresholds: 1 to 75 creates a coin, 76 to 100 an enemy. Loot drops, enemy waves and card draws work the same way.
Every 2 seconds, spawn from the weighted table (75% coin, 25% enemy) and reset the timer.
Do it in the browser: a real game design tool, a short mission and instant feedback. No install.
Start this lesson — free