async function getChatRoom(filename) {
        //console.log(characters[Characters.selectedID].chat);
        jQuery.ajax({    
            type: 'POST', 
            url: '/getchatroom', 
            data: JSON.stringify({
                room_filename: filename
            }),
            beforeSend: function(){
                //$('#create_button').attr('value','Creating...'); 
            },
            cache: false,
            timeout: requestTimeout,
            dataType: "json",
            contentType: "application/json",
            success: function(data){
                // console.log(data);
                //chat.length = 0;
                // if(is_room)
                // {
                //     Rooms.selectedIDs.forEach(function(curId, i) {
                //         if(!Characters.id.includes(curId))
                //         {
                //             let msg = "Cannot load room. Some characters expected are missing. Please check if you have all the characters.";
                //             callPopup(msg, "alert");
                //             return;
                //         }
                //     });
                // }
                if(data[0] !== undefined){
                    // Rooms.selectedCharacterNames = chat[0]['character_names'];
                    // Rooms.selectedCharacters = getIDsByNames(chat[0]['character_names']);
                    // console.log(data[0]['character_names']);
                    // console.log(Characters.id);
                    let selectedCharactersIdBuffer = getIDsByFilenames(data[0]['character_files']);
                    let isMissingChars = false;
                    selectedCharactersIdBuffer.forEach(function(curId, i) {
                        if(curId < 0) // If name doesn't exist in the Characters.id objects array, then curId will be -1
                        {
                            let msg = "Cannot load room. Some characters expected are missing. Please check if you have all the characters.\nRequired Characters: ";
                            let chNameBuffer = "";
                            for(var i = 0; i < selectedCharactersIdBuffer.length; i++)
                            {
                                chNameBuffer = Characters.id[curId].name;

                                // selectedCharactersIdBuffer.length is equal to data[0]['character_names'].length
                                // if(i < selectedCharactersIdBuffer.length - 1)
                                //     msg += data[0]['character_names'][i] + ", ";
                                // else
                                //     msg += data[0]['character_names'][i] + ".";

                                if(i < selectedCharactersIdBuffer.length - 1)
                                    msg += chNameBuffer + ", ";
                                else
                                    msg += chNameBuffer + ".";
                            }
                            callPopup(msg, "alert");
                            isMissingChars = true;
                            return;
                        }
                    });
                    // Don't continue if one or more characters is missing
                    if(isMissingChars)
                        return;

                    // Below block of code is for removing the redundant character_names attribute in selected room if exists, and removing the flag updated from the response.
                    if(data[0]['updated']) {
                        delete Rooms.id[Rooms.getIDbyFilename(filename + ".jsonl")].chat[0].character_names;
                        Rooms.id[Rooms.getIDbyFilename(filename + ".jsonl")].chat[0].character_files = data[0]['character_files'];
                        delete data[0].updated; // The flag should now no longer be needed, and must be removed before the next process.
                    }

                    // console.log("Incorrect/Error");
                    clearChat();
                    chat.length = 0;
                    for (let key in data) {
                        chat.push(data[key]);
                    }
                    //chat =  data;
                    // const ch_ext = ".webp"; // Assumed that character files would always have .webp extension
                    // Characters.selectedID = Characters.getIDbyFilename(chat[0]['character_names'][0]+ch_ext);
                    // Rooms.selectedCharacterNames = chat[0]['character_names'];
                    Rooms.selectedCharacters = getIDsByFilenames(chat[0]['character_files']);

                    let chNames = [];
                    Rooms.selectedCharacters.forEach(function(curId, i) {
                        chNames.push(Characters.id[curId].name);
                    });
                    Rooms.selectedCharacterNames = chNames;

                    Rooms.activeCharacterIdInit(chat[chat.length-1]);
                    chat_create_date = chat[0]['create_date'];
                    winNotes.text = chat[0].notes || "";
                    winNotes.strategy = chat[0].notes_type || "discr";
                    if(!winNotes.text || !winNotes.text.length) {
                        let defaultWpp = '[Character("'+Characters.id[Characters.selectedID].name+'"){}]';
                        try {
                            let parsed = WPP.parse(Characters.id[Characters.selectedID].description);
                            if(parsed[0] && parsed[0].type && parsed[0].type.length && parsed[0].name && parsed[0].name.length) {
                                defaultWpp = '[' + parsed[0].type + '("' + parsed[0].name + '"){}]';
                            }
                        } catch(e) { /* ignore error */ }
                        winNotes.wppText = defaultWpp;
                    }
                    chat.shift();
                    assignIDsByFilenames();
                }else{
                    chat_create_date = Date.now();
                }
                //console.log(chat);
                getChatResult();
                loadRoomSelectedCharacters();
                saveChatRoom();
                // console.log(data[0]);
                
                textareaAutosize($('#room_scenario'));
            },
            error: function (jqXHR, exception) {
                getChatResult();
                console.log(exception);
                console.log(jqXHR);
            }
        });
    }
Note that the clearChat() function (and chat.length = 0 assignment) is already called in this function, calling it before calling this function is redundant