if statements were the exact thing I was avoiding really, is there not a way to make one if statement work on all instances of this? its hard to explain but
local projectileInfo = SwordInfo.ProjectileInfo or {} --if first value is nil instead use an empty table so it doesn't error
newSword.ProjectileType = projectileInfo.ProjectileType or 1 --if it's nil then use a default value instead
--and so on
You can just put them all in one scope, it’s what I would do. Declare a variable outside so that it has a default value.
local cooldown = 0
local velocity = 0
if SwordInfo.ProjectileInfo ~= nil then
cooldown = SwordInfo.ProjectileInfo.projectileCooldown
velocity = SwordInfo.ProjectileInfo.projectileVelocity
-- put all variables that depend on it's existence
end
if (swordInfo['ProjectileInfo'] ~= nil) then
if (swordInfo['ProjectileInfo']['ProjectileType'] ~= nil and swordInfo['ProjectileInfo']['ProjectileCooldown'] ~= nil swordInfo['ProjectileInfo']['ProjectileVelocity'] ~= nil) then
--// whatever here
end
end
I did try that before and it did work, however if I did this for every variable that i’m going to have, then its gonna take up a lot of space and make the code less readable (in my opinion), thanks for replying though!