Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

Hoarding Gold (No coin.value code?)


I’m having trouble getting my avatar to actually go around and collect the gold. She just runs straight to Naria and says “Done collecting gold!”. Any suggestions on why the program is ignoring my code?

var totalGold = 0;
loop {
    var coin = this.findNearestItem();
    // Pick up the coin and add its value to the total.
    // Get its value with:  coin.value
    if (coin) {
        var pos = coin.pos;
        var x = this.pos.x;
        var y = this.pos.y;
        totalGold = totalGold += coin.value;
    if (totalGold >= 25) {
        // >= means totalGold is greater than or equal to 25.
        // This breaks out of the loop to run code at the bottom.

this.moveXY(64, 34);
this.say("Done collecting gold!");


I don’t know if this is the problem, but it is wrong…

it should either be “totalGold += coin.value;” or “totalGold = TotalGold + coin.value” not both.


Strangely enough we where trying “totalGold + coin.value = totalGold” and it wouldn’t work. It has to be " totalGold = totalGold + coin.value "


An assignment always looks the same:

variable = computation

It is not forbidden to use variable in computation if it has already been defined. In fact, the following expression is absolutely valid:

variable = variable

Look at the following example:

totalGold = totalGold + coin.value

What actually happens is this:

  1. Get the value stored in totalGold
  2. Get the value stored in coin.value
  3. Add the two stored values together
  4. Store the result in a variable named totalGold, unimportant whether it existed before or not.


[…deleted poorly formatted, unhelpful code…]


Draz, please do not give out correct code, as it gives any reader the answer without providing the learning. Besides, the person you are replying to gave the issue over five months ago. And you still haven’t learned to post your code correctly.


Could you help me, I need to figure out how to pick up the “coin” I do not remember how to pick up items in this game without it being an “item”


You pick the coin by moving to its position.



the reason is that you have to say totalGold in the message


Please do not revive dead threads! This problem has already been solved and left alone for one year.


just trying to be helpful


Thanks for trying to help the CodeCombat community, but this problem is already solved.