Problem With Upgraders



  •   I really do enjoy this game but for the past few days I have been stuck on this one problem. When I am trying to program my creeps that handle upgrading the controller, I continue to have the same problem which is that they will only pick up two energy (they have only one work part), and then deliver it to the controller. If any of you know a way to have the creep harvest a full load and then deliver the whole load to the controller, it would be greatly appreciated if you left a comment here.

    -Thank You

    PS: If you wish to have any further information on my problem feel free to ask for it.



  • Seems like you are using code like this:

    if(creep.carry[RESOURCE_ENERGY] === 0) { /*harvest*/ }

    else {/*upgrade*/}

    You should wait for full load by

    if(_.sum(creep.carry) < creep.carryCapacity) { /*harvest*/ }

    else {/*upgrade*/}

    Pretty old and classical problems 😃



  • Thanks for the help, but I was also wondering, how could I make it so that they completely unload at the controller? 



  • had same issue. just keep calling upgrade till you run out of energy on your creep



  • What you need is basically a simple finite-state machine. What you want to do is impossible without saving some state in the creeps memory, because without further information, the creep can't know what to do when it's neither completely full nor completely empty. What Mototroller suggested will only reverse the problem. So you will need to give the creep further information. You can do this by introducing a memory variable that defines the current state, and you will need to explicity toggle it. In my code, I usually call it "task". Here's a simple example:

    http://hastebin.com/afitekatan.avrasm 

     



  • Thanks for the help Amadox, this solved my problem!