Hey folks, finished the getting started tutorial but have an issue, when the character dies the app resets as it should by deleting the platforms and he drops back in to start again but I have coin remnants floating above the ground at the start. Checked the forum and been through the code umpteen times can’t find the issue, did anyone else have this? see screenshot:
1 Like
Could you please post the platform.script here? The platform script should be responsible for creating coins and deleting them when the platforms themselves are deleted. I’m guessing that something goes wrong when the platform is deleted.
Here is the code:
function init(self)
self.speed = 9 -- default speed
self.coins = {}
end
function final(self)
for i,p in ipairs(self.coins) do
go.delete(p)
end
end
function update(self, dt)
local pos = go.get_position()
if pos.x < -500 then
msg.post("/level/controller#script", "delete_spawn", { id = go.get_id() })
end
pos.x = pos.x - self.speed
go.set_position(pos)
-- print (pos)
end
function create_coins(self, params)
local spacing = 56
local pos = go.get_position()
local x = pos.x - params.coins * (spacing*0.5) - 24
for i = 1, params.coins do
local coin = factory.create("#coin_factory", vmath.vector3(x+i*spacing, pos.y+64, 1))
msg.post(coin, "set_parent", {parent_id=go.get_id()})
msg.post(coin, "start_animation", { delay = i/10})
table.insert(self.coins, coins)
end
end
function on_message(self, message_id, message, sender)
if message_id == hash("set_speed") then
self.speed = message.speed
elseif message_id == hash("create_coins") then
create_coins(self, message)
end
end
If you put your code within
```lua
code goes here
```
It will make it look nicer.
1 Like
This is wrong. It should be:
table.insert(self.coins, coin)
Thanks that fixed it, second pair of eyes helps I must have read through line by line 5 times and missed it.
2 Likes