In Lua, you can only access local variables in your area. In order for other functions to see your variables, you will need to rewrite them so that the protected variables are in a table accessible by the child class.
One way to do this is to simply make the properties publicly available in the current class and use naming conventions (e.g. names starting with underscores) to denote protected things. You probably know this, but I have to say that I think that this approach is usually much easier to implement than real protected variables.
If you need real protected variables, you need to separate the table from public and protected materials. One approach is to change the blessing function so that it receives both of these tables:
function infested_mariner.bless (pub, pro) -- New methods: function pub.strongerheal (value) pro.hp = pro.hp + value*2 end return pub end
How to set things up so that the designers pass the protected table to each other remains an exercise. If you are following this route, you probably want some function to execute it for you, so that you cannot instantly touch the protected table.
source share