Hi all! First post here. I’ve tried to search for something similar but haven’t found an answer to my problem, or haven’t been able to identify it with my limited knowledge
, sorry if this has been solved elsewhere. Any help is appreciated.
What I’m trying to do
I’m trying to build a base with files for game notes (Fantasy Life 3ds). I wanted to have one note for each ‘life’ (profession), where I store all the quests that need to be completed to advance in that life. I thought it would be possible to use a Dataview query to update how many quests I’ve completed once I’ve checked them off in the note, and then sync the values calculated with Dataview for overall progress and some other stats to the YAML properties so that I could display them in the base itself using the Card view.
Things I have tried
- Used this Dataview query (parts of it are in Spanish because that’s the language I’m playing the game in. Also, I used Gemini to help since I’m at a loss on how to achieve complex stuff with Dataview yet - I know this isn’t ideal):
const page = dv.current();
const tasks = page.file.tasks;
const completedTasks = tasks.filter(t => t.completed);
const totalTasks = tasks.length;
let starsEarned = 0;
completedTasks.forEach(task => {
const match = task.text.match(/(\d+)\s*Estrellas/);
if (match) {
starsEarned += parseInt(match[1]);
}
});
const rankThresholds = [
{ name: "Novato", stars: 100 },
{ name: "Aprendiz", stars: 500 },
{ name: "Versado", stars: 1200 },
{ name: "Experto", stars: 4000 },
{ name: "Maestro", stars: 8000 },
{ name: "Héroe", stars: 12000 }
];
let nextRank = "¡Rango Máximo!";
let starsToNext = 0;
let currentRankName = "Principiante";
for (let rank of rankThresholds) {
if (starsEarned >= rank.stars) {
currentRankName = rank.name;
} else if (starsToNext === 0) {
nextRank = rank.name;
starsToNext = rank.stars - starsEarned;
}
}
const progressPercent = totalTasks > 0 ? Math.round((completedTasks.length / totalTasks) * 100) : 0;
const progressBar = "█".repeat(Math.floor(progressPercent / 5)) + "░".repeat(20 - Math.floor(progressPercent / 5));
dv.header(3, "Rango Actual: " + currentRankName);
dv.paragraph(`**Progreso de Misiones:** ${completedTasks.length}/${totalTasks} (${progressPercent}%)`);
dv.paragraph(`\`${progressBar}\` ${progressPercent}%`);
dv.paragraph(`**Estrellas Ganadas:** ${starsEarned}`);
dv.paragraph(`**Siguiente Rango:** ${nextRank}`);
dv.paragraph(`**Estrellas Necesarias:** ${starsToNext > 0 ? starsToNext + " ⭐" : "¡Completado!"}`);
const fields = [
`progress:: ${progressPercent}%`,
`current_stars:: ${starsEarned}`,
`stars_to_next:: ${starsToNext}`,
`current_rank:: ${currentRankName}`
].join(' '); // Joins with a space
dv.span(fields).style.display = 'none';
- Enabled JavaScript queries in the Dataview settings
- Enabled JavaScript in the Meta Bind settings
- Disabled code restrictions in the Meta Bind settings
- Cleaned up my YAML properties in Source Code to ensure there were no previous values conflicting with the code
I haven’t been able to get it to work yet, and since I’m a beginner, I don’t know what to do to fix it. Anyone have any idea? Thanks in advance!