logo       

Re: More than 256 literals referenced.: msg#00136

lang.smalltalk.squeak.beginners

Subject: Re: More than 256 literals referenced.

The limit is 256 literals per method. However, a literal array is
still just one literal. So you can put all your data into one literal
if you want:

#((
value 2
cost -3
step 2
defense 3
combatMove 7
fullMove 14
carry 10
lift 20
death 20
unconscious 11
woundThreshold 4
recovery 05
mysticArmor 0
) (
value 2
cost -3
step 2
defense 3
combatMove 7
fullMove 14
carry 10
lift 20
death 20
unconscious 11
woundThreshold 4
recovery 05
mysticArmor 0
) )

Then just iterate over it (#do: for the outer array, #pairsDo: is
handy for the inner) to construct your objects. Btw, you surely would
like to make a class and not just use dictionaries ;)


256 literals per method seems find to me, initializing such a large
dictionary was unusual for me and something of an experiment (mainly
to avoid reading from a file at all). I had the data in YAML that I
just wrote a small script to generate smalltalk code from.

I didn't make a class mainly because I don't need the data for
anything more than lookups dictionaries give me. I'll give your
suggestion above a try but might just convert the YAML to XML or CSV
and read the table in from the file. Maybe as an array of RecordEntry
instead of using a dictionary.

I will have a need for a database (or some persistence layer) later in
the project, so might just bite the bullet now.

Thanks,
Robert


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise