Drop the Flag Java issues

Ive been stuck on this level for a while, I’ve looked at other posts, and they haven’t helped much. I’ve fixed most of the problems on my own, but there have been problems that pop up once I fix others.

Here’s my code. Im using javascript but i have copy pasted from other people who used python while trying to find an answer so if there are any things that are for python and not javascript, please tell me. Words in Italics are not part of code.

loop{
var flag = self.findFlag()
if flag{
this.buildXY(“fire-trap”,30, 46)
this.buildXY(“fire-trap”,30, 30)
this.buildXY(“fire-trap”,30, 16)
this.pickUpFlag(flag)
}
else{
var if item:
var itemX = pos.x it says pos is not defined
var itemY = pos.y
self.moveXY(itemX, itemY)
}
}

First of all, I don’t like the Ambassador tag on a post that is just “please help me” on a very first post.

I invite you to read FAQ, which invite you to be read before posting. It really helps for people who might want to help to read a well formated code. There :

loop{
    var flag = self.findFlag()
    if flag{
        this.buildXY("fire-trap",30, 46)
        this.buildXY("fire-trap",30, 30)
        this.buildXY("fire-trap",30, 16)
        this.pickUpFlag(flag)
    }
    else{
        var if item:
        var itemX = pos.x it says pos is not defined
        var itemY = pos.y
        self.moveXY(itemX, itemY)
    }
}

First of all, self doesn’t exist in JavaScript. You want to use this.findFlag() and this.moveXY()
2) All semi colons are missing at the end of every statements.
3) var if item: is a very weird statement in which I think you want to to define a variable named item, but fails to do so.

  1. pos can’t be used on its own as it is a method. It needs something to be applied to. In your case : item.

    var itemX = item.pos.x ;
    var itemY = item.pos.y ;

Hope this helps.

Now its saying that on line 11 (var itemX = item.pos.x; ) tmp32 is undefined and it highlights item.pos. Its strange that the semicolons arent showing up on the msg. Thank you for trying to help though. What do you mean dont put an ambassador tag? I thought the different options were just what kind of post my post was. please explain

Well, where do you define item???

you have a flag = …
where is item = …

loop{
var flag = self.findFlag()
if flag{
this.buildXY("fire-trap",30, 46)
this.buildXY("fire-trap",30, 30)
this.buildXY("fire-trap",30, 16)
this.pickUpFlag(flag)
}
else{
var if item:
var itemX = pos.x it says pos is not defined
var itemY = pos.y
self.moveXY(itemX, itemY)
}
}

Alrighty,

  1. First off you need to put your flag conditional in parentheses.
  2. Self is not used in JavaScript, it’s a Python thing, the videos on this site use Python as most of the users on this site use Python, what is important to us JavaScripters is ‘this’. My understanding is it allows a global variable to be called.
  3. You should not be placing integers into the buildXY() for this level, you should be passing in the location of the flag.
    You need to take the flag variable,use .pos and assign it to X and Y coordinates and pass those in.
    Likewise you need to do this to your item pickup.

It needs to be item.pos.x to work in your itemX, where item is your variable (also item needs to be declared a variable in a different preceding statement) when you assemble a method statement you need to do it in this order: global.variable.method, essentially starting off from a high level and working down.

1 Like