Receiving Error that animation does not exist when animation is in animation tab

Hello! One of my students’ code is giving the error “ERROR: Line: 36: Error: Unable to find an animation named “coats.” Please make sure the animation exists.”
I cannot figure it out since they have do have that animation in the animation tab, we copy and pasted the name.
Here is the code link: Game Lab - Code.org

hello @kendra.thompson,

Solution

I think you’ll be glad to know that this isn’t a bug and I’ll provide a more technical evaluation bellow which will help explain why this change is necessary though I’m not sure if you’ll understand why

function setup() {
  b = createSprite(200, 200);
  b.setAnimation("blda title.jfif_1");
  b.scale = 2;
  coat1.setAnimation("coats");
  coat2.setAnimation("coats");
  drawSprites();
}

this will set the animations appropriately

Why the heck was this not working?

As you know of gamelab is a wrapper from the library p5play, this library allows for simple integration for what it takes to run a simple game, however there are certain functions that can cause a race condition which will force the program to error out, we can view this via using

console.log(Game.pInst._predefinedSpriteAnimations)

if you’ve included either preload() or setup() this will give undefined due to it having the callback no longer be set to the interpreter to pause the program until all the animations are loaded in, of course there are ways of loading them in yourself but that’s way much more work and you’d need a preload and the current setup loop you have to match it… that or you could just get rid of the setup loop entirely and let the interpreter halt the program until the animations are loaded in

Varrience

Ah - yes. Using @varrience’s tip, if you remove the setup() function and move all the sprite info for the “b” sprite out of the setup function (I just moved it all to the top after your other var declarations), and remove the function call for setup(), the program runs.

~Michelle