How to alias load_data?

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,111
Reaction score
13,715
First Language
English
Primarily Uses
RMMV
I'm not sure what class or module the load_data command belongs to.  I want to alias it so I can do some extra processing whenever a database file or a map is loaded.  Does anyone know what the correct syntax would be (or how I would find where load_data "lives")?
 

Galv

Veteran
Veteran
Joined
Oct 1, 2012
Messages
1,309
Reaction score
1,580
First Language
English
Primarily Uses
RMMZ
Not sure if this is what you are after, but in rpg_managers.js there is the code for the DataManager object that includes functions for loading different data, including map data.


Nevermind - my bad, wrong RPGmaker :X
 
Last edited by a moderator:

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,111
Reaction score
13,715
First Language
English
Primarily Uses
RMMV
Yeah, Ace :)


Ah, it's a built-in function, like rgss_main:

load_data(filename)



Loads the data file indicated by filename and restores the object.



$data_actors = load_data("Data/Actors.rvdata2")

This function is essentially the same as:

Code:
File.open(filename, "rb") { |f|
  obj = Marshal.load(f)
}

However, it differs in that it can load files from within encrypted archives.




So that shows me where it is, but I'm still unsure how to alias it ...


Edit: think I've got it:

Code:
alias shaz_load_data load_data

def load_data(file)
  p 'loading file ' + file
  shaz_load_data(file)
  # do stuff here
end


Edit2: And now that I've got it, I don't think I can use it for the desired purpose, as database objects are arrays, and a map isn't.  So back to plan 1 (2 separate methods), and at least I learned something new today.
 
Last edited by a moderator:

Another Fen

Veteran
Veteran
Joined
Jan 23, 2013
Messages
565
Reaction score
276
First Language
German
Primarily Uses
Probably not helpful anymore, but for the sake of completion:


load_data is a private instance method from the Kernel module (it should therefore show up when you use Kernel.private_instance_methods(false)).


Good luck with your project.
 
Last edited by a moderator:

Sixth

Veteran
Veteran
Joined
Jul 4, 2014
Messages
2,162
Reaction score
823
First Language
Hungarian
Primarily Uses
RMVXA
Edit2: And now that I've got it, I don't think I can use it for the desired purpose, as database objects are arrays, and a map isn't.  So back to plan 1 (2 separate methods), and at least I learned something new today.


And that's why we got:


object.is_a?(Array)


Which should let you do what you want, I guess.


You can also check the file name itself to know ahead what is loaded exactly. A map file always has "MapNNN" in it's name, the data file for weapons is always named "Weapons.rvdata2", and so on. 
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,111
Reaction score
13,715
First Language
English
Primarily Uses
RMMV
Thanks guys.  
 

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

Latest Threads

Latest Profile Posts

Don't forget, aspiring writers: Personality isn't what your characters do, it is WHY they do it.
Hello! I would like to know if there are any pluggings or any way to customize how battles look?
I was thinking that when you start the battle for it to appear the eyes of your characters and opponents sorta like Ace Attorney.
Sadly I don't know how that would be possible so I would be needing help! If you can help me in any way I would really apreciate it!
The biggest debate we need to complete on which is better, Waffles or Pancakes?
rux
How is it going? :D
Day 9 of giveaways! 8 prizes today :D

Forum statistics

Threads
106,051
Messages
1,018,549
Members
137,837
Latest member
Dabi
Top