Let’s do some messages.

I have to spend a bit of time in front of the computer, for a meeting that won’t require much attention. Let’s add some amusing messages to the system, at least for Chests and Mimics.

Messages on Decor are in a table:

local DecorMessages = {
    Skeleton1={
    "Yorick: Hamlet? Is that you?",
    "Appears to be some kind of hominid remains.",
    "He's dead, Princess",
    "Bones. Dry, dead, bones.",
    "Seems to have an ID tag ... 'Adventurer something`.",
    "There's a skull. Could be a dead'un. Not sure ...",
    "This fellow's in bad shape, Princess.",
    },
    Skeleton2={
    "Femur, tibia, ..., monster picnic, I'd guess.",
    "Something bad may have happened here. Just guessing.",
    "I believe someone took a bad fall here.",
    "Poor fellow. I wonder if he had anything good when he passed.",
    },
    Chest={
    "Seems to be a chest."
    },
...

Let’s see how a Mimic might do its messages.

Monster.mimicBehavior = {
    query=function(mimic) 
        if mimic.awake then
            return "HAHAHA!!! I'm a MIMIC!!!"
        else
            return"I am probably a mysterious chest."
        end
    end,
    flip = function(mimic) if mimic.awake then mimic:flipTowardPlayer() end end,
    drawSheet = function(mimic) if mimic.awake then mimic:drawSheet() end end,
    isActive = function(mimic) return mimic.awake and mimic:isAlive() end,
}

We’ll want them both to have the same messages, for maximum confusion. So first, let’s get Mimic to pick randomly from a list. We can probably crib from Decor, but it’s pretty simple:

function Decor:queryMessagesPrivate()
    local answers = DecorMessages[self.kind] or {"I am junk.", "I am debris", "Oh, just stuff.", "Well, mostly detritus, some trash ..."}
    return answers[math.random(1,#answers)]
end

So in Mimic, let’s do this …

Monster.mimicBehavior = {
    query=function(mimic) 
        local answers
        if mimic.awake then
            answers = {"HAHAHA!!! I'm a MIMIC!!!"}
        else
            answers = {"I am probably a mysterious chest."}
        end
        return answers[math.random(1,#answers)]
    end,
    flip = function(mimic) if mimic.awake then mimic:flipTowardPlayer() end end,
    drawSheet = function(mimic) if mimic.awake then mimic:drawSheet() end end,
    isActive = function(mimic) return mimic.awake and mimic:isAlive() end,
}

And now to think of some amusing things to say:

Monster.mimicBehavior = {
    query=function(mimic) 
        local answers
        if mimic.awake then
            answers = {
                "HAHAHA!!! I'm a MIMIC!!!",
                "As is now clear, I'm a Mimic!",
                "As a Mimic, I advise you to RUN!",
            }
        else
            answers = {
                "I am probably a Mysterious Chest.",
                "This seems to be a Mysterious Chest.",
                "Box shape, metal binding, rounded top. Possible Chest.",
                "Possibly a treasure Chest. Possibly not.",
                "What does it look like? Maybe that's what it is.",
                "You may have discovered a large Chest.",
                "If I had to guess, I'd say 'Mysterious Chest'."
            }
        end
        return answers[math.random(1,#answers)]
    end,
    flip = function(mimic) if mimic.awake then mimic:flipTowardPlayer() end end,
    drawSheet = function(mimic) if mimic.awake then mimic:drawSheet() end end,
    isActive = function(mimic) return mimic.awake and mimic:isAlive() end,
}

But if I were to transfer those messages to Decor, it would amount to duplication. Instead, let’s move them to Decor …

local DecorMessages = {
    Skeleton1={
    "Yorick: Hamlet? Is that you?",
    "Appears to be some kind of hominid remains.",
    "He's dead, Princess",
    "Bones. Dry, dead, bones.",
    "Seems to have an ID tag ... 'Adventurer something`.",
    "There's a skull. Could be a dead'un. Not sure ...",
    "This fellow's in bad shape, Princess.",
    },
    Skeleton2={
    "Femur, tibia, ..., monster picnic, I'd guess.",
    "Something bad may have happened here. Just guessing.",
    "I believe someone took a bad fall here.",
    "Poor fellow. I wonder if he had anything good when he passed.",
    },
    Chest={
        "I am probably a Mysterious Chest.",
        "This seems to be a Mysterious Chest.",
        "Box shape, metal binding, rounded top. Possible Chest.",
        "Possibly a treasure Chest. Possibly not.",
        "What does it look like? Maybe that's what it is.",
        "You may have discovered a large Chest.",
        "If I had to guess, I'd say 'Mysterious Chest'."
    },

Then let’s change Decor to have a message selector:

We have this function:

function Decor:queryMessagesPrivate()
    local answers = DecorMessages[self.kind] or {"I am junk.", "I am debris", "Oh, just stuff.", "Well, mostly detritus, some trash ..."}
    return answers[math.random(1,#answers)]
end

Let’s replace it with a public method:

function Decor:queryMessage(kind)
    local answers = DecorMessages[kind] or {"I am junk.", "I am debris", "Oh, just stuff.", "Well, mostly detritus, some trash ..."}
    return answers[math.random(1,#answers)]
end

This all works nicely. I changed one test to use the new function. Commit: Chests and Mimics now use the same query messages.

So, that was fun. Let’s ship the code and the article.