How to build something with a flag

I do not know how to build a fence with a flag

o now i now it is:
while True:
flag = hero.findFlag(“green”)
if flag:
hero.pickUpFlag(flag)
hero.buildXY(“fence”, flag.pos.x, flag.pos.y)

Actually, you have to build before you pick-up the flag

What level is this??

It’s great that you solved this level but please don’t post finished, working code or final solutions. The purpose of this board is to help people learn and simply providing solutions is counterproductive toward that goal. Thanks.