Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

[Resolved]

Void

Member

I just started using Ccoa's Universal Message Script. In the instructions it says to make a define shortcuts in a Script. So I am assuming that means a seperate script. But when I try to play test the game it says there is a problem with the script that defines the shortcuts. It says...
"UMS Shortcuts" (the name of the script) line 1: NoMethodError occured. undefined method `add_shortcut' for nil:NilClass. I have no idea what that means but does someone know what I did wrong and how to fix it?
 

Void

Member

Sort of. With the script you are supposed to be able to create a shortcut for those. So if you use a bunch of those in the message box you can write a line like so... $game_system.add_shortcut('\c1', '\nm[Bob]\face[bob]\fl') in a new script and so by typing \c1 in the messagebox of the event it will be recognized as typing out all of the others.
 
Are you sure that you have the method defined within Game_System? I use the UMS, and I have no problem with this function. The modification of Game_System for the UMS I have looks like this:
Code:
class Game_System
  attr_accessor :ums_mode # what mode the UMS is in
  attr_accessor :text_skip # whether or not text skip is activated
  attr_accessor :skip_mode # write the text faster while C is pressed, or just skip to the end
  attr_accessor :write_speed # frame delay between characters
  
  attr_accessor :window_height # default height of message window
  attr_accessor :window_width # default width of message window
  attr_accessor :window_justification # default justification of window
  
  attr_accessor :face_graphic # current face graphic
  attr_accessor :face_graphic_justification # justification of face graphic
  attr_accessor :face_graphic_position # position of face graphic
  
  attr_accessor :shadowed_text # whether or not to draw a shadow behind the text
  attr_accessor :shadow_color # the shadow color
  
  attr_accessor :choice_justification # where the choice window is located
  attr_accessor :choice_position # prefered position of choice window
  
  attr_accessor :message_event # what event to center the text over (0 player, -1 to not)
  
  attr_accessor :comic_enabled # using "talk" icons?
  attr_accessor :comic_style   # what type of comic image to use
  
  attr_accessor :name # the text for the name window
  
  attr_accessor :font # the name of the font
  
  attr_accessor :text_justification # the justification of the window text
  
  attr_reader :shortcuts  # user-defined shortcuts
  
  alias ums_initialize initialize
  def initialize
    ums_initialize
    @ums_mode = FIT_WINDOW_TO_TEXT
    
    @skip_mode = WRITE_ALL
    @text_skip = true
    @write_speed = 1
    
    @window_height = 128
    @window_width = 590
    @window_justification = CENTER
    
    @face_graphic = ""
    @face_graphic_justification = LEFT
    @face_graphic_position = CENTER
    
    @shadowed_text = false
    @shadow_color = Color.new(0, 0, 0, 100)
    
    @choice_justification = RIGHT
    @choice_position = SIDE
    
    @message_event = -1
    
    @comic_enabled = false
    @comic_style = TALK1
    
    @name = ""
    
    @font = "Tahoma"
    
    @text_justification = LEFT
    
    @used_codes = ['\v', '\n', '\c', '\g', '\skip', '\m', '\height', '\width', 
                   '\jr', '\jc', '\jl', '\face', '\fl', '\fr', '\b', '\i', '\s',
                   '\e', '\t1', '\t2', '\th', '\nm', '\font', '\p', '\w', '\ws',
                   '\oa', '\oi', '\os', '\ow']
                   
    @shortcuts = {}
  end
  
  def add_shortcut(shortcut, code)
    text = shortcut.downcase
    if !@used_codes.include?(text)
       @shortcuts[shortcut] = code
    end
  end
end
Though by the error supplied in your first post (NoMethodError occured. undefined method `add_shortcut' for nil:NilClass.) proves that the $game_system instance is not actual set to an object. Because the engine interprets it as a nil value, not set to anything. Note, if you added this piece of code anywhere before the $game_system object being instanced, this would result in an error. In Scene_Title, the line below is found:
Code:
$game_system = Game_System.new
If this code is left alone, and set to run after you use the add_shortcut code, it will result in the exact error you got.

Hope this helps.
 

Void

Member

I'm sorry but I'm a real idiot, especially when it comes to scripting. It is defined in the script, like the first portion of script you posted, but I have no idea what you are talking about in the bottom section.
 
I believe you're creating a new script rather than using a Call Script in an event command. Instead of typing the code in a script, use the "Call Script" command on the 3rd event page.

Another option is to directly paste the shortcuts in the script, find the line "@shortcuts = {}" and put them inside the brackets.
 
You are not making a new script, as Regi stated. Using this in a call script would work perfectly fine, just don't use it before $game_system is initialized. If you could post where you put this code, it would help a lot, and thereby it would actually work as you want it to work, as I can fix it pretty simply. Also note that the fact of putting the codes inside the array brackets, as Regi stated as well, would be just as good unless you want the shortcut only to appear at a certain point. If you don't know how to use it, just add the following line after the "@shortcuts = {}":
Code:
add_shortcut("\c1","\nm[Bob]\face[bob]\fl")
Hope this helps.
 

Void

Member

Ok... well I put it under the "@shortcuts = {}" and it did work. The starting page loaded without the error muessage but when I hit new game I get another error message except it's for a different script. Script 'Window_SaveFile' line 32: AugmentError. Undefinded class/module Game_Message.
 
We cannot help you without you posting the block where this error occured. (The block around line 32 in Window_SaveFile apparently). Post this with a marker of which line is 32, and maybe we can toss ya some help.
 

Void

Member

Sorry, I hadn't changed it at all so I didn't post because I assumed it could be looked at from their RMXP Program.
Code:
def initialize(file_index, filename)
    super(0, 64 + file_index % 4 * 104, 640, 104)
    self.contents = Bitmap.new(width - 32, height - 32)
    self.contents.font.name = $defaultfonttype  # "File" (File #) window font
    self.contents.font.size = $defaultfontsize
    @file_index = file_index
    @filename = "Save#{@file_index + 1}.sav"
    @time_stamp = Time.at(0)
    @file_exist = FileTest.exist?(@filename)
    if @file_exist
      file = File.open(@filename, "r")
      @time_stamp = file.mtime
      @characters = Marshal.load(file)
      @frame_count = Marshal.load(file)
      (line 32)@game_system = Marshal.load(file)
      @game_switches = Marshal.load(file)
      @game_variables = Marshal.load(file)
      @total_sec = @frame_count / Graphics.frame_rate
      file.close
    end
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top