@Kampfkarren
I must’ve been unclear in my OP
The question isn’t about retaining the Leveler itself - it exists because it is reused
If you want a concrete example, each machine type in my game has its own Leveler stat.Leveler = newLeveler(stat.LevelConstant,stat.LevelBase)
that depends on the machine’s LevelConstant and LevelBase which vary per machine
So there is a clear need for some sort of Leveler class
As for @suremark’s idea to do a “curve fitting” function, I think that would be useful but I don’t think its necessary for this although I will do it in the future if the math isn’t insane so thanks for the idea
btw I like that you used ad-hoc lol
Ok anyways so I’ll continue with the Machine example instead of player example:
So each Machine type has its own Leveler, but Machine types are in their own sense “classes” (because multiple machines of that type can exist and have separate “states”), more specifically with the following variables and functions:
--[=[
return {
Id = 1,
Image = "rbxassetid://000000",
Description = [[
]],
Type = "Normal",
MachineType = "Producer",
LevelConstant = 1000,
LevelBase = 1.3,
CostConstant = 1000,
CostBase = 1.1,
HealthConstant = 100,
HealthBase = 1.1,
ShopProbability = 100,
ShopAmount = 10,
ProductionTime = 3*60,
ProductionConstant = 10,
ProductionBase = 1.1,
Add = function(machine) end,
}
Level constant and base - see leveler
others:
Constants: initial
Base: base^level
Add - function called when a new model of this machine is added. machine is the Machine object
ShopProbability - prob of this appearing in shop = ShopProbability/(sum of all machine shop probabilities)
ShopAmount - amount of this item that can be sold at once in shop
Additions:
Models - array of models for corresponding levels
MaxLevel - the max upgrade level of this machine (last machine model)
GetModel - gets the appropriate model for the machine level
Leveler - returns leveler
GetCost - method returns cost based on level
GetHealth - method returns health based on level
GetHeal - method returns cost to heal health points
GetProduction - method returns production based on level
--]=]
Here is an actual machine object:
machine = Stream.New(tostring(tile.Global),nil,{
Name = stat.Name,
Id = id,
Owner = owner,
CreationTime = getTime(), -- used for production
Level = level,
Xp = xp,
XpLeft = xpLeft,
Model = build,
--Tile = tile, -- not using it atm and it messes up remotes bc cyclic table references
Global = tile.Global, -- global position
Health = health,
MachineDataIndex = ind, -- index in machineData if its on an ffa tile to reference from client and when killing, this will be nil if its not in ffa region
Humanoid = humanoid,
-- functions wont be streamed to client so its fine
GrantXp = grantXp,
Kill = function(playAnimation)
humanoid:Kill()
grid[tostring(machine.Global)].Machine = nil
if playAnimation then
removeBuild(machine)
else
build:Destroy()
end
Stream.Kill(machine)
if ind then -- is ffa machine iff started as ffa machine
machineFFAIndex[machine.MachineDataIndex] = nil
end
machine = nil
end,
},{"Humanoid",})
As you can see it has the variables:
Level = level,
Xp = xp,
XpLeft = xpLeft,
It doesn’t need Level and XpLeft, I was just bored so I micro-optimized lol
But to get the individual machine’s leveler stats I have to call functions on the machine type’s stat as shown here:
RB.Network("Upgrade"):Bind(function(player,global)
local machine = grid[global]
machine = machine and machine.Machine
local stat = Machines[machine.Id]
if not (machine.Owner == player and machine.Level < stat.MaxLevel and machine.XpLeft == 1) then
return
end
local nl = machine.Level+1
local nx = machine.Xp+1
local data = Data:Get(player)
local d = data.Money-stat:GetCost(nl)
if d>=0 then
-- update money and machine xp
data("Money",d)
machine("Xp",nx)
machine("XpLeft",stat.Leveler:Left(nx))
machine("Level",nl)
-- rest is done within the health changed
end
end)
(Where it says stat.Leveler:Left(nx)
)
So my question is do I want to have stuff like that or should it be replaced by things such as machine.LevelerInstance.Left -- __index call // probably need better name than LevelerInstance but you get the point