Where's The Problem About The Function "notWait()"


#1


Here’s the problem: every time my hero collected 73 coins, the lower area on the right stopped producing coins. My hero could only attack the ogres.
Even if I’m able to solve this problem through placing flags, but I want to achieve this goal by writing code.
So I finished the function “notWait()”. The coordinate inside the function is the coordinate of the middle of the map. After hero walked there, he can find other coins and go to that part.
But this made a infinity loop. I don’t understand.
Please tell me why. Or just offer another idea which can solve the problem~ Thanks!:pray::pray::pray:


#2

Try moving DY to the other areas.


#3

Sorry, I mean try to move XY.


#4

What type of glasses do u have


#5

The strongest :sunglasses:
The one which can see through walls


#6

Well, it didn’t work :sob:


#7

Hi @Hammer, could you message me your whole solution so I could have a better understanding of your code? it’s hard for me to tell what went wrong from the screenshot. :wink:


#8

The function notWait() is at the bottom :sweat_smile:

(solution removed)

There are some functions about yaks because they were written in the Sarven Desert. I copied them.


#9

Please do not post final solutions. This is counter-productive toward the goal of this forum. Posting answers takes the whole point out of the game. Also, please format your code correctly. It should look like this:

while True:
    enemy = hero.findNearestEnemy()
    if enemy:
        hero.say("Run to the nearest corner.")
    else:
        hero.say("My code is formatted properly!")
    

Thank you and welcome to the board.


#10

Hi @Hammer, like @TheDemonPrince said, it is not encouraged to post solution code directly, (If it’s a code that is not working I think it should be fine. However, you didn’t format your code properly I guess that’s why it gets edited even if it’s not a solution.

Use pre-formatted text to post the code. You can find it in the toolbar above the input area.
Also it helps to add the level link to the post, it will take some time to locate the level you mentioned, like this
https://cn.codecombat.com/play/level/backwoods-treasure?

OK, The way I did this level is by defining 3 functions:

  1. collect coins by certain priority
  2. if there is not any coin the hero can see, let the hero move to the center of the map where he/she can have a clear view of the whole area (you mentioned that you have the google with infinity range, so maybe define a range for it? :slight_smile:)
  3. a function which allow the hero to attack nearest enemy whenever they spwan

I suggest you re-write your solution and change the function “notWait()”, it feels to me that this add un-necessary complexity to the level.

Let me know if it helps!:wink:


#11

Another way to do it is to use flag, when one area no longer spawn coins, manually guide your hero to other areas.


#12

不好意思我不知道为什么我我发不了帖子,只好借你这个地方回复
我这个哪里错了。。是右,上,然后看到敌人攻击啊,一直提示我看不到敌人


#13

Thats wierd, why is that happening?


#14

嗯。。。你能不能把那个提示x掉,我看不到啊


#15

Well, I know, but I want to find out a way to achieve this without using flags


#16

The second one is exactly what I want! “let the hero move to the center of the map where he/she can have a clear view of the whole area”. You inspired me that I could set a range because I can SEE the coin but unable to COLLECT it.
Thank you very much.


#17

Glad it helped! :wink::+1:
不客气!