stardance has been extended another month! the new deadline is october 31 :)

You are browsing as a guest. Sign up (or log in) to start making projects!

1h 5m 7s logged

Devlog 3 - FLAG-DESC

So today I fixed the bug from earlier where the flag description wasnt working, basically sometimes in the description it would use the official name of the country, for example instead of just Afghanistan (which is its common name) the description would say Islamic Emirate of Afghanistan (which is its official name) there are also other examples where the name used in the description was neither its official name nor the common name, but it was one of the alternate names given by the API, so I had to include those as well in my filter. In the end, I made this function:

function getSanitizedDescription(countryName) {
    const countryData = JSON.parse(localStorage.getItem("countryData"))[countryName];
    if (!countryData) return null;

    // Combine all names into a single array cuz description name format is inconsistently weird
    const names = [
        ...(countryData.names.alternates || []),
        countryData.names.official,
        countryData.names.common,
    ].filter(Boolean);

    let description = countryData.flag.description;

    for (const name of names) {
        description = description.replaceAll(name, "this country");
    }

    return description;
}

This works by firstly getting an array of all the names associated with the country provided in the API, and then testing the description against every single one of them until the country name is not in the description, and it returns the sanitized description.

Stuff I need to Fix

1. Not allowing duplicate countries/hints

Currently, if the user types the same country twice, the app allows them to, in theory I allow this (its not game breaking its just bad strategy) but I think it would be better if I didn’t let them. Whats more game-breaking, however, is duplicate hints, which are very annoying. I will probably fix this in the next devlog

2. Giving the user a message when they guess the right country

Currently, the app just assumes you didn’t guess the correct country and never tells you if you guessed it right, which is not good game design! I will probably fix Bug #1 first before tackling this, as I’ll need to make and style a whole new popup for when the user wins, and program a restart, etc.

Anyways, see you next devlog!

0
1

Comments 0

No comments yet. Be the first!