Jump to content

Recommended Posts

Greetings,

I might have messed up some stuff in this code, could someone correct it?

 

Quote

local function followerWardrobe(inst, data, owner, self, costume, visuals)
    return function (inst, data)
        local function dressFollowerup(inst)
            if data and data.leader then
                local myownerskin = data.leader.components.skinner.skin_name
                
                if myownerskin == owner.."formal" then
                
                    inst.AnimState:SetBuild(self.."_formal")
                    
                elseif myownerskin == owner.."survivor" then
                
                    inst.AnimState:SetBuild(self.."_survivor")
                    
                elseif myownerskin == owner.."shadow" or myownerskin == owner.."unshadow" then
                
                    inst.AnimState:SetBuild(self.."_shadow")
                    
                elseif myownerskin == owner.."_"..costume or myownerskin == owner.."_"..costume.."_d" then
                
                    inst.AnimState:SetBuild(self.."_"..costume)
                    
                elseif myownerskin == owner.."_combatant" then
                
                    inst.AnimState:SetBuild(self.."_combatant")
                    
                elseif myownerskin == owner.."_gladiator" then
                
                    inst.AnimState:SetBuild(self.."_gladiator")
                    
                elseif myownerskin == owner.."_rose" then
                
                    inst.AnimState:SetBuild(self.."_rose")
                    
                elseif myownerskin == owner.."_ice" then
                
                    inst.AnimState:SetBuild(self.."_ice")
                    
                else
                    inst.AnimState:SetBuild(self.."_base")
                end
            end
        end
        
        inst:ListenForEvent("startfollowing", dressFollowerup)
    end
end

AddPrefabPostInit("abigail", function(inst)
    followerWardrobe(inst, data, "wendy", "ghost_abigail", "lureplant", false)
end)

 

Link to comment
https://forums.kleientertainment.com/forums/topic/85918-code-sorting/
Share on other sites

In line 2 you're returning a function when I don't think you will.

 

Also you may like lookup tables instead of a giant if-then-else tree:

local skin_lookups = {
    formal = "_formal",
    survivor = "_survivor",
    shadow = "_shadow",
    unshadow = "_shadow",
    lureplant = "_lureplant",
    lureplant_d = "_lureplant",
    _combatant = "_combatant",
    _gladiator = "_gladiator",
    _rose = "_rose",
    _ice = "_ice",
}


myownerskin = myownerskin:sub(owner:len()+1)
local self_suffix = skin_lookups[myownerskin] or "_base"
inst.AnimState:SetBuild(self..self_suffix)

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...