Need help with tutorial (Solved)

I’m going through the War Battles tutorial and an error that I do not understand is occurring. I’m currently at the “Make the rockets explode” part of the guide. Whenever I build the project and fire a rocket that is supposed to trigger an explosion, this error message pops up:
ERROR:GAMEOBJECT: Component ‘/instance0#sprite’ could not be found when dispatching message ‘play_animation’ sent from main:/instance0#rocketcode
The line of code that triggers this error is as follows:
sprite.play_flipbook("#sprite", “explosion”)
I don’t know what is going wrong here because I’ve been messing around a little and have been able to get this line to work and trigger the explosion the player script, but whenever I try to execute it in the rocket script, it just gives me the same error message.

Perhaps you are deleting the rocket at the same time as playing the animation? Can you share the code here?

Here is the code for the rocket object:

go.property("dir", vmath.vector3())                 -- [1]

function init(self)
	self.speed = 200                                -- [2]
	self.life = 1
end

function update(self, dt)
	local pos = go.get_position()                   -- [3]
	pos = pos + self.dir * self.speed * dt          -- [4]
	go.set_position(pos)                            -- [5]

	self.life = self.life - dt                              -- [1]
	if self.life < 0 then                                   -- [2]
		self.life = 1000                                    -- [3]
		go.set_rotation(vmath.quat())                       -- [4]
		self.speed = 0                                      -- [5]
		sprite.play_flipbook("#sprite", "explosion")
	end
end
function on_message(self, message_id, message, sender)      -- [1]
	if message_id == hash("animation_done") then            -- [2]
		go.delete()                                         -- [3]
	end 
end

And your rocket hierarchy? Does it have a #sprite component with that name?

Sorry, I don’t understand what you mean by hierarchy?
In terms of the sprite components here is a screenshot of the atlas that the sprite is contained on.

No, sorry, I mean the rocket’s hierarchy. The gameobject, which has this script and should also have a sprite component :slight_smile:

Oh, here is a screenshot of the object.

Since you named the rocket’s sprite component rocket, the line of code should be:

sprite.play_flipbook("#rocket", "explosion")

and not:

sprite.play_flipbook("#sprite", "explosion")

Ah, I see. Thank you for the help.

1 Like