![]() |
Subject: Re: bugs in saving/loading attributes methods?
From: Pierre Bommel (bommel@cirad.fr)
Date: Thu Mar 30 2006 - 00:21:09 CEST
Hello Geraldine,
> Hello,
>
> I am currently trying to use the default CormasModel methods for
> saving/loading attributes of entities (saveAttributes: attributes
> fromClass: aClass inFile: aStringOrFilename separator: aChar and
> loadAttributesForClass: aClass fromFile: aStringOrFilename).
> It seems that what the methods are writting do not correspond to what
> the methods are supposed to read, I allways come out with a 'Wrong
> File' error.
> I have already been fighting for one hour trying to redefine the
> methods so that the good thing is written but I get discouraged!
Well few people use this and the bug was sleeping for a while...
> Also the saveAttributes method is appending instead of writting over,
> I don't know whether it is normal.
No it is not !
It should rather be :
stream := filename writeStream.
> I don't know whether some of the methods are obsolete and maybe one of
> you already made a nice patch so these things work correctly!
...hmmm, here is the "nice patch" !
Then, an example to save :
self saveAttributes: (OrderedCollection with: 'energy' with: 'bidon')
fromClass: RestrainedForager inFile: 'titi.csv'.
And an example to load :
self loadAttributesForClass: RestrainedForager fromFile: 'titi.csv'
By the way, you can also save and load your agents (AgentLocation or
ObjectLocation) by using "saveLocatedAgent: withAttributs: inFile:" and
"createAndLoadAttributesFromClass: fromFile:". Ex :
self saveLocatedAgent: RestrainedForager withAttributs:
(OrderedCollection with: 'energy') inFile: 'restrained.csv'."
and
self createAndLoadAttributesFromClass: RestrainedForager fromFile:
'restrained.csv'.
T'chaooo,
Pierre
Pierre Bommel - CIRAD - UR Green
Universidade de Brasilia - CDS
SHIS QI 26, Conjunto 15, Casa 18
71670-150
Brasilia DF
tel: (00 55 61) 3367 3405
http://www.cirad.fr/ur/green