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

Tsukihime

Veteran
Veteran
Joined
Jun 30, 2012
Messages
8,564
Reaction score
3,846
First Language
English
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.

module RPG class Event::page 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:


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

Does it look good?

Is there a more efficient way to do this?
 
Last edited by a moderator:

Zeriab

Huggins!
Veteran
Joined
Mar 20, 2012
Messages
1,268
Reaction score
1,422
First Language
English
Primarily Uses
RMXP
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
 

Tsukihime

Veteran
Veteran
Joined
Jun 30, 2012
Messages
8,564
Reaction score
3,846
First Language
English
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.
 

TheoAllen

Self-proclaimed jack of all trades
Veteran
Joined
Mar 16, 2012
Messages
5,592
Reaction score
6,522
First Language
Indonesian
Primarily Uses
RMVXA
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.
 

Another Fen

Veteran
Veteran
Joined
Jan 23, 2013
Messages
564
Reaction score
275
First Language
German
Primarily Uses
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.
 
Last edited by a moderator:

Tsukihime

Veteran
Veteran
Joined
Jun 30, 2012
Messages
8,564
Reaction score
3,846
First Language
English
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.
 
Last edited by a moderator:

TheoAllen

Self-proclaimed jack of all trades
Veteran
Joined
Mar 16, 2012
Messages
5,592
Reaction score
6,522
First Language
Indonesian
Primarily Uses
RMVXA
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
 

Balrogic

Veteran
Veteran
Joined
Dec 19, 2014
Messages
40
Reaction score
17
First Language
English
Primarily Uses
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".
 

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::please(false, true) $game_message.num_input_digits_max = MoreNumbers::please(true, true) MoreNumbers::please(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.
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.
 
Last edited by a moderator:

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD
How many parameters is 'too many'??

Forum statistics

Threads
105,865
Messages
1,017,059
Members
137,574
Latest member
nikisknight
Top