Having trouble with comment tags and event pages

KieronGryph

Veteran
Veteran
Joined
Dec 12, 2012
Messages
40
Reaction score
0
First Language
English
I've set up this script to change the screen tint after checking the very first comment command on every event within the current map.

It works just fine whenever I move to a new map, it checks the comments again; but what if I wanted to check the comments again

after I've changed event pages, and thus changing the map's tint?

I've tried calling the method: kg_setup_notes() again from various other methods. Currently it's from Game_Map refresh().

I always get the same error when I change the event page

ERROR:  Script **Elysia Core** line 57:NoMethodError occurred.

                undefined method '[]' for nil::NilClass

Is there any better way of checking if an event's page has changed?

The tags I'm using are these: Page1 <grph tint: night> ; Page2 <grph tint: twilight>

Full Script Below

Code:
=begin#==============================================================================# ╔════════════════════════════════════════════=═════=═══╤═══════╤═══════════╗ ║ Elysia Core Script                                   │version│  updated  ║ ║ By: KieronGryph                                      │ 1.0   │  1/17/14  ║ ╚═════════════════════════════════════════════════=════╧═══════╧═══════════╝#-------------------------------------------------------------------------------# Changelog   #---------------------------------------------------------------------------------=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--                              ---------------                           #Event Comment Tags #                              ---------------*NOTICE* Event Comment Tags will only work if the comment is the event's very         first command.         Set map's default tint: <grph tint: tint name>  Adding this to an event's comment will set the current map's tint to one  specified here by it's name. It will also prevent the changing of the time  from affecting the tint for the current map. Tint can still be temporally  changed using the Tint Screen event command, until you leave the map.--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--#==============================================================================#=end  Graphics.resize_screen(640,480)class Game_Map#==============================================================================# * Public Instance Variables#==============================================================================  attr_accessor :tint_name  attr_accessor :can_change_tone  attr_reader   :comment#-------------------------------------------------------------------------------  alias kg_core_game_map_old_setup_kg   setup  def setup(map_id)    kg_core_game_map_old_setup_kg(map_id)    init_attr()    kg_setup_notes()  end #alias setup    alias kg_core_old_game_map_refresh_kg   refresh  def refresh()    kg_core_old_game_map_refresh_kg#**********************#     #*********************#    #**********************#    kg_setup_notes() #comment this out and the script runs just fine.#**********************#     #*********************#    #**********************#  end #alias refresh    def init_attr()    @tint_name = ""    @can_change_tone = true    @comment = ""  end #init_attr    def get_first_comment(event_id)    if events[event_id].list[0].code == 108      text = []      index = 0      text.push(events[event_id].list[index].parameters[0])      while events[event_id].list[index + 1].code == 408        index += 1        text.push(events[event_id].list[index].parameters[0])      end #while      return text    end #if    return ""  end #get_first_comment    def kg_setup_notes()#~     for event in events #~       id = event[0]    @map.events.each do |i, event|      id = i      p(id)      if get_first_comment(id) != ""        p("Skye")        @comment = get_first_comment(id)        tint_note(id)      end #if    end #.each do  end #setup_notes    def tint_note(id)      for i in @comment        i.match(/<grph tint:\s*(\w+)>/i)        @can_change_tone = false   unless  $1 == nil || $1 == ""        @tint_name = $1            unless  $1 == nil || $1 == ""        screen_tinter(@tint_name)  unless  $1 == nil || $1 == ""      end #for  end #tint_note    #$game_map.screen_tinter("name", duration)  def screen_tinter(tint, duration = 60)    if    tint == "dawn"      $game_map.screen.start_tone_change(Tone.new(-34,-34,34, 0), duration)    elsif tint == "midday"      $game_map.screen.start_tone_change(Tone.new(0,0,0, 0), duration)    elsif tint == "dusk"      $game_map.screen.start_tone_change(Tone.new(51,-25,-34, 0), duration)    elsif tint == "twilight"      $game_map.screen.start_tone_change(Tone.new(0,-68,-25, 68), duration)    elsif tint == "night"      $game_map.screen.start_tone_change(Tone.new(-68,-68,0, 68), duration)    elsif tint == "volcanic"      $game_map.screen.start_tone_change(Tone.new(34,-68,-34, 0), duration)    end #if  end #screen_tinterend #Game_Map
 

Napoleon

Veteran
Veteran
Joined
Dec 29, 2012
Messages
869
Reaction score
97
First Language
Dutch
Primarily Uses
Is there any better way of checking if an event's page has changed?

The tags I'm using are these: Page1 <grph tint: night> ; Page2 <grph tint: twilight>
Code:
class Game_Event < Game_Character  alias nap_ev_text_setup_page_settings setup_page_settings  def setup_page_settings    nap_ev_text_setup_page_settings            # < your code here >  end
 

KieronGryph

Veteran
Veteran
Joined
Dec 12, 2012
Messages
40
Reaction score
0
First Language
English
I've tried adding this code to yours, but I still can't get it working.

Code:
# $game_map.kg_setup_notes()class Game_Event < Game_Character  alias nap_ev_text_setup_page_settings setup_page_settings  def setup_page_settings    nap_ev_text_setup_page_settings            $game_map.kg_setup_notes() #my code here  end #alias setup_page_settingsend #class Game_Event
 

Napoleon

Veteran
Veteran
Joined
Dec 29, 2012
Messages
869
Reaction score
97
First Language
Dutch
Primarily Uses
I only replied to the question regarding how to check if an event page has changed. That is the method to alias because that aliased method is executed when:

- The event is created (note that the other events might not have had their pages setup yet at this time!).

- The event changes it's event page.

That is usually what you need when working with comments. I did not post a solution to your other question. You were not supposed to just copy-paste that example in it because your code is not compatible with that.

Well, here is the answer to your other question then (I'm bad at explaining these things):

It will crash because events is nil on line 57. That is because the events have not been added to the events attr_accessor of Game_Map yet. You can find that out with the print statements.

Then you find out that the game_map tries to call all setup_page_settings for each event. And with your copy-paste code it will loop through all game_map events (even the ones that haven't been initialized yet) FOR EACH EVENT. So if you have 10 events then you try to scan each event page 10x10 = 100 times....

Instead of looping through all of them, just do it event by event. Look at my Event Text script (see my signature). I process them one by one instead of looping through it (which you can only do after Game_Map.setup_events() has been completed). But you tried to do it before that.

Snippet from one of my scripts

Code:
class Game_Event < Game_Character  alias nap_ev_text_setup_page_settings setup_page_settings  def setup_page_settings    nap_ev_text_setup_page_settings            nap_ev_text_commenttag  end      def nap_ev_text_commenttag    return if self.list.nil?        sprite_character = self.sprite    return if !sprite_character        for command in self.list      if command.code == 108                # set text        if command.parameters[0] =~ /<#{NAP_EV_TEXT_CONF::COMMENT_TAG}.*?)>/ix          sprite_character.nap_ev_set_text($1)        end        #<snip>                sprite_character.nap_ev_refresh if refresh      end    end  end # nap_ev_text_commenttag
 

KieronGryph

Veteran
Veteran
Joined
Dec 12, 2012
Messages
40
Reaction score
0
First Language
English
Okay, thanks. I'm still quite new to scripting in any language, but I think I understand what to do now.
 

Napoleon

Veteran
Veteran
Joined
Dec 29, 2012
Messages
869
Reaction score
97
First Language
Dutch
Primarily Uses
No worries. If you're totally new to programming/scripting in general then that is some pretty nice code.
 

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

Latest Threads

Latest Profile Posts

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'??
Yay, now back in action Happy Christmas time, coming back!






Back in action to develop the indie game that has been long overdue... Final Fallacy. A game that keeps on giving! The development never ends as the developer thinks to be the smart cookie by coming back and beginning by saying... "Oh bother, this indie game has been long overdue..." How could one resist such? No-one c
So I was playing with filters and this looked interesting...

Versus the normal look...

Kind of gives a very different feel. :LZSexcite:

Forum statistics

Threads
105,855
Messages
1,017,007
Members
137,563
Latest member
MinyakaAeon
Top