Using % in Game Lab


#1

I have a student who is diving deep into her interactive card and she has me stumped! Can anyone offer help?

Does the % code work in gamelab? We are not sure if there is a bug in the code or if it is outside the scope of gamelab. I have included her description of the problem below:

I have a variable titled "time" that gets updated in this draw loop (time = time + 1;), and I want the sprite to change when the "time" variable is divisible by 5, using %.

if (time%5===0 && fire1.setAnimation("fire")) {

fire1.setAnimation("fire2");

fire2.setAnimation("fire2");

text("wow", 10, 390);

}

if (time%5 ===0 && fire1.setAnimation("fire2")) {

fire1.setAnimation("fire");

fire2.setAnimation("fire");

}


#2

Can you click the share link and paste the URL to the project here?

Also, what is the bug that she is experiencing?


#3

https://studio.code.org/projects/gamelab/3A4R1jqSvUHHHqUFVJxcaHBFyWESJvMao-KSEutRc4g

I’m not sure that I fully understand the bug, other than it did not work as she hoped. She said that she doesn’t think the % command works in game lab, but I am not familiar with what the % command does in javascript. I think she ended up working around it, so I do not believe this section of code is in her current program.


#4

Hi Sean,

The % operator does work in Game Lab, but it looks like she is trying to use the setAnimation method as a Boolean, which does not work. setAnimation will change a sprite’s animation, not return true or false depending on what its animation is.

Elizabeth