I am having Trouble passing the data to the factory created game objects. I Have them reporting into the script and storing them into a table. But I can’t seem to get them out of the table I get an error of unknown instance. I spent hours with trial and error.
> local acc = require "in.accelerometer"
>
> function init(self)
> msg.post(".", "acquire_input_focus")
> self.ball_id = {}
> self.height = tonumber(sys.get_config("display.width", 0))
> self.width = tonumber(sys.get_config("display.height", 0))
> window.set_listener(function(self, event, data)
> if event == window.WINDOW_EVENT_RESIZED then
> acc.on_window_resized(data.width, data.height)
> self.width = data.height
> self.height = data.width
> end
> end)
> acc.calibrate()
> end
>
> function on_input(self, action_id, action)
>
> if not action.acc_x then
> local action_pos = vmath.vector3(action.x, action.y, 0)
> if action.pressed then
> self.drag = true
> action.dx = 0
> action.dy = 0
> acc.calibrate()
> elseif action.released then
> self.drag = nil
> acc.calibrate()
> end
>
> if self.drag then
> local diff = action_pos - vmath.vector3(self.width / 2, self.height / 2, 0)
> action.acc_x = diff.x / (self.height / 2)
> action.acc_y = diff.y / (self.width/ 2)
> action.acc_z = 0
> else
> action.acc_x = 0
> action.acc_y = 0
> action.acc_z = 0
> end
> acc.on_input(action)
> else
> --action.acc_x, action.acc_y = action.acc_y, action.acc_x
> --action.acc_x = action.acc_x * -1
> acc.on_input(action)
>
>
>
> end
> end
>
> function final(self)
> acc.reset()
> end
>
>
> local function update_label()
> local avg = acc.average()
> local zero = acc.zero()
> local latest = acc.latest()
> local calibrated = acc.calibrated()
> local adjusted = acc.adjusted()
>
> local info = ([[
> Average (%.3f),(%.3f),(%.3f)
> Zero (%.3f),(%.3f),(%.3f)
> Latest (%.3f),(%.3f),(%.3f)
> Calibrated (%.3f),(%.3f),(%.3f)
> Adjusted (%.3f),(%.3f),(%.3f)
> ]]):format(
> avg.x, avg.y, avg.z,
> zero.x, zero.y, zero.z,
> latest.x, latest.y, latest.z,
> calibrated.x, calibrated.y, calibrated.z,
> adjusted.x, adjusted.y, adjusted.z
> )
> label.set_text("info#label", info)
> end
>
> function update(self, dt)
> update_label()
> local adjusted = acc.adjusted()
> local force = adjusted * 100000 * dt
>
> if self.ball_id ~= nil then
> for _, value in pairs(self.ball_id) do
> do
> print(value)
>
> msg.post(value, "#apply_force", { position = go.get_world_position(), force = force })
> --msg.post(msg.url(nil, value, "#apply_force"), { position = go.get_world_position(), force = force })
> end
>
>
> end
> end
> end
>
> function on_message(self, message_id, message, sender)
> if message_id==hash("report_in") then
> table.insert(self.ball_id, sender)
> end
> end
> function on_reload(self)
> -- Add reload-handling code here
> -- Remove this function if not needed
> end