Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Excerpt

Guess the type of a specified component...

 

Syntax

Code Block
themeRDark
languagejavascript
linenumberstrue
go.cuessComponentType = function(comp) {
	// ... guess component type ...
 
	return guessedType;
}

Parameters

ParameterTypeNotes
compStringThe component ID that the type should be determined for.

Return values

The function should return a constant defining the component type.

A list of constants can be found in the componentAvailable() "Notes" section.

(info) The constants are pre-defined by componentAvailable.js so you don't need to define them yourself.

If you're unable to guess the component type, return COMP_UNKNOWN.

Notes

This function is used by componentAvailable() on Warzone 3.1 if the component type is not specified.

If the component type is specified, it is assumed to be correct and this function will not be invoked.

The function should provide it's own internal caching to improve performance (see example below).

Example

A default function is provided by componentAvailable.js, a simplified version of which is shown below...

Code Block
themeRDark
languagejavascript
linenumberstrue
var componentCache = {};
 
// body and propulsion components are pre-cached (not shown in this example)
 
go.guessComponentType = function(comp) {
	if (componentCache.hasOwnProperty(comp)) return componentCache[comp];
	
	if (comp.contains("Brain") || comp.contains("Command")) {
		return componentCache[comp] = COMP_BRAIN;
	}
	
	if (comp.contains("epair")) {
		return componentCache[comp] = COMP_ECM;
	}
	
	if (comp.contains("ECM")) {
		return componentCache[comp] = COMP_ECM;
	}
 
	if (comp.contains("Spade")) {
		return componentCache[comp] = COMP_CONSTRUCT;
	}
	
	if (comp.contains("Sensor")
		|| comp.contains("Radar")
		|| comp.contains("CB")
		|| comp.contains("trike")) {
		return componentCache[comp] = COMP_SENSOR;
	}
	
	return COMP_WEAPON;
}
Div
classbox
Availability
Status
colourYellow
title3.1

Requires:

This function is not defined on Warzone 3.2+

Div
classbox
Contents

Jump to:

Table of Contents
maxLevel5