Missing something here

What am i missing here? positions of the searchable objects in the json hav to be copied and value “a” has to calculated and put in. New to coding but i think i miss something in groups. The script runs but doesn’t show results in outputFile.cfg

Repl link:

code snippet

Hi @nheiden
ChatGPT has given this code:

const fs = require('fs');

// Input file //
const inputFileName = 'Input.json';

// Output file //
const outputFileName = 'output.cfg';

// Read JSON file //
const inputData = JSON.parse(fs.readFileSync(inputFileName, 'utf8'));

// Objects to search for //
const objectsToFind = ['Land_Mil_Barracks_Round', 'Land_Mil_Barracks1', 'Land_Mil_Barracks2', 'Land_Mil_Barracks3', 'Land_Mil_Barracks4', 'Land_Mil_Barracks5', 'Land_Mil_Barracks6', 'Land_Tisy_Garages'];

// Function to calculate "a" //
function calculateA(y) {
  return (y < 0) ? 360 - y - 90 : 360 + y + 90;

// Array to store generated groups //
const groups = [];

// Search JSON and convert //
if (inputData && inputData.Objects && Array.isArray(inputData.Objects)) {
  inputData.Objects.forEach((obj) => {
    if (obj && obj.name && obj.pos && obj.ypr) {
      if (objectsToFind.includes(obj.name)) {
        const [x, y, z] = obj.pos;
        const [yaw] = obj.ypr;
        const a = calculateA(yaw);
        const group = `x=${x}, y=${y}, z=${z}, yaw=${yaw}, a=${a}`;
} else {
  console.error('Invalid JSON structure in Input.json.');

// Write generated groups to output file //
fs.writeFileSync(outputFileName, groups.join('\n'));
console.log(`Conversion ready files stored into ${outputFileName}.`);

I have tried it and data is printed to the output.cfg file.
Hope this helps!

My repl: https://replit.com/@NateDhaliwal/Json2MapGroupPos-Conv

1 Like

@nheiden If this answers your question, you can mark the post above as the Solution.

Thank you, i’ll try it now.

1 Like

It did put the result cfg but calculation wasnt working. i fixed it all now and is working good. thanks again Nate.
end result ;

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.