To keep references of pcs within other pcs I have been just storing their tag, which I set to equal their key when they log in. Then if I need a reference to the actual pc, I use locate(Tag). Somehow this just seems "cleaner" than storing the actual object reference. I'm probably wrong, but that's how I like to code it, dammit!
According to the DM reference, locate() works with:
locate(Type) in Container
locate(X,Y,Z)
locate(Tag)
locate(TextRef)
So my question is, how come there isn't a more direct way to get an object reference by key? Shouldn't the keys be unique?
ID:137905
Jun 14 2001, 4:34 am
|
|
In response to Dan
|
|
On 6/14/01 11:03 am Dan wrote:
I thought about automatically making mob.tag = mob.key, but the problem is that this might interfere with tags the programmer is using internally. I suppose some sort of naming convention such as "key=[ckey]" might be possible. Yeah please don't...this would definitely be problematic in a game like Living & Dead, where players are mob-switching all over. |
In response to Deadron
|
|
Yeah please don't...this would definitely be problematic in a game like Living & Dead, where players are mob-switching all over. I agree with you, Ron... but: Speaking of mob switching, I absolutely hate anyone who puts their logout messages in the topmost mob class when switching is a possibility. If you ever change mobs, EVER (and that includes using Deadron's CharacterHandling demo), make your players a subclass of /mob and then put the Logout() proc there. Or, do what I do, only give "Player has logged out!" messages in the client/Del() proc. Otherwise, you'll be getting "Player has logged out!" when in actuality he just switched bodies. |
I thought about automatically making mob.tag = mob.key, but the problem is that this might interfere with tags the programmer is using internally. I suppose some sort of naming convention such as "key=[ckey]" might be possible.
Otherwise, you could create a list of players with the items in the list being the player keys and the associated values being the mobs. Example:
That would give you fast lookups.