[BUG] Access Method returning Incomplete Tuple
See original GitHub issueThe Bug
Familiarising myself with Evennia, I was running through the First Steps coding tutorial. As documented, I re-wrote the at_object_creation
function in the Character
class to assign 3 persistent ability attributes (self.db.strength, self.db.agility, self.db.magic) the values of 5, 4, and 2 respectively. Then, I wrote a function to return those values as a tuple.
When I @reload
, @update
, and call this function in-game, however, it only returns the first element, 5. The entries exist in the database, confirmed with @examine self
, and the values can be printed and indexed from the tuple.
Input
In typeclasses.characters, as found in the documentation:
def at_object_creation(self):
"""
Called only at initial creation. This is a rather silly
example since ability scores should vary from Character to
Character and is usually set during some character
generation step instead.
"""
#set persistent attributes
self.db.strength = 5
self.db.agility = 4
self.db.magic = 2
def get_abilities(self):
"""
Simple access method to return ability
scores as a tuple (str,agi,mag)
"""
return self.db.strength, self.db.agility, self.db.magic
Expected Result
@py self.get_abilities()
*>>> (5, 4, 2)
Evennia correctly returns all elements in the tuple corresponding to persistent data.
Actual Result
reload
Server restart initiated …
… Server restarted.
update rainboa
rainboa updated its existing typeclass (typeclasses.characters.Character).
Only the at_object_creation hook was run (update mode). Attributes set before swap were not removed.
py self.get_abilities()
>>> self.get_abilities()
5
examine self
Name/key: rainboa (#1) Session id(s): #1 Account: rainboa Account Perms: <Superuser> Typeclass: Character (typeclasses.characters.Character) Location: Limbo (#2) Home: Limbo (#2) Permissions: developer [Superuser] Locks: … Commands: … Persistent attributes: desc = This is User #1. prelogout_location = Limbo strength = 5 agility = 4 magic = 2
Steps Taken
I have:
- Tried this on a clean database.
- Tried this on a new character.
- Reproduced this in Linux and Windows.
- Experimented with writing different functions that do the same thing.
- Experimented with making the attributes non-persistent.
Systems Information
OS
- Windows 10Ver1909 (64-bit) build 18363.592
- Debian GNU/Linux 10
Python, Evennia, Etc
Evennia version: 0.9.0 (rev 798cacc2) OS: nt Python: 3.8.1 Twisted: 19.10.0 Django: 2.2.9
Issue Analytics
- State:
- Created 4 years ago
- Comments:15 (11 by maintainers)
Top GitHub Comments
@Oscuro87
Even though that wasn’t the issue in this case, this is still a fair concern to be wary of in any Python codebase that was ever ported from 2.x to 3.x. There are quite a few subtle syntactical gotchas that were introduced in that migration, affecting even basic mechanics like how the division operator works 😕
True, I even remember when I first came across python 3, and all my
print "some string"
suddenly died 🤣. Thankfully the error message was developer friendly IIRC.