#no error just question

5 messages · Page 1 of 1 (latest)

grave meteor
#

so I am making a tower defense game honestly going great everything is working fine, but I have some questions about how I decided to structure my code now I know this is just a small snippet of my code but should I have taken a different approach to how I did this please let me know thanks

local RunService = game:GetService("RunService")
local Dat = require(script.Parent.dat)

local Tower = {}

Tower.__index = Tower

function Tower.NewTower(Radius, Model, AtkSpeed, OutPoint, AttackObj, UpgradeCost, BetterEye, Name, Damage, Player)
    local self = {
        Radius = Radius,
        Model = Model,
        AtkSpeed = AtkSpeed,
        OutPoint = OutPoint,
        AttackObj = AttackObj,
        UpgradeCost = UpgradeCost,
        BetterEye = BetterEye,
        Name = Name,
        Damage = Damage,
        Player = Player,
        
        --Global Args
        
         -- Add owner arg so the game knows what is what.
        CurrentUpgrade = 1,
        Hovering = false,
        InUiState = false,
    }
    
    
    return setmetatable(self, Tower)
end
spice thistle
#

looks god
but personally i prefer putting the variables in a table
so like

function Tower.NewTower(Data)
    local self = {
    Radius = Data.Radius
    }

and in the other code then :

local Tower = TowerThing.NewTower({
    Radius = 10,
    Model  = idk,
    Name = "Gunter"
})
#

@grave meteor

#

also you can combine that with type casting
then it shows you what values it needs to work and gives you a warning if something is missing

#

but thats just when you want it readable
also like that you dont have to care about what order you put the variables