Please help me with Sarven Sentry!

Here is my code:

loop:
    flagGreen = self.findFlag("green")
    if flagGreen:
        x = flag.pos.x
        y = flag.pos.y
        self.buildXY("fence", 36, 30)
    flagBlack = self.findFlag("black")
    if flagBlack:
        x = flag.pos.x
        y = flag.pos.y
        self.buildXY("fire-trap", x, y)
    flagViolet = self.findFlag("violet")
    if flagBlack:
        x = flag.pos.x
        y = flag.pos.y
        self.moveXY(x, y)

I don’t know what I am doing wrong!!

Check especially the line where you build the fence and the line where you check if the violet-flag exists.

Try to find it out for yourself first!

You build the fence at (36, 30) rather than (x, y)
You check if the black flag exists, but you should check for the violet flag to exist.

Okay. Thank you. I put it in like that:

loop:
    flagGreen = self.findFlag("green")
    if flagGreen:
        x = flag.pos.x
        y = flag.pos.y
        self.buildXY("fence", x, y)
    flagBlack = self.findFlag("black")
    if flagBlack:
        x = flag.pos.x
        y = flag.pos.y
        self.buildXY("fire-trap", x, y)
    flagViolet = self.findFlag("violet")
    if flagViolet:
        x = flag.pos.x
        y = flag.pos.y
        self.moveXY(x, y)

But it is still not working:( What else?

It’s also saying

flagGreen = self.findFlag("green")
   if flagGreen:
        x = flag.pos.x
        y = flag.pos.y
Self find flag

I PMed you how to write code so we can read it. Please fix your previous posts.

I overlooked that you never call self.pickUp(flag) This method takes one of the three methods above and removes that flag from the gameboard (so you can reuse it).
After each action (build, build or move) you should pickup the flag.

So like this?

loop:
    flagGreen = self.findFlag("green")
    if flagGreen:
        x = flag.pos.x
        y = flag.pos.y
        self.buildXY("fence", x, y)
        self.pickUpFlag()
    flagBlack = self.findFlag("black")
    if flagBlack:
        x = flag.pos.x
        y = flag.pos.y
        self.buildXY("fire-trap", x, y)
        self.pickUpFlag()
    flagViolet = self.findFlag("violet")
    if flagViolet:
        x = flag.pos.x
        y = flag.pos.y
        self.moveXY(x, y)
        self.pickUpFlag()
    
    

Does it work? Did you try it in the level?

Yes, but it didn’t work.

What exactly did not work? Do you get an error? If yes, which one? If not: What happens differently from what you expect to happen?

Also a common source of problem: Check that you have a hammer and a flag equipped. There is really no reason to ever unequip the flag, but maybe you have a sword in hand. With a sword you can obviously not build a fence or a fire-trap.

It’s saying: Try Self.findFlag()
And i have a hammer.

Oh, I got it.

You wrote

self.pickUpFlag()

but you’re supposed to write

self.pickUp(flag)    #replace flag with the actual flagname, like flagBlack

Still not working:

loop:
    flagGreen = self.findFlag("green")
    if flagGreen:
        x = flag.pos.x
        y = flag.pos.y
        self.buildXY("fence", x, y)
        self.pickUp(flagGreen)  
    flagBlack = self.findFlag("black")
    if flagBlack:
        x = flag.pos.x
        y = flag.pos.y
        self.buildXY("fire-trap", x, y)
        self.pickUp(flagBlack)  
    flagViolet = self.findFlag("violet")
    if flagViolet:
        x = flag.pos.x
        y = flag.pos.y
        self.moveXY(x, y)
        self.pickUp(flagViolet) 

Ah, the formatting is a little different, actually. The method name is pickUpFlag, and it also takes a flag argument.

self.pickUpFlag(flagGreen)
self.pickUpFlag(flagBlack)
self.pickUpFlag(flagViolet)

Now it’s saying flag not defined

loop:
    self.pickUpFlag(flagGreen)
    self.pickUpFlag(flagBlack)
    self.pickUpFlag(flagViolet)
    if flagGreen:
        x = flag.pos.x
        y = flag.pos.y
        self.buildXY("fence", x, y)
        self.pickUpFlag(flagGreen)  
    if flagBlack:
        x = flag.pos.x
        y = flag.pos.y
        self.buildXY("fire-trap", x, y)
        self.pickUpFlag(flagBlack)  
    if flagViolet:
        x = flag.pos.x
        y = flag.pos.y
        self.moveXY(x, y)
        self.pickUpFlag(flagViolet)  

'cause its not…

flag = is never set

change flag to flagGreen (or black/violet where appropriate)

I’ve never seen “self.findFlag(flagGreen)” so I wouldn’t have expected that to work.
If it does, cool!! if not then make it (replacing Color/“color” of course):

flagColor = self.findFlag(“color”)

My bad, sorry. I was absolutely sure it was just pickUp.

if flagBlack:
x = flag.pos.x ------>flagBlack.pos.x
y = flag.pos.y ---------------->flag.pos.y
self.buildXY(“fire-trap”, x, y)
self.pickUpFlag(flagBlack)

Help! My language is Python and here is my coding:

loop:
flag = self.findFlag()
if flag:
# How do we get fx and fy from the flag’s pos?
flagpos = flag.pos
fx = flag.pos.x
fy = flag.pos.y
self.buildXY(“fire-trap”, fx, fy)
self.pickUpFlag(flag)
else:
item = self.findNearestItem()
if item:
pos = item.pos
itemX = pos.x
itemY = pos.y
self.moveXY(itemX, itemY)

How do I make it do a firetrap? I’ve tried doing this but didn’t work:

loop:
flag = self.findFlag()
if flag:
# How do we get fx and fy from the flag’s pos?
flagpos = flag.pos
fx = flag.pos.x
fy = flag.pos.y
self.buildXY(“fire-trap”, fx, fy)
self.pickUpFlag(flag)
else:
item = self.findNearestItem()
if item:
pos = item.pos
itemX = pos.x
itemY = pos.y
self.moveXY(itemX, itemY)
loop:
flag = self.findFlag()
if flag:
# How do we get fx and fy from the flag’s pos?
flagpos = flag.pos
fx = flag.pos.x
fy = flag.pos.y
self.buildXY(“fence”, fx, fy)
self.pickUpFlag(flag)
else:
self.buildXY(“firetrap”, fx, fy)

Nevermind, it was too hard for me so then I just used the move command and the build firetrap and build fence command. It actually worked! :smiley:

ok guys or people who needs help with this one this is a basic code

[redacted, please don’t post solutions]

It will work