Install Steam
login
|
language
简体中文 (Simplified Chinese)
繁體中文 (Traditional Chinese)
日本語 (Japanese)
한국어 (Korean)
ไทย (Thai)
Български (Bulgarian)
Čeština (Czech)
Dansk (Danish)
Deutsch (German)
Español - España (Spanish - Spain)
Español - Latinoamérica (Spanish - Latin America)
Ελληνικά (Greek)
Français (French)
Italiano (Italian)
Bahasa Indonesia (Indonesian)
Magyar (Hungarian)
Nederlands (Dutch)
Norsk (Norwegian)
Polski (Polish)
Português (Portuguese - Portugal)
Português - Brasil (Portuguese - Brazil)
Română (Romanian)
Русский (Russian)
Suomi (Finnish)
Svenska (Swedish)
Türkçe (Turkish)
Tiếng Việt (Vietnamese)
Українська (Ukrainian)
Report a translation problem
Basically what it's saying is that "sources" is an array. An array is basically a single variable that stores multiple values. For example, a simple array in JavaScript would be:
var array = ['one', 'two', 'three', 'four', 'five'];
Each array index indicates a value in our array. For example:
console.log(array[0]);
The above command would write "one" to the console.
console.log(array[4]);
The above command would write "five" to the console.
sources[0] indicates the first source found when you run:
var sources = creep.room.find(FIND_SOURCES);
It finds all the sources in the room and puts them in an array. I'm not sure what implications it has if you use "sources" instead of "sources[0]", but my personal code uses "sources" and does not have an index mentioned. My creeps will use whatever source is available in the room. Indicating "sources[0]" means that whichever creep runs that code will only ever harvest from one source; the source indicated by "source[0]".
Example:
var sources = [source1, source2];
if you want your creep to only harvest from "source1" then you must say:
creep.harvest(sources[0]);
If you still don't understand, it's either because I'm pretty nooby to JavaScript, or because you don't know enough.
Either way, I highly recommend you check out this course (it can be taken for free and provides everything you need to understand Screeps at a basic level (including arrays)):
https://www.codecademy.com/learn/introduction-to-javascript