Play Home Contribute GitHub Join Us Discourse Staff Members GitHub Contribution Guides Team

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


// 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();


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.


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.


Thank you so much.:blush: