Why the hero doesn't hit chicken?


Actually, i don’t understand the code:

typeLeft = look('left')
while look('left') == typeLeft:
     zap('left')

why the sentences make the hero to ignore the chicken?
in my opinion, i need to set the condition to ignore the chicken. but now there is only the variable and value: typeLeft = look(‘left’), which means i can re-write the code using variable’s value “look(‘left’)” instead of variable “typeLeft”, like below:

`

typeLeft = look(‘left’)

`

Q1: like you see, "look(‘left’) == look(‘left’) doesn’t make any sense. i don’t know why the python system sets it like this.
Q2: As i mention above, why this piece of code can make chicken avoid being attacked.

i am very appreciate it if someone can solve my problem.

1 Like

upup please help me. so sad :smiling_face_with_tear:

1 Like

I don’t do the junior, but I will try to help and figure it out. :upside_down_face:

Welcome to the discourse :partying_face:

You can use this:

for i in range(0, 5):
    typeLeft = look('left')
    while look('left') == typeLeft and typeLeft != "chicken":
         zap('left')
    typeRight = look('right')
    go('up', 1)

I think this will only attack the left if the type isn’t “chicken” (assuming that’s the type name for chicken)

hi willwa12
thx reply at first.
it should be lvl 291 naming ‘looking sharp’

and i have another similar question about lvl 293 ‘look and see’

please look at the picture below:


typeUp = look('up')
    typeDown = look('down')
    go('left', 1)
    if typeUp != "chicken":
        zap('up')
    if typeDown != "chicken":
        zap('down')

my problem appears on the meaning of this piece of code:

typeUp != “chicken”

why the code makes the hero doesn’t attack the chicken, and even tnt bomb? i don’t understand the principle of it.

i will be very appreciated if you can answer my quesion.

1 Like

Your code worked for me. You don’t want to attack the chickens, and that piece of code makes it check if the type above you isn’t a chicken

For looking sharp, you need to check left with what I showed you, and then check and zap right after the typeRight variable. You can implement this with:

typeLeft = look('left')
while look('left') == typeLeft and typeLeft != "chicken":
    zap('left')
typeRight = look('right')
while look('right') == typeRight and typeRight != "chicken":
    zap('right')

thx for you relpy.

i know the phenomena the code acts, and imitating the example, i know how to write the code correctly.

i need to know about the principle of the code working and rules about the code running in the bottom . not how to write the code.

so i very thanks you for your relpy, but it is so pity that your answer is not what i want.

1 Like

Do you mean how the code works

I’m sorry, if I’m not answering what you want, but I don’t understand what you want :confused:

the underlying logic of the code like:
why the code “look(‘left’) == typeLeft” will make the hero ignore chicken or tnt

1 Like

That isn’t the part of the code that makes it ignore the chicken. That finds all the units to the direct left of you and this if-statement only runs if the unit to it’s direct left is not a chicken. != means if it doesn’t equal:

while look('right') == typeLeft and typeLeft != "chicken":

I hope that helped :grin:

It doesn’t ignore the tnt, the tnt will just blow up the chickens so it doesn’t fire at them

the original code pieces doesn’t add the sentence 'and typeLeft != “chicken” ’ as you do, though it still avoid ‘chicken’ being attacked.

the original correct code is like:

for i in range(0, 5):
    typeLeft = look('left')
    while look('left') == typeLeft:
        zap('left')
    typeRight = look('right')
    while look('right') == typeRight:
        zap('right')
    
    go('up', 1)

as you see, i don’t need to add’and typeLeft != “chicken” ', it still works.

look('left') == typeLeft finds the enemies on the direct left from the placeholder hero. You have to use equals typeLeft for it to not target the chickens

look('left') == typeLeft finds the enemies on the direct left from the placeholder hero. You have to use equals typeLeft for it to not target the chickens

there is not necessary to do that. the code still works. this is what i want to know why

To be honest, I don’t know why, but maybe somebody else can help you. Sorry that I couldn’t help :pensive_face:

yes, after your test, you should find this odd stuff. so, anyway, thx a lot for your help.