Have a problem a instance of one sprite could not be found when dispatching animation from instance of another script

What does the code look like? And the structure of your game objects? Where is the script calling sprite.play_flipbook() and where is the sprite?


this is the code for swarm movement:


this is the main collection
image

Your play_animation function is global, which is likely causing issues. I am guessing that your player script also has a play_animation function. One of these is overwriting the other.

Review this section of the docs (I linked to the scope section): Lua programming in Defold

Long story short, you want to declare it as:

local function play_animation(self, animation)

Not:

function play_animation(self, animation)

Note also that the function will need to be placed above where it is called, otherwise you will get an error about the function being nil or undeclared. For example:

	local function play_animation(self, animation)
		--do stuff
	end

	function init(self)
		play_animation(self, "idle")
	end

Not:

	function init(self)
		play_animation(self, "idle")
	end

	local function play_animation(self, animation)
		--do stuff
	end

I’m not sure this is your only issue, but it’s likely part of it.

Also, in the future, please post code as text rather than screenshots. It’s easier to read and work with. Wrap it in three of these symbols ` on either side like this:
```
code here
```

4 Likes