-
Notifications
You must be signed in to change notification settings - Fork 17
Farm Code Examples
JoeStrout edited this page Jan 10, 2022
·
2 revisions
The farm
module contains methods to get information about the farm. In particular, you can use farm.width
and farm.height
to know how big the farm is, and then call farm.tile(x,y)
to get information about any objects or terrain features at position x,y. (This will return null
for empty, unimproved ground.)
This example scans the entire farm, counting how many times each type of thing (Weeds, Stone, Twig, Tree, Grass, etc.) appears.
// Farm info
counts = {}
total = 0
for x in range(0, farm.width)
for y in range(0, farm.height)
t = farm.tile(x,y)
if not t then continue
if counts.hasIndex(t.name) then
counts[t.name] = counts[t.name] + 1
else
counts[t.name] = 1
end if
total = total + 1
end for
end for
pprint counts
print "Total features: " + total