self.memory[to_recognize:token()] = 1 -- or whatever we need to remember about this character -- sometime later: if self.memory[candidate:token()] then -- stuff end -- or if some_token:equals(candidate_char) then -- stuff endIn this example, the
token()
method returns a userdata with the same C pointer as the character, but with a different tag. This new type has no member besides equals()
, which returns true if the argument is the same token or the character it represents. It represents well in savefiles, since userdata is saved separately from the C structure it refers to. Fundamentally tokens aren't any different from UIDs, but the interface is a little more focused (a token is nothing but a token to scripts, where a UID is both a number and a reference to a character) and the implementation is sparser (the memory allocator takes care of generating the IDs and releasing them, and nothing needs to get saved with the character, since its index in the savefile effectively becomes its UID). We should still protect the character methods against inappropriate use, and characters will still need to retain references (the soul-binding thing is a good example of where this would happen), but this encourages scriptwriters to separate the active referencing of a character for continuing interaction from the long-term recognition problem.
-- ElminI - 25 Oct 2004
Topic CharacterPersistence . { Edit | Attach | Ref-By | Printable | Diffs | r1.11 | > | r1.10 | > | r1.9 | More } |
Revision r1.11 - 25 Oct 2004 - 18:19 GMT - ElminI Parents: WebHome |
Copyright © 1999-2003 by the contributing authors.
All material on this collaboration platform is the property of the contributing authors. Ideas, requests, problems regarding EgoWiki? Send feedback. |