Retrieve multiline comment (command 108)

● ARCHIVED · READ-ONLY
Started by Napoleon 12 posts View original ↗
  1. Constants:

    EV_COMMENT_TAG = 'minimap' EV_NAME_COMMENT_TAG = 'minimap name' EV_DESC_COMMENT_TAG = 'minimap desc'Snippet:

            # Scan for name/desc commands        if command.code == 108          if command.parameters[0] =~ /<#{Regexp.escape(Minimap::EV_NAME_COMMENT_TAG)}: ([^>]*)>/ix            name = $1          elsif command.parameters[0] =~ /<#{Regexp.escape(Minimap::EV_DESC_COMMENT_TAG)}: ([^>]*)>/ix            desc = $1          end        endThis works perfectly for single-line comment tags.

    But if I have this multi-line comment-tag:
     

    <minimap desc: line 1

    line 2

    last line.>
    It obviously won't work. I tried printing the command.parameters object but it only contains:

    ["line 1"] # output from: p command.parametersThe rest of the text is not there?
  2. Event commands are stored line-by-line, so every line in the editor matches one element in the command list.

    This would be how the interpreter reads a comment:

    Code:
      #--------------------------------------------------------------------------  # * Comment  #--------------------------------------------------------------------------  def command_108    @comments = [@params[0]]    while next_event_code == 408      @index += 1      @comments.push(@list[@index].parameters[0])    end  end
  3. What is code 408? Where can I find a list of the command codes anyway?

    Then what would be the proper way to use a regex on it that scans for a begin- and end-character? Like what If I need to retrieve the 3 lines of text between "<start:" and ">"?

    <start:text1text2text3>I already am inside a for-each loop. Namely the:

    e.list.each{ |command|Scanning ahead from within that loop would be weird and could cause other problems.

    So I'd have to replace the .each with a for-loop instead (index loop) and then increase the index until I find the end character and then concatenate it all?

    Like (peusdo):

    i = 0while i < e.list.length do command = e.list <my stuff here> command.parameters[0] =~ /my start-regex here/ix if $1 @comment = $1 i++ while e.list.code == 108 command.parameters[0] =~ /my end-regex here/ix break if $1 @comment += command.parameters[0] end @comment = @comment[0..-1] # remove ending character ">" end i++endMan that is some seriously messy code... Especially if you have several multi-line comment-calls.
  4. You can look up the most event commands by searching for their name within the interpreter-script. As for the followup-options this list should help (hoping I didn't forget anything):

    Spoiler
    0 : Empty Line401 : Message Text Line
    402 : Choice Handler
    403 : Choice Cancel Handler
    404 : Choice End
    405 : Scroll Text Line

    408 : Comment Line
    411 : Branch Else Handler
    412 : Branch End
    413 : Repeat Above

    505 : Move Route Command (redundant, since the actual route is stored within the leading 205-command)

    601 : Handler for Battle Win

    602 : Handler for Battle Escape
    603 : Handler for Battle Lose
    604 : Battle Processing End

    605 : Shop Processing Item
    655 : Script Command Line
    Regarding your problem: You also could collect the entire comment text first and then scan it. Might not be the fastest way though, but saves you some code.

    As an example (not the cleanest code either^^):

    Code:
    list.each_with_index do |cmd, index|  next  unless cmd.code == 108  text = cmd.parameters[0].dup  text << "\n" << list[index].parameters[0]  while list[index += 1].code == 408   # Scan text for instructions hereend
  5. I've always just written a method for Game_Event, something like so:

    class Game_Event alias initialize_note initialize def initialize(*argv) @note = '' initialize_note(*argv) end def note if @note.nil? @note = '' for command in @page.list next unless [108, 408].include?(@page.code) @note << "@page.parameters[0]#{$/}" end end return @note end alias setup_page_and_note setup_page def setup_page(*argv) @note = nil setup_page_and_note(*argv) endendThat makes note change each time the page does, basically. It doesn't check it every frame, but manages to keep it updated well enough.EDIT: I just realized I didn't answer your question, though. Using the method I've shared, you simply have to scan with the m option on your regex, like so:

    $game_map.events[0].note =~ /<multiline[:= ]+(.+?)>/imTry it out on www.rubular.com (the regex, not the rm code, lol).Note that doing it this way leaves newline characters in the scanned string, filter them out with

    Code:
    result.gsub!($/, ' ')
  6. I was thinking about writing a method like that as well. One that just collects all the comments into one large string (and in an array of strings) once on setup_page. That way not every single script has to loop through it and combine it all. And because some scripts scan until the end of the string, you need both an array of string as well as one large string.

    I would just not call it note but nap_note_array and nap_note_string or something to remain compatible with other (core)-scripts.

    What is the difference between the codes 108 and 408?
  7. Entries with a code of 400 or higher are used as extensions for previous commands. In the editor they begin with a ":" instead of a "@>" and can't be deleted independently.
  8. Ah... So a 108 is a new comment-entry, and a 408 is a 2nd or 3rd, etc. line of that comment?

    Update:

    Confirmed the above. This is nice because now I can create a proper array of strings where each string is a full comment (including it's other lines).

    Code:
    class Game_Event  attr_accessor :nap_note   alias nap_note_setup_page setup_page  def setup_page(new_page)    nap_note_setup_page(new_page)    nap_create_note  end   def nap_create_note    @nap_note = []    str = nil    @list.each { |command|      if command.code == 108 # 108: new comment-item, always the first line.        @nap_note << str if str        str = command.parameters[0].dup      elsif command.code == 408 # 408: comment-line, but not the first one.        str << command.parameters[0]      elsif str # It's not a comment-code, so add the previous str (if any) to the note.        @nap_note << str        str = nil      end    }    p @nap_note  endend
  9. Looks pretty nice, except one little thing:
    Remember that string << other modifies the string itself instead of creating a copy. Since you did not use any duplication commands you are not only altering str but also the original first parameter of the found 108-command.
  10. Thanks and fixed :) .
  11. Ahh, and I forgot: setup_page will also be called when the page is cleared (and thus no list exist). :)
  12. Indeed I totally forgot that one. Fixed as well.

    Code:
    class Game_Event  attr_accessor :nap_note  @nap_note = []   alias nap_note_setup_page setup_page  def setup_page(new_page)    nap_note_setup_page(new_page)    nap_create_note if @list  end   def nap_create_note    @nap_note = []    str = nil    @list.each { |command|      if command.code == 108 # 108: new comment-item, always the first line.        @nap_note << str if str        str = command.parameters[0].dup      elsif command.code == 408 # 408: comment-line, but not the first one.        str << command.parameters[0]      elsif str # It's not a comment-code, so add the previous str (if any) to the note.        @nap_note << str        str = nil      end    }    p @nap_note  endend