Global Interpreters for common events.

GGZiron

Veteran
Veteran
Joined
Nov 6, 2016
Messages
75
Reaction score
25
First Language
Bulgarian
Primarily Uses
RMVXA
What is a script with such a boring name for?

Did you ever happen to use a parallel common event? It will run all across the maps. But alas, it will restart once you transfer to a new map. And thus, if you don't want that to happen, you would need heavy eventing.
The first photo shows the common event I made.
Second photo is how it reached to the third message on it's execution.
Third photo shows what happens once the player transfers to another map, while the event still works.

Well, that won't happen anymore with this script :). In the same example, the third image would show the forth message of the common event, if my script were activated.

This script works only with common events!!!

So, why do the common events restart?
What I see of it, it is because their interpreter is assigned to class instance variable, which is erased once you transfer to another map. In my script, the interpreters are stored in global array, which is also added to the save file.

What it is that interpreter anyway?
The interpreter is class in the RPG Maker, that reads and interpret events code, and execute it. Which is why it is so important to be preserved when the player transfers to another map, if we don't want the common event to restart its execution.

You don't want all common events to have global interpreter?
There are settings. You can fill an array with the id's of the common events you want to have global interpreter, or set all to work with it (which I am not sure how much that will affect the productivity).

Here is the script:
Code:
=begin
Author:GGZiron
Script Name: Global Interpreters
Term of use: Free both for comercial and non comercial use. Credit me
if you are going to use it. Do not share directly on other forums. Give link
instead.
Optionally, you can send me link to check your finished game, if
my script is used on it.

Version 1.0. Date of release: 22 May 2018

Version 1.1 Date: 26 May 2018
Changelog:
Added additional aliases for more compability. Also fixed one part of my
code that I did not liked.

About the script: Did you ever had to use parallel process event, across the maps,
without it to restart everytime you transfer?
This script does just that, but only with the common events.
It does that by adding the common event interpreters into global array.
This global interpreter goes into the save file too.
You have the option to set this to work for all common events,
or only those, which id's are included in the array bellow, in the Settings
header.

=end

module GGZiron_GlobalInterpreter # don't touch this
#=============================Settings======================================
#Add all the common events Id's you want to work
#with global interpreter into this array.
#You can add as many entries you like, as long you follow the syntaxis rules.
COMMON_EVENTS =[1, 2, 3]

#Or alternatively, if you want to work with all common events,
#set the value of this to true:
USE_FOR_ALL = false

#===========================End of settings===================================


#=============================================================================
#                   DO NOT EDIT ANYTHING BELLOW, UNLESS YOU
#                            UNDERSTAND THE CODE
#=============================================================================



end

module DataManager


singleton_class.send(:alias_method, :setup_new_game_old, :setup_new_game)
singleton_class.send(:alias_method, :extract_save_contents_old, :extract_save_contents)
singleton_class.send(:alias_method, :make_save_contents_old, :make_save_contents)

 #======================Edited Original methods===============================

   def self.setup_new_game
      $game_interpreters = []
      setup_new_game_old
      end

    def self.extract_save_contents(contents)
      extract_save_contents_old(contents)
      $game_interpreters  = contents[:interpreter]
      end

    def self.make_save_contents
      ggziron_extended_save_contents
      end

#=============================================================================

#========================New Method===========================================
    def self.ggziron_extended_save_contents
      saves = {}
      saves = make_save_contents_old
      saves[:interpreter] = $game_interpreters
      saves
      end
#=============================================================================
end

class Game_CommonEvent
 
   alias_method :initialize_original, :initialize
   alias_method :refresh_original, :refresh
   alias_method :update_original, :update

#======================Edited original methods================================

  def initialize(common_event_id)
    initialize_original(common_event_id)
    @id = common_event_id
    end
 
  def refresh
    global_interpreter? ?  global_refresh :  refresh_original
    end

  def update
    global_interpreter? ? global_update : update_original
    end
#=============================================================================

#============================New Methods======================================

  def global_update
    if $game_interpreters[@id]
      $game_interpreters[@id].setup(@event.list) unless $game_interpreters[@id].running?
      $game_interpreters[@id].update
      end
    end

  def global_refresh
    if active?
      $game_interpreters[@id] ||= Game_Interpreter.new
    else
      $game_interpreters[@id] = nil
      end
    end

  def global_interpreter?
    work_with_this = GGZiron_GlobalInterpreter::COMMON_EVENTS.include?(@id)
    work_with_all =  GGZiron_GlobalInterpreter::USE_FOR_ALL
    work_with_this  ||  work_with_all
    end
#=============================================================================
end

And here is the header, together with the terms of use:
Author:GGZiron
Script Name: Global Interpreters
Term of use: Free both for comercial and non comercial use. Credit me if you are going to use it. Do not share directly on other forums. Give link instead. Optionally, you can send me link to check your finished game, if my script is used on it.
Version 1.0. Date of release: 22 May 2018
Version 1.1 Date: 26 May 2018
Changelog:
Added additional aliases for more compability. Also fixed one part of my
code that I did not liked.


If I notice something wrong, will try to fix it. You can report bugs too. Cannot promise to fix, but ll try.
 
Last edited:

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

Latest Threads

Latest Profile Posts

Person: "Taxes are bs and money is, too! Anarchy!!" *Literally anything goes wrong* Same Person: "Why hasn't the government fixed this???"
Stream will be live shortly with a session of Haunting Ground! Feel free to drop by!
As for the Coronavirus? Well: "People that spend their life avoiding death are already dead (they're also rich, and I like to spend my life with their money.)"
- R. Sanchez, "Edge of Tomorty: Rick, Die, Repeat"
making pierogi and corrupting my game files wbu

Forum statistics

Threads
94,345
Messages
920,111
Members
124,105
Latest member
acelaces
Top