I've been spending way too much time on this issue... So i want to declare a 2D array called "positions" that can be used in other functions. using a parsing code that worked in the function "init", i tried to create a simple function called "parsing" as to avoid repeating the long parsing process every time i want to use the positions array. except when i console.log(positions) in other functions, it always returns an empty array = []. How come "positions" doesn't get modified in the parsing function and how do i do it? This is the code used:
var positions = [];
parsing();
init();
function parsing() {
fetch('Petit_film_256_atomes.txt').then(response => response.text()).then(text => {
const arr = text.split('\n')
.map(line => line.trim())
.map((arr) => arr.split(' '))
.map(([size, x, y, z]) => ({
size: Number(size),
x: Number(x),
y: Number(y),
z: Number(z)
}));
while (arr.length > 0) {
positions.push(arr.splice(0, size).slice(2));
}
})
}