I'm trying to run addAttributes in the sequence that the code is written. The code enters the if statement but when it hits the reader it stops and goes the last if statement at the bottom of the code and executes it. After that executes it goes back to the file reader picks up from where it left off, processing the rest of the code that was skipped.
const addAttributes = (_element) => {
let selectedElement = _element.layer;
var carPart;
var speed = 0;
var handling = 0;
var acceleration = 0;
if (selectedElement.name != null){
const lineReader = require('line-reader');//SKIPS THIS
lineReader.eachLine('doc.csv', function(rowItems, last) {
carPart = [rowItems.split(",")];
carPart.forEach(dataCheck);
function dataCheck(carPart){
if ((carPart[0]) == selectedElement.name) {// must incloude random asset
console.log(selectedElement.name);
console.log(carPart);
speed = speed + parseInt(carPart[ 1]);
handling = handling + parseInt(carPart[2]);
acceleration = acceleration + parseInt(carPart[3]);
console.log("speed " + speed)
console.log("handling " + handling)
console.log("acceleration " + acceleration)
if (speed != 0){
attributesList.push({trait_type: "Speed",Value: speed,})
}
if (handling !=0){
attributesList.push({trait_type: "Handling",Value: handling,})
}
if (acceleration != 0){
attributesList.push({trait_type: "Acceleration",Value: acceleration,})
}
}
if(last){
stop=false;
}
}
})
}
const layerAttributes = {
trait_type: _element.layer.trait,
value: selectedElement.traitValue,
...(_element.layer.display_type !== undefined && {
display_type: _element.layer.display_type,
}),
};
if (
attributesList.some((attr) => attr.trait_type === layerAttributes.trait_type ))
return;
attributesList.push(layerAttributes);
};