Thank you **andrea**.

I like your _variant_ but _match_ is for me similar in verbosity to my getText 
and I think it could be compressed further.

My attempt:
    
    
    import patty
    
    variant Message:
        hit(hp: int)
        death(died: string)
    
    proc hhit(m: Message) = echo "HIT " & $m.hp
    proc hdeath(m: Message) = echo "DEATH" & m.died
    
    template choose(t: typed, handlers: tuple) =
        #var x = ord(t.kind)
        #handlers[x]() # - compilation error: cannot evaluate at compile time
        case ord(t.kind)
            of 0: handlers[0](t)
            of 1: handlers[1](t)
    
    proc test() =
        var h = hit(5)
        choose(h, (hhit, hdeath))
    
    
    test()
    

It works nice, but I cannot overcome problem with variable amount of handlers.

Thank you **flyx**.

When death message is dispatched entity is already removed so having ID I would 
not be able to fetch name, and you will have to make string somewhere anyway to 
display it - so this is not my concern.

Your solution is also very interesting.

Reply via email to