Thunderhooves, I need help


#1


#2


#3

yak.pos.y > hero.pos.y;
should be
if(yak.pos.y > hero.pos.y) {


#4

I tried it too, look


#5


#6

As of your latest screenshot, you have an else if that isn’t attached to an if.
It should be more like:

if(yak) {
    if( yak position is greater than hero position ) {
        // build a fence 10 units down
    } else if( yak position is less than hero position ) {
        // build a fence 10 units up
    }
} else {
    // the code you already have here works
}

#7

why did you repeat the same if two times? if(yak.pos.y > hero.pos.y) {
if( yak position is greater than hero position ) {


#8

My bad, was trying to type it quickly. Edited

Based on the code you have in the screenshot, you could just change
yak.pos.y > hero.pos.y
to
yak && yak.pos.y > hero.pos.y

and change

yak.pos.y < hero.pos.y
to
yak && yak.pos.y < hero.pos.y

Basically, you don’t know if a yak even exists yet, so you need to check for it before you can read its position.


#9


#10

ohhhh I put the x + 10 (nevermind)


#11

You have an extra curly brace on line 9 in the screenshot above. You don’t need to do the yak && thing if you choose to surround your code with if(yak) { }


#12

tanks I got it correct :smiley: