Is there a better way to collect a group of event comments?

Here's a script that goes through an event page's commands.

It is taken from this script: More Input Digits

All it does is determine whether there's a comment following a "show number input" command and then parses the comment to see if there are any special instructions.

Spoiler
module RPG class Event:😛age alias :th_more_input_digits_list :list def list parse_more_input_digits unless @more_input_digits_parsed th_more_input_digits_list end def parse_more_input_digits @more_input_digits_parsed = true i = 0 while i < @list.size cmd = @list # Number Input command if cmd.code == 103 next_cmd = @list[i+1] # Collect all comments under it comment = "" while next_cmd.code == 108 || next_cmd.code == 408 i += 1 comment << "\n" << next_cmd.parameters[0] next_cmd = @list[i+1] end # Check if there's something special if comment =~ TH::More_Input_Digits::Regex num = $1.to_i cmd.parameters[1] = num end end i += 1 end end endendAll of this is just so that I can do this:
moreInputDigits2.jpg


This is a pretty basic way to iterate over an array.

Does it look good?

Is there a more efficient way to do this?
You can leave a hint through a script call before Input Number command. Personally I find that to be more natural than having a comment with the information afterwards.

How does the @list work with multiple number inputs? Are commands being popped off as you progress through the event list?

*hugs*

 - Zeriab
You can leave a hint through a script call before Input Number command. Personally I find that to be more natural than having a comment with the information afterwards.
I decided to put it after was because if I put it before the command, I need to put it above the show text command as well.


Which would work: set the input type, and then after you're done with it clear it out.

How does the @list work with multiple number inputs? Are commands being popped off as you progress through the event list?
It should iterate the list once and whenever it sees a number input it will look for a comment after it.


This should support multiple number input.
If you're going to do that, you will likely to make your own basic module in case if you want to apply to more event commands. So you can alias the method. Good idea btw.
Don't forget your code is supposed to work for common events too (and perhaps troop event pages). 🙂

It's a neat idea indeed.

I also like Zeriabs idea of replacing the comment by a script call as it would be easy to implement and would automatically allow flexible amounts of digits.
A script call would probably be something like

input_digits(30)and then the actual num input setup would be changed to

Code:
def setup_num_input(params)  $game_message.num_input_variable_id = params[0]  $game_message.num_input_digits_max = params[1]  # new line  $game_message.num_input_digits_max = __________end
Which would be clean and indeed flexible (and requires much less work)My main motivation behind restricting the scope of the functionality to a comment after the command is so that if you made the script call and then FORGOT about it for some reason...and this led to a bug in a different input event...

The comment approach would have prevented this from happening.
This idea is not entirely bad. Just need to do a little more trick

It just same as the show text. Where the actual text is placed on the next index.

It's also more readable 🙂

Back to topic

Does it look good?

Is there a more efficient way to do this?
I heard when you use .size in iteration, it's not a best practice. As my brother already tried (not in Ruby though)

During the iteration check, it calculate the size of the array.

I suggest you to use each or save the size of the list into local variable

Code:
@list.each_with_index |cmd, i|  # Do stuffend
Code:
i = 0size = @list.sizewhile i < size  # Do stuffend
My thinking is more along these lines. Just throw it in a script call before the input number command, only blows up in your face if the user tries to set the number to something stupid like "catlol".
 

Spoiler
module MoreNumbers def self.please(number, x="Sure, no problem!") if x == "Sure, no problem!" @no_problem = true @number = number else return @number if number return @no_problem if x @no_problem = nil @number = nil end endendclass Game_Interpreter alias old_icky_setup_num_input setup_num_input def setup_num_input(params) old_icky_setup_num_input(params) if MoreNumbers:😛lease(false, true) $game_message.num_input_digits_max = MoreNumbers:😛lease(true, true) MoreNumbers:😛lease(false, false) end endend
I wound up taking a very different approach to parsing comments in events, as I tend to be more interested in what's happening in other events rather than the event I'm currently accessing. So, I wrote this earlier today. Detects comments across the entire game map and only returns information when the relevant event is undeleted and on the relevant page.
Spoiler
Code:
class Game_Interpreter  def all_defeated?    remaining = []    $game_map.events.each_value {|event| remaining << event}    remaining.select! {|x| x.list[0].code == 108 &&      x.list[0].parameters == ["Required Battle"] if x.list}    if remaining.length == 0      true    else      $game_self_switches[[:game, :battles, :remaining]] = remaining.length      false    end  endend
Edit: Good thing I posted that, just noticed a bug from having to cancel out of the script window halfway through some changes, courtesy of my bastard cat.

Original thread: https://forums.rpgmakerweb.com/threads/is-there-a-better-way-to-collect-a-group-of-event-comments.36407/