MNoya / Element-TD

Element Tower Defense
http://www.eletd.com
64 stars 22 forks source link

tweaking random formula #459

Closed biax closed 8 years ago

biax commented 8 years ago

function getRandomElement(wave) -- Never random a Pure Essence unless there's enough to use it on a Periodic/Pure tower if usedElements["pure"] < 2 then for i,v in pairs(usedElements) do if v == 3 then hasLvl3 = true end if v == 0 then hasLvl1 = false end end if hasLvl3 or hasLvl1 then usedElements[element] = usedElements[element] + 1 local element = elements[math.random(#elements - 1)] return element end else local element = elements[math.random(#elements)] return element end

Noya, able to tell me if this code works?

While it doesn't change the formula at all, I thought its better to actually test first before attempting to random rather than making numerous attempts.

biax commented 8 years ago

disregard above code. review this instead:

function getRandomElement(wave) -- Never random a Pure Essence unless there's enough to use it on a Periodic/Pure tower if usedElements["pure"] < 2 then for i,v in pairs(usedElements) do if v == 3 then hasLvl3 = true end if v == 0 then hasLvl1 = false end end if hasLvl3 or hasLvl1 then local element = elements[math.random(#elements - 1)] usedElements[element] = usedElements[element] + 1 return element end else local element = elements[math.random(#elements)] usedElements[element] = usedElements[element] + 1 return element end

biax commented 8 years ago

i think theres some logic error from my part heh. ill think it through