Introduction It's something that I've been wondering about for years, would it have been all that hard for Enterbrain to include a spell checker in the default engine? This script will highlight words that don't appear in the dictionary while you're playing your game (let's face it, even the best of us slip up sooner or later! I know I'd rather make the mistake and fix it before anyone else noticed ).
Features This features a British and American dictionary, and it's easily customisable so you can add/remove any words that you like .
Script
code
CODE
#============================================================================== # ** Night_Runner's Spell Checker Script #------------------------------------------------------------------------------ # History: # Date Created: 05/Jun/11 # @> http://www.rpgrevolution.com/forums/index.php?showtopic=50720 # # Description: # This script is designed to highlight words if they do not exist in the # dictionary # # How to Install: # Select and copy this entire piece of code. # In your game, select Tools >> Script Editor # Along the left hand side, scroll all the way to the bottom, right # click on 'Main', and select 'Insert'. # Paste the code in the blank window on the right. # # How to Use: # Below on line 96 selects the British or American dictionary # Line 97 sets whether to remake the dictionary (only needs to be true # for when you testplay and start a new game once) # Line 98 defines what color the word will appear if it is incorrectly # spelled (a pink/purple colour by default) #==============================================================================
#============================================================================== # ** String #------------------------------------------------------------------------------ # Edited to include a split by, which is like the split command, but # holds on to the characters which the split was made by. #==============================================================================
class String #-------------------------------------------------------------------------- # * Split By #-------------------------------------------------------------------------- def split_by(regexp) # Make an array ret = [''] # Set a true/false flag, was the last character part of the regexp or # not last_was_regexp = 0 # Loop through every character in the string for i in 0...self.size # Get the character c = self[i].chr # If the character is part of the regexp if not((c =~ regexp).nil?) # If the last character added was NOT part of the regexp if last_was_regexp == false # Start a new section in the array ret << c # If the last character added WAS part of teh REGEXP else # Continue the string of regexp characters ret[ret.size - 1] = ret[ret.size - 1] + c end # Set the flag to say the last character was part of the regexp last_was_regexp = true # If the character is NOT part of the regexp else # If the last character was part of the regexp if last_was_regexp == true # Then start a new section for the non-regexp ret << c # If the last character was NOT part of the regexp else # Continue the string of non-regexp characters ret[ret.size - 1] = ret[ret.size - 1] + c end # Set the flag to say the last character was NOT part of the regexp last_was_regexp = false end end # Return the array ret end end
#============================================================================== # ** Window_Message #------------------------------------------------------------------------------ # Edited to read the dictionary, and colour the words if they're # spelled incorrectly #==============================================================================
class Window_Message #-------------------------------------------------------------------------- # * Invariables #-------------------------------------------------------------------------- BRITISH_DICTIONARY = true # Set to true/false to load British/American LOAD_DICTIONARY = true # Set to true/false to load/not load the dictionary INCORRECT_WORD_COLOR = Color.new(255, 0, 128) # Red, green, blue #-------------------------------------------------------------------------- # * Alias Methods #-------------------------------------------------------------------------- alias nr_dictionary_initialize initialize unless $@ #-------------------------------------------------------------------------- # * Invariables #-------------------------------------------------------------------------- def initialize(*args) # Load the dictionary language = BRITISH_DICTIONARY ? 'british' : 'american' if $DEBUG file = File.open("Data/#{language}-english.txt") save_data(file.read.split("\n"), "Data/Dictionary.rxdata") end @dictionary = load_data("Data/Dictionary.rxdata") file.close # Run the original initialize return nr_dictionary_initialize(*args) end #-------------------------------------------------------------------------- # * Refresh #-------------------------------------------------------------------------- def refresh self.contents.clear self.contents.font.color = normal_color x = y = 0 @cursor_width = 0 # Indent if choice if $game_temp.choice_start == 0 x = 8 end # If waiting for a message to be displayed if $game_temp.message_text != nil text = $game_temp.message_text # Control text processing begin last_text = text.clone text.gsub!(/\\[Vv]\[([0-9]+)\]/) { $game_variables[$1.to_i] } end until text == last_text text.gsub!(/\\[Nn]\[([0-9]+)\]/) do $game_actors[$1.to_i] != nil ? $game_actors[$1.to_i].name : "" end # Change "\\\\" to "\000" for convenience text.gsub!(/\\\\/) { "\000" } # Change "\\C" to "\001" and "\\G" to "\002" text.gsub!(/\\[Cc]\[([0-9]+)\]/) { "\001[#{$1}]" } text.gsub!(/\\[Gg]/) { "\002" } # Make an array of each word correctly spelled correct_letters = [] # If the text has a word in it for word in text.split_by(/[a-zA-Z']+/) # If the word is in the dictionary, or isn't a word if @dictionary.include?(word) or (word =~ /[a-zA-Z']+/).nil? or @dictionary.include?(word.downcase) # Set the characters to be correct correct_letters << ([true] * word.size) # If the word isn't a forrect word else correct_letters << ([false] * word.size) end end correct_letters.flatten! loop_count = 0 # Get 1 text character in c (loop until unable to get text) while ((c = text.slice!(/./m)) != nil) # If \\ if c == "\000" # Return to original text c = "\\" end # If \C[n] if c == "\001" # Change text color text.sub!(/\[([0-9]+)\]/, "") color = $1.to_i if color >= 0 and color <= 7 self.contents.font.color = text_color(color) end # go to next text next end # If \G if c == "\002" # Make gold window if @gold_window == nil @gold_window = Window_Gold.new @gold_window.x = 560 - @gold_window.width if $game_temp.in_battle @gold_window.y = 192 else @gold_window.y = self.y >= 128 ? 32 : 384 end @gold_window.opacity = self.opacity @gold_window.back_opacity = self.back_opacity end # go to next text next end # If new line text if c == "\n" # Update cursor width if choice if y >= $game_temp.choice_start @cursor_width = [@cursor_width, x].max end # Add 1 to y y += 1 x = 0 # Indent if choice if y >= $game_temp.choice_start x = 8 end # go to next text # Increment the loop counter loop_count += 1 next end # Backup the text colour backup_color = self.contents.font.color.clone # If the word is incorrectly spelled if correct_letters[loop_count] == false # Change the font colour self.contents.font.color = INCORRECT_WORD_COLOR end # Draw text self.contents.draw_text(4 + x, 32 * y, 40, 32, c) # restore the text colour self.contents.font.color = backup_color # Add x to drawn text width x += self.contents.text_size(c).width # Increment the loop counter loop_count += 1 end end # If choice if $game_temp.choice_max > 0 @item_max = $game_temp.choice_max self.active = true self.index = 0 end # If number input if $game_temp.num_input_variable_id > 0 digits_max = $game_temp.num_input_digits_max number = $game_variables[$game_temp.num_input_variable_id] @input_number_window = Window_InputNumber.new(digits_max) @input_number_window.number = number @input_number_window.x = self.x + 8 @input_number_window.y = self.y + $game_temp.num_input_start * 32 end end end
#============================================================================== # ** End of Script. #==============================================================================
In addition to this code, you need the dictionary file: british_english.txt ( 908.05K )
Number of downloads: 19
american_english.txt ( 909.87K )
Number of downloads: 17 Make sure that you save the dictionary in your game's Data folder! Note: RRR changed the name of the dictionary files when I uploaded them, make sure top change the files names to british-english.txt and american-english.txt
Customization Lines 96 - 98 have the code:
CODE
BRITISH_DICTIONARY = true # Set to true/false to load British/American LOAD_DICTIONARY = true # Set to true/false to load/not load the dictionary INCORRECT_WORD_COLOR = Color.new(255, 0, 128) # Red, green, blue
The first option is either true/false, to set the dictionary to British / American spelling respectively The section option is also true/false, to synchronise the dictionary, and will resynchronise the next time you 'testplay' your game. This needs to be set to true done the first time you load the script, and every time you edit the dictionary and want it to reload The last option is the colour of the incorrect word, where 255, 0, 128 is the red, green and blue components respectively (between 0 and 255)
Compatibility This script is only compatible with the default message system at the moment.
Installation Copy and Paste the code into your game's Script Editor (In your game, Tools >> Script Editor) And download the british-dictionary.txt or american-dictionary.txt, depending on which you need, and save the dictionary in your game's Data folder (e.g. C:\Users\Night_Runner\My Documents\RMXP\ProjectDictionary\Data\british-dictionary.txt).
FAQ Well, I've only just uploaded it, so there's no questions yet... Does it work with any custom message systems? Not that I'm aware of, you're more than welcome to try, and if you leave a link to the message system you're using I can try and have a look at converting it for you, but the general answer is no, sorry. It seems to take longer to load my game now Make sure you set the synchronisation switch (line 97) to false after you've loaded the dictionary. Will it stop working when I encrypt my game and give it to others No, you need to manually remove the script before you give a copy of your game to your friends.
Terms and Conditions I really don't mind, credit me if you think it's been useful and I've helped.
Credits Special thanks to the /usr/share/dict/words file on my computer for the default words list.
__________________________
K.I.S.S. Want help with your scripting problems? Upload a demo! Or at the very least; provide links to the scripts in question.
Group: +Gold Member
Posts: 4,136
Type: Scripter
RM Skill: Undisclosed
Heh, I noticed that a little earlier at work but haven't had the chance to comment on it. Let me do it now:
This is. One of the best ideas. I've ever seen for a script. I'm serious. Especially for me, who can't really tell the difference between British and American english and sometimes merges the two.
__________________________
FRACTURE - a SMT inspired game (demo) made by Rhyme, Karsuman and me. Weep and ragequit.
Group: Member
Posts: 89
Type: Developer
RM Skill: Intermediate
QUOTE (Kread-EX @ Jun 4 2011, 02:31 PM)
This is. One of the best ideas. I've ever seen for a script. I'm serious. Especially for me, who can't really tell the difference between British and American english and sometimes merges the two.
Meh that's fine actually. That is pretty much a good way to describe Canadian English.