nheiden
September 8, 2023, 9:36am
1
Question:
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:
https://replit.com/@nheiden/Json2MapGroupPos-Conv#index.js
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}`;
groups.push(group);
}
}
});
} 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.
nheiden
September 8, 2023, 10:00am
4
Thank you, i’ll try it now.
1 Like
nheiden
September 8, 2023, 12:02pm
5
NateDhaliwal:
(y < 0) ? 360 - y - 90 :
It did put the result cfg but calculation wasnt working. i fixed it all now and is working good. thanks again Nate.
end result ;
https://replit.com/@nheiden/DayZ-Json2MapGroupPos-ConvMil#index.js
1 Like
system
Closed
September 15, 2023, 12:02pm
6
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.