Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
function toJson(obj)
local r = ''
local ia = false
for k, v in pairs(obj) do
if r ~= '' then
r = r .. ','
end
if type(k) == 'string' then
r = r .. utf8.char(0x0022)
r = r .. k
r = r .. utf8.char(0x0022) .. ':'
else
ia = true
end
if type(v) == 'table' then
r = r .. toJson(v)
elseif type(v) == 'string' then
r = r .. utf8.char(0x0022)
r = r .. v
r = r .. utf8.char(0x0022)
else
r = r .. v
end
end
if ia then
return '[' .. r .. ']'
else
return '{' .. r .. '}'
end
end
function func(l)
ml = 5
if l > ml or l < 0 then
l = ml
end
nl = l + 1
obj = {}
obj.maxLevel = ml
obj.speed = 5
obj.housingSpace = 1
obj.attackRange = 1
obj.hitPoints = 10 * l
obj.healthPoints = 100 * l
obj.buildTime = 100 * l
obj.upgradeTime = 100 * nl
bc = {}
bc.gold = (28500 * math.pow (l, 2)) - (77500 * l) + 51000
obj.buildCost = bc
uc = {}
uc.gold = (28500 * math.pow (nl, 2)) - (77500 * nl) + 51000
obj.upgradeCost = uc
obj.trainingTime = 10 * l
tc = {}
tc.gas = 10 * l
obj.trainingCost = tc
return obj
end
print (toJson(func(1)))
Advertisements
We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.
AcceptLearn more