Subject: identical oid's in YAML db file
Author: Massaria
Posted: 01/12/2006 08:54PM
Just a minor one I believe, doubt if it would mess anything up really.
Still, here goes.
While attempting to set my evolution/gene stuff up in a seperate file (been pouring it into Class:Player), I got booted many times during the initialization of Player.
Player.new:
def initialize(name,passwd,session)
@session = session
@passwd = encrypt(passwd)
super(name,$engine.world.options.home)
@powered = true
@color = false
...
@genome = {}
Genes.add_new_chrom(@genome, "symmetry")
...
end
my resulting yaml file:
---
- !ruby/object:Room
contents:
- 2
- 2
- 2
- 2
- 2
- 2
- 2
- 2
- 2
- 2
- 2
- 2
- 2
- 3
desc: This is home.
exits: {}
farts: {}
location:
name: Home
oid: 1
- !ruby/object:Player
...
heh. I'm actually quite surprised I've even found a glitch - it really is the most stable code I've come across (it's not that many, but still).
Not sure if this is worth bothering with, as players really shouldn't get booted even before they log in - but as it happens, this gives me the opportunity to ask why it couldn't find my new file, or rather the methods within the Genes class, located in that file.
my genes.rb file:
public
class Genes
attr_accessor :seq, :taxon, :chrom, :title
public
def initialize
@seq = ""
@taxon = ""
@chrom = ""
@title = ""
end
def to_s
@chrom
end
def add_new_chrom(var, chrom)
if var.class == Hash
var.store(chrom, [])
else
var.push(chrom)
end
end
end
def add_new_chrom(var, chrom)
if var.class == Hash
var.store(chrom, [])
else
var.push(chrom)
end
end
As you can see I've gone to great lengths to make add_new_chrom visible from Player.initialize - but I'm sure it's the last definition it uses, and I'd like to use the one inside the class - just to keep it neat :-)
Anyways,
Songs & Somersaults from
Mass.
_____
EDIT:
AHA!
Class methods which are meant to be used outside the class itself should be prefixed with the class name, like this:
Class Genes
def Genes.add_new_chrom(var, chrom)
...
end
end
Not sure if that's an entirely accurate way of putting it, but it works now.
Yay :-)
reply
Subject: identical oid's in YAML db file
Author: Tyche
Posted: 01/13/2006 01:05AM
Massaria wrote:
> Player.new:
> def initialize(name,passwd,session)
> @session = session
> @passwd = encrypt(passwd)
> super(name,$engine.world.options.home)
> @powered = true
>
> @color = false
>
> ...
> @genome = {}
> Genes.add_new_chrom(@genome, "symmetry")
> ...
> end
>
The super() calls the parent
GameObject#initialize to fill in the @oid and @location of the player. This line in
GameObject adds the object to contents of the location (the home room for Players): $engine.world.db.get(location).add_contents(oid)
If the player can't be constructed because of some error later in Player#initialize then the contents of the home Room would still have its contents updated.
So........
What I've done for the next release is remove the line from
GameObject and have account.rb and cmd_object.rb (OLC) to do it. And only if the player/object actually gets created. If there's a problem I log it as an error, and send a message to the player and put them back at them prompt. I also put double checks in
GameObject#add_contents and
GameObject#delete_contents to log errors if the an object is unexpectantly already in (or isn't in) the contents.
Hopefully it be bullet-proof now!
reply