A snippet of code from Cookie Clicker. An additional For loop has been created which breaks (in the programmatic sense) once it has successfully spawned a golden cookie. It reads " if (success && Game.shimmerTypes['golden'].n<=0 && Game.auraMult('Dragon Orbs')>0) { var highestBuilding=0; for (var i in Game.Objects) { if (Game.Objects[i].amount > 0) highestBuilding = Game.Objects[i]; } for (var i = 0; i < amount; i++) { if (highestBuilding == this && Math.random() < Game.auraMult('Dragon Orbs') * 0.1) { var buffsN = 0; for (var ii in Game.buffs) { buffsN++; } if (buffsN == 0) { new Game.shimmer('golden'); Game.Notify(EN ? 'Dragon Orbs!' : loc("Dragon Orbs"), loc("Wish granted. Golden cookie spawned."), [33, 25]); break; } } } }"
The first of what will hopefully be many additions to Cookie Clicker, With the help of a friend we made a somewhat inefficient loop that correctly identifies when you've made a bulk sale of buildings and rolls your chance of spawning a golden cookie correctly #dragonorb #cookieclicker