(info) Other great resources: Official JS API docs, Scripting Forum

findResearch()

Overview

Returns a list of technologies that need to be researched to achieve a specific research goal.

This is an incredibly useful function because you can use it to make decisions about your research path.

Availability

Warzone 3.2 and above.

Syntax

var returnValue = findResearch(targetTechnology);

Parameters

ParameterTypeMandatoryDescriptionGame version
targetTechnologyString(tick)The technology you want to research.3.2

Return value

ValueTypeDescriptionGame version
<array>Array

An array of Research objects starting with the targetTechnology (at index 0) and then listing all pre-requisite technologies, if any, that need to be researched first.

If you've already researched the pre-requisite technologies, but haven't yet researched the targetTechnology, the array will just contain the targetTechnology.

If the targetTechnology is already researched then the array will be empty.

3.2
<error>ErrorIf the specified targetTechnology does not exist, an error will be thrown.3.2

Example

Which AA defence is most achievable?
// Scenario: You've just been attacked by VTOLS...
// ... but you've not yet researched Anti-Aircraft (AA) defences!
// You're strapped for cash (power) - what is the cheapest AA defence to research?
 
var researchPath = [ /* big list of research items */ ];
 
var noAATech = true; // initially we have no AA tech

function costToResearch(tech) {
  var cost = 0;
  var reqs = findResearch(tech);
  for (var r=0; r<reqs.length; r++) {
    cost += reqs[r].power;
  }
  return cost;
}

function cheapestToResearch(tech1,tech2) {
  return (costToResearch(tech1) < costToResearch(tech2)) ? tech1 : tech2;
}

function eventAttacked(victim,attacker) {
  if (noAATech && isVTOL(attacker)) {
    // R-Defense-Sunburst will be cheaper if we've been researching rockets
    // R-Defense-AASite-QuadMg1 (Hurricane) will be cheaper if we've been researching machineguns/cannons
    researchPath.unshift(cheapestToResearch("R-Defense-Sunburst", "R-Defense-AASite-QuadMg1"));
    noAATech = false; // we've now prioritised AA tech research
  }
}

function eventResearched(research,structure) {
  // in case we research AA defences before first VTOLs attack us
  // Note: && has precedence over ||
  // (see: https://developer.mozilla.org/en/JavaScript/Reference/Operators/Operator_Precedence )
  if (noAATech && research.name == "R-Defense-Sunburst" || research.name == "R-Defense-AASite-QuadMg1") {
    noAATech = false;
    // you probably want to instruct your trucks to start building AA defences at this point!
  }
} 

See also