Help with the level canyon of storms

in this level you have to collect coins while yaks are there, then hide when they are gone.
the problem is that I won’t stop collecting even after the yaks are gone.
here is the code :

// A desert storm is coming!
// Yaks can detect when a storm is coming.

// This variable will be used as a condition.
var yak = hero.findNearest( hero.findItems());

// While there is a sand yak:
while (yak) {
// Collect a coin.
var coin = hero.findNearest( hero.findItems());
if (coin) {
hero.moveXY(coin.pos.x, coin.pos.y);
}

// Update the variable "yak".

}
// The yaks have hidden.
// Move to the hideout.
hero.moveXY(38, 58);

how do I update the variable? what does it mean?
please help

Because
// Update the variable "yak".

If you don’t update it for each cycle, then yak contains a value from the first frame.

and how do I update it?
I am new to coding

It’s an adventurer level. Have you completed levels before?

yak = findNearestEnemy();
1 Like

I have completed the dungeon and forest worlds, I just never encountered an update instruction.
thanks a lot for your help

Hm. Thanks. It’s a useful feedback. I think I should rewrite this comment-instruction.

1 Like

Can you explain : then yak contains a value from the first frame. ?
In another way : what is the difference between first variable yak and the updated one?
I’m newbie and thanks for helping :slight_smile:

On the first frame (first second, start the game etc) we definitely see yaks here. So yak variable contains the result of the findNearestEnemy.

But then the level state is changing and if you don’t update yak then it contains the result from the first call. So we need to recheck the state and write the new results of findNearestEnemy in the yak variable. It’s updated value.

2 Likes

Thank you so much.:blush:

One of the biggest sources of frustation with this teaching method is that the developers are in a high level of experience and they presume that they can instruct us about what should be done with simply a word or two. They replied this topic but for no avail. I simply cannot figure out what they wanted to say with the update yak thing. It´s just one exemple of ineffective communication between highly experienced staff and plain begginers. They presume too much about our current understanding.

Hello, welcome to the forum @knightcvel. If this post doesn’t help you with this level, you can start another with your specific questions. There are a lot of people with varying degrees of experience and not just the developers that can provide support.

If you need some advice, post your code and give some detail about the challenges you are having completing the level. We will help as much as we can. If there are some details that need more explanation we will try to provide the information as much as we understand with our experience in CodeCombat.