If you want it DRY so badly, which is certainly a good thing, add a
character:hasCostume method that both pieces of code make use of. It's
worth it to not be blindly swallowing errors.


On Wed, May 8, 2013 at 1:20 AM, Nick Scripp <notifications@github.com>wrote:

> In src/items/consumables/tacomeat.lua:
>
> > @@ -0,0 +1,20 @@
> > +return{
> > +    name = 'tacomeat',
> > +    type = 'consumable',
> > +    MAX_ITEMS = 10,
> > +    use = function( consumable, player )
> > +        local Timer = require('vendor/timer')
> > +        local sound = require('vendor/TEsound')
> > +        for i=1,10 do
> > +            Timer.add(i, function ()
> > +                player.health = player.health - 1
> > +                sound.play('/audio/sfx/damage.ogg')
> > +            end)
> > +        end
> > +        Timer.add(10, function ()
> > +            pcall(player.character.setCostume, player.character, 'zombie')
>
> As far as I can tell, the only place that there is a check to see whether
> the character has a costume is inside character:setCostume. I could
> duplicate that functionality elsewhere, but it already does exactly what I
> need. This is the error it throws if it fails to return after successfully
> changing the costume.
> error( "Undefined costume ( " .. costume .. " ) requested for character (
> " .. self.name .. " )" )
>
> —
> Reply to this email directly or view it on GitHub<https://github.com/hawkthorne/hawkthorne-journey/pull/1372/files#r4129929>
> .
>