Page 1 of 1

idle/clicker game

Posted: Thu Aug 13, 2015 11:29 pm
by soullessbr
It's all right?

Guys I've been wasting my time with those idle/clicker game and I wonder if you can make one in love2d ?

As you would variables with those absurdly large numbers (see here units)?

Thank you

Re: idle/clicker game

Posted: Thu Aug 13, 2015 11:33 pm
by eqnox
not sure what exactly you are asking, but a good way of storing really big numbers is exponents

Re: idle/clicker game

Posted: Fri Aug 14, 2015 12:38 am
by Inny
Big numbers in computers work the way we all learned addition way back in grade school. You line the numbers one on top of the other, justified to the right, add the right most numbers together, and carry the extra digits to the next number to the left. We can do a bit more sophistication by doing this in several orders of magnitude instead of 1, and we're going to store things in the table "little endian" meaning the smaller numbers appear in smaller numbered indexes in the table. Here's some code showing how to make and add the numbers:

Code: Select all

--- Make a big number expressed in "big endian", makebig(2,993)
function makebig(...)
  local t = {...}
  for i = 1, math.floor(#t/2) do t[i], t[1+#t-i] = t[1+#t-i], t[i] end
  return t
end

function bigadd(x, y)
  local N = math.max(#x, #y)
  local z = {}
  local carry = 0
  for i = 1, N do
    z[i] = (x[i] or 0) + (y[i] or 0) + carry
    carry = math.floor(z[i] / 1000)
    z[i] = z[i] - (carry * 1000)
  end
  if carry > 0 then
    z[#z+1] = carry
  end
  return z
end

-- Show that two numbers are added together correctly
local testone = bigadd(makebig(2,993), makebig(2,742))
print(testone[2] .. ',' .. testone[1])
assert(testone[2]==5 and testone[1]==735)

-- test the roll over from 999k to 1 Million
local testtwo = bigadd(makebig(999,999), makebig(1))
assert(testtwo[3]==1)
The reason I choose 1000 is because in English there's a convenience around numbers that have gotten larger by 3 orders of magnitude, you change the suffix name of the number from "thousand" to "million" to "billion". So, the length of the big number table can be the index into the suffix table, and you only need to display the largest digits.

Re: idle/clicker game

Posted: Fri Aug 14, 2015 1:51 pm
by undef
I once thought about making one as well, because it's so easy.
Then I thought they are actually pretty horrible, because there's nothing positive about them.