mob
var/HP,Gold
The standard DM way of modifying these variables would be something like:
proc/luckyDay(mob/M)
M.HP += 5
M.Gold += 5
Whereas, with accessors you'd define more functions and the same method would look like this:
mob/proc
getHP()
return HP
setHP(_HP)
HP = _HP
getGold()
return Gold
setGold(_Gold)
Gold = _Gold
proc/luckyDay(mob/M)
M.setHP(M.getHP()+5))
M.setGold(M.getGold()+5)
Now, this looks like a waste of code, which was certainly what I thought when I first learned other languages (since I learned DM first), but in reality there are some benefits. Like having control over the possible values for variables. You could put an if statement in the setGold to check that Gold isn't negative.
Now, obviously, I think some people do use these sort of functions in DM, but I've never heard of someone defining accessors for virtually all of their variables. Would it be worth all the extra functions for the peace of mind that each variable isn't going to have some strange value?
Another random thought is that it might be useful if there was a way to call these functions generically, and I'm not sure that's possible. Is there really a programmatic way to call functions in DM? Assuming you kept to a naming convention for the accessors, otherwise it'd be next to impossible.
I feel like this could be better done by doing something like this, but really, I only like that approach in DM (it seems more fitting than accessors, because we don't have private/public). I agree with you on stronger variable control, but that can be wrapped up in a nice datum.
I don't think so. In a language where you can go Object.getMyVariable().variableMethod(), I find it beneficial. Since DM doesn't let you, it just doesn't seem worth it, since you have to typecast it, or store it somewhere before you can use it, in the case of an object type.
I think you can use call() to call procs with arguments -- call("proc")("procarg1","procarg2") if I'm not mistaken.