Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function onLoad()
- Wait.time(countItems, 2.0, -1)
- end
- function countItems()
- local bounds = self.getBounds()
- local vertical_bound = 1
- local hits = Physics.cast({
- origin = {
- x = bounds.center.x,
- y = bounds.center.y + bounds.size.y + vertical_bound / 2,
- z = bounds.center.z,
- },
- direction = {0, 0.001, 0},
- type = 3,
- size = {
- x = bounds.size.x,
- y = vertical_bound,
- z = bounds.size.z,
- },
- orientation = self.getRotation(),
- max_distance = 1,
- --debug = true
- })
- -- tally token totals
- -- A table that defaults to 0, and each object's name is matched for "amount label"
- total = {}
- for i, v in pairs(hits) do
- name = v.hit_object.getName()
- if name != nil then
- amount, label = string.match(name, '(%d+) (%a+)s?')
- total[label] = (total[label] or 0) + amount
- end
- -- v.hit_object.highlightOn({0, 1, 0}, 10)
- end
- for k, v in pairs(total) do
- print(v, ' ', k)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment