Where is 'e' meant to come from? The function does not take parameters which is strange (working only with global variables makes code harder to understand and to change).
We don’t have much info to understand the situation here.
Can you share more code and, most importantly the exact error message? Or even upload the cart.
Is this rat variable defined beforehand? Should you be passing e as a parameter to this function perhaps? What exactly is the error message? Why not have e.name be the enemy name instead of an integer?
From what I understand, I think you may have forgotten to define variable, rat. If a variable hasn't been set to a value, your Namer function will print [nil].