2

I have found a script on github to pull prices from the EVE-Central API to include in a Google Spreadsheet. I have uploaded that script into the editor and saved it. When I try to run it I get an error about a file or function that is missing.

need typeids (line 38, file 'Code')

When I try to use the function inside the spreadsheet it tells me the function does not exist. After a lot of reading I found out Google changed something in their script editors.

Here is the script I am using. And a picture of the error code I got.

    /*

Takes a bunch of typeids from a list (duplicates are fine. multidimensional is fine) and returns a bunch of rows 
with relevant price data.

TypeID,Buy Volume,Buy average,Buy max,Buy min,Buy Std deviation,Buy median,Buy Percentile,
Sell Volume,Sell Average,Sell Max,Sell Min,Sell std Deviation,Sell Median,sell Percentile



I'd suggest loading price data into a new sheet, then using vlookup to get the bits you care about in your main sheet.

loadRegionPrices defaults to the Forge
loadSystemPrices defaults to Jita


=loadRegionPrices(A1:A28)
=loadRegionPrices(A1:A28,10000002)
=loadRegionPrices(A1:A28,10000002,47)

=loadSystemPrices(A1:A28)






An example below:

https://docs.google.com/spreadsheets/d/1f9-4cb4Tx64Do-xmHhELSwZGahZ2mTTkV7mKDBRPrrY/edit?usp=sharing

*/
function loadRegionPrices(priceIDs,regionID,cachebuster){
  if (typeof regionID == 'undefined'){
    regionID=10000002;
  }
  if (typeof priceIDs == 'undefined'){
    throw 'need typeids';
  }
  if (typeof cachebuster == 'undefined'){
    cachebuster=1;
  }
  var prices = new Array();
  var dirtyTypeIds = new Array();
  var cleanTypeIds = new Array();
  var url="http://api.eve-central.com/api/marketstat?cachebuster="+cachebuster+"&regionlimit="+regionID+"&typeid=";
  priceIDs.forEach (function (row) {
    row.forEach ( function (cell) {
      if (typeof(cell) === 'number' ) {
        dirtyTypeIds.push(cell);
      }
    });
  });
  cleanTypeIds = dirtyTypeIds.filter(function(v,i,a) {
    return a.indexOf(v)===i;
  });
  var parameters = {method : "get", payload : ""};

  var o,j,temparray,chunk = 100;
  for (o=0,j=cleanTypeIds.length; o < j; o+=chunk) {
    temparray = cleanTypeIds.slice(o,o+chunk);
    var xmlFeed = UrlFetchApp.fetch(url+temparray.join("&typeid="), parameters).getContentText();
    var xml = XmlService.parse(xmlFeed);
    if(xml) {
      var rows=xml.getRootElement().getChild("marketstat").getChildren("type");
      for(var i = 0; i < rows.length; i++) {
        var price=[parseInt(rows[i].getAttribute("id").getValue()),
                   parseInt(rows[i].getChild("buy").getChild("volume").getValue()),
                   parseFloat(rows[i].getChild("buy").getChild("avg").getValue()),
                   parseFloat(rows[i].getChild("buy").getChild("max").getValue()),
                   parseFloat(rows[i].getChild("buy").getChild("min").getValue()),
                   parseFloat(rows[i].getChild("buy").getChild("stddev").getValue()),
                   parseFloat(rows[i].getChild("buy").getChild("median").getValue()),
                   parseFloat(rows[i].getChild("buy").getChild("percentile").getValue()),
                   parseInt(rows[i].getChild("sell").getChild("volume").getValue()),
                   parseFloat(rows[i].getChild("sell").getChild("avg").getValue()),
                   parseFloat(rows[i].getChild("sell").getChild("max").getValue()),
                   parseFloat(rows[i].getChild("sell").getChild("min").getValue()),
                   parseFloat(rows[i].getChild("sell").getChild("stddev").getValue()),
                   parseFloat(rows[i].getChild("sell").getChild("median").getValue()),
                   parseFloat(rows[i].getChild("sell").getChild("percentile").getValue())];
        prices.push(price);
      }
    }
  }
  return prices;
}

function loadSystemPrices(priceIDs,systemID,cachebuster){
  if (typeof systemID == 'undefined'){
    systemID=30000142;
  }
  if (typeof priceIDs == 'undefined'){
    throw 'need typeids';
  }
  if (typeof cachebuster == 'undefined'){
    cachebuster=1;
  }
  var prices = new Array();
  var dirtyTypeIds = new Array();
  var cleanTypeIds = new Array();
  var url="http://api.eve-central.com/api/marketstat?cachebuster="+cachebuster+"&usesystem="+systemID+"&typeid=";
  priceIDs.forEach (function (row) {
    row.forEach ( function (cell) {
      if (typeof(cell) === 'number' ) {
        dirtyTypeIds.push(cell);
      }
    });
  });
  cleanTypeIds = dirtyTypeIds.filter(function(v,i,a) {
    return a.indexOf(v)===i;
  });
  var parameters = {method : "get", payload : ""};

  var o,j,temparray,chunk = 100;
  for (o=0,j=cleanTypeIds.length; o < j; o+=chunk) {
    temparray = cleanTypeIds.slice(o,o+chunk);
    var xmlFeed = UrlFetchApp.fetch(url+temparray.join("&typeid="), parameters).getContentText();
    var xml = XmlService.parse(xmlFeed);
    if(xml) {
      var rows=xml.getRootElement().getChild("marketstat").getChildren("type");
      for(var i = 0; i < rows.length; i++) {
        var price=[parseInt(rows[i].getAttribute("id").getValue()),
                   parseInt(rows[i].getChild("buy").getChild("volume").getValue()),
                   parseFloat(rows[i].getChild("buy").getChild("avg").getValue()),
                   parseFloat(rows[i].getChild("buy").getChild("max").getValue()),
                   parseFloat(rows[i].getChild("buy").getChild("min").getValue()),
                   parseFloat(rows[i].getChild("buy").getChild("stddev").getValue()),
                   parseFloat(rows[i].getChild("buy").getChild("median").getValue()),
                   parseFloat(rows[i].getChild("buy").getChild("percentile").getValue()),
                   parseInt(rows[i].getChild("sell").getChild("volume").getValue()),
                   parseFloat(rows[i].getChild("sell").getChild("avg").getValue()),
                   parseFloat(rows[i].getChild("sell").getChild("max").getValue()),
                   parseFloat(rows[i].getChild("sell").getChild("min").getValue()),
                   parseFloat(rows[i].getChild("sell").getChild("stddev").getValue()),
                   parseFloat(rows[i].getChild("sell").getChild("median").getValue()),
                   parseFloat(rows[i].getChild("sell").getChild("percentile").getValue())];
        prices.push(price);
      }
    }
  }
  return prices;
}

Error Note

1
  • 1
    Please clarify what you mean by "After a lot of reading I found out Google changed something in their script editors"? We can't guess what you read, or what change affected you. What exact error do you see? How have you tried invoking the custom function from the spreadsheet? Commented May 9, 2016 at 13:48

1 Answer 1

1

The error message is very explicit. Here's the relevant code:

function loadSystemPrices(priceIDs,systemID,cachebuster){
  if (typeof systemID == 'undefined'){
    systemID=30000142;
  }
  if (typeof priceIDs == 'undefined'){
    throw 'need typeids';      ////  <<<< Line 38
  }

Function loadSystemPrices() has been invoked with no value for the priceIDs parameter. This condition is explicitly checked by the code, and results in a custom error message being thrown on line 38.

That's happening because you've invoked the function from the debugger, with no parameters. You can work around this by writing a test function to pass parameters, as described in Debugging a custom function in Google Apps Script.

Sign up to request clarification or add additional context in comments.

1 Comment

op should look at the comment at the top of the copied code, where it shows examples of how to use the functions from a sheet cell formula

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.