Help with adding points and < >

I have a student that is trying to add points when her bee flys through two rocks. She has an if statements set up and tried doing it with if fly.x=210 then score = score + 1. This would not work. We changed it to fly.x > 210 then score = score + 1. This worked somewhat, but the score kept increasing. It is almost like we need to say something like fly.x >209 but < 211. Is there a way to do this?

Hope this makes sense.

Thank you!

Could you post the code so we can look at it?

Here is a copy of the code. Looks like she tried adding somethings today, while she was home as well.

// Variables
var score = 0;
var mtn = createSprite(200, 200);
mtn.setAnimation(“mtn”);
mtn.scale = 2;

// Create your sprites here
var fly = createSprite(20, 140);
fly.setAnimation(“fly1”);
fly.scale = .5;
var rock1 = createSprite(200, 20);
rock1.setAnimation(“rock1”);
rock1.scale = .9;
var rock = createSprite(200, 299);
rock.setAnimation(“rock”);
rock.scale = .9;
rock1.setAnimation(“rock1”);
rock1.scale = .9;
var rock = createSprite(190, 375);
rock.setAnimation(“rock”);
rock.scale = .9;
var rock1 = createSprite(245, 45);
rock1.setAnimation(“rock1”);
rock1.scale = .9;
var rock = createSprite(190, 390);
rock.setAnimation(“rock”);
rock.scale = .9;
var rock1 = createSprite(282, 55);
rock1.setAnimation(“rock1”);
rock1.scale = .9;
var rock = createSprite(270, 360);
rock.setAnimation(“rock”);
rock.scale = .9;
var rock1 = createSprite(112, 39);
rock1.setAnimation(“rock1”);
rock1.scale = .9;
var rock = createSprite(95, 299);
rock.setAnimation(“rock”);
rock.scale = .9;
var rock1 = createSprite(360, 85);
rock1.setAnimation(“rock1”);
rock1.scale = .9;
var rock = createSprite(3, 300);
rock.setAnimation(“rock”);
rock.scale = .9;
var rock = createSprite(370, 370);
rock.setAnimation(“rock”);
rock.scale = .9;
drawSprites();
function draw() {
showScore();
myFunction();
movePlayer();
// draw background
addPoints();
points();
isToching();
//createSprites

}

// Create your functions here
function isToching() {
if (fly.isTouching(rock)) {
fly = fly.collide(rock);
}
if (fly.isTouching(rock1)) {
fly = fly.collide(rock1);
}
}
function points() {
if (rock.isTouching(fly)) {
score = score - 1;
}
if (rock1.isTouching(fly)) {
score = score - 1;
}
}
function myFunction() {
if (score == 30) {
var golden = createSprite(200, 200);
golden.setAnimation(“golden”);
golden.scale = 2;
}
}
function addPoints() {
if (fly != 370) {
fly = score + 30;
}
}
function showScore() {
fill(“white”);
textSize(20);
text(“Score”,20,20,200,100);
text(score,20,40,200,100);
}
function movePlayer(){
if (keyDown(“right”)) {
fly.x = fly.x + 3;
}
if (keyDown(“left”)) {
fly.x = fly.x - 3;
}
if (keyDown(“up”)) {
fly.y = fly.y + -3;
}
if (keyDown(“down”)) {
fly.y = fly.y + 3;
}

Sarah,

Sorry to ask more of you, but could you click on the “share” button and share the code that way? I tried copying it into an empty GameLab and the student uses so many animations that its giving me a lot of warnings/errors, once I worked through adding the animations I’m getting this error Error: overlap can only be checked between sprites or groups but my code still doesn’t work. Does the game work just with the exception of the points?

Looking forward to figuring this out!
Brad