Lately, I've been heavily focused on Python programming but recently delved into the realm of Screeps and Javascript.
As part of a tutorial, there is this code snippet that moves a creep towards an energy source to harvest it:
if(creep.store.getFreeCapacity() > 0) {
var sources = creep.room.find(FIND_SOURCES);
if(creep.harvest(sources[0]) == ERR_NOT_IN_RANGE) {
creep.moveTo(sources[0]);
}
}
This code works as intended, with the creep moving to the resource and harvesting it. However, my initial thought was that the creep would not start harvesting unless explicitly commanded to do so. Is this behavior specific to how objects are defined in Screeps, or am I missing something fundamental about JavaScript?
I also conducted a test by simply instructing the creep to move to the source without any conditionals to see if it would begin harvesting automatically, but it did not.