#define scr_saveGame // Saves a game into the Save_games sub-directory as .sav { var file; file = ""; // The entered by the user var fname; // The filename for the save game including .sav suffix and absolute pathname prefix var overwrite; var invalid; invalid = true; // Assume save game name initially invalid overwrite = false; // Set if a file with that name already exists while (file == "" || invalid == true) { // Loop while save game name blank or invalid file = get_string('Enter a name for the save game:#Cannot contain < > \ / ? " * : |##Type CANCEL to cancel save.', ''); if(file == "cancel" || file == "CANCEL") // If CANCEL input in any case immediately exit exit; if(string_pos("<", file) != 0 || string_pos(">", file) != 0 || string_pos("/", file) != 0 || string_pos("\", file) != 0 || string_pos("?", file) != 0 || string_pos('"', file) != 0 || string_pos("*", file) != 0 || string_pos("|", file) != 0 || string_pos(":", file) != 0) { // Save game name contains invalid characters show_message(file + " cannot be saved because the name contains invalid characters.#Click OK and enter a new name."); } else { // Save game name valid invalid = false; } } // Make into filename fname = working_directory + "\Save_games\" + file + ".sav"; while(overwrite != true) { // Loop while a file with that name exists if(!file_exists(fname)) break; // Ask user if want to overwrite file overwrite = show_question("A save game with that name already exists. Do you want to overwrite it?"); if(overwrite != true) { // User does not want to overwrite so ask for new name invalid = true; // New save game name invalid file = ""; // Clear old name while (file == "" || invalid == true) { // Loop while new save game name blank or invalid file = get_string('Enter a new name for the save game:#Cannot contain < > \ / ? " * : |##Type CANCEL to cancel save.', ''); if(file == "cancel" || file == "CANCEL") // If CANCEL input in any case immediately exit exit; if(string_pos("<", file) != 0 || string_pos(">", file) != 0 || string_pos("/", file) != 0 || string_pos("\", file) != 0 || string_pos("?", file) != 0 || string_pos('"', file) != 0 || string_pos("*", file) != 0 || string_pos("|", file) != 0 || string_pos(":", file) != 0) { // Save game name contains invalid characters show_message(file + " cannot be saved because the name contains invalid characters.#Click OK and enter a new name."); } else { // Save game name valid invalid = false; } } // Make into filename fname = working_directory + "\Save_games\" + file + ".sav"; } // Loop exits if user did want to overwrite } // Save the game game_save(fname); show_message("The file has been saved as " + file); }