When you have many scripts to share, and they all read notes from database items, how do you write your scripts so the methods that read the notes don't overwrite each other? With a normal class method, you'd just alias it each time. But if it's a new method that hasn't been defined in the RPG:: classes, there's nothing to alias.
I mean, when you write them in a way that the notes are loaded at the same time as the database is loaded, and save the data into variables, not so that they're looked at every time you want to check if an item has particular contents in its notes. Like a read_notes method that's called on each object after the $data_* classes are loaded.
I'm thinking of making a script that just defines the method for each class but leaves it empty, and calls them when the database is loaded. Then each script would alias the method. But that means when scripts are shared, the user would need to grab both - the script that they WANT, plus the one that defines the read_notes method.
Or do you just not do it that way, and have every script scan through the notes when and where it wants to know if the specified tag exists?
But if you have several scripts that all have read_notes, doesn't that mean only the first (or the last) will actually run what's in its method?
That's what I'm after. Thanks 🙂
What's the if method_defined?🙂notes) commented out for in the second group? Can it be done either way, or is there a difference between the two?
prefixing them means each script would get its own method, and if you have a ridiculous 50 scripts that all read notes from the database, wouldn't that mean going through each entry in the database 50 times, each time reading all notes, looking for the specific ones to that script?
I guess what I'm thinking of is one script that should be distributed each time (maybe note it as a "Required Script") that will loop through all the objects, reach the notes, and for each note line, call a method that checks if a certain string is in that line. Then provide a dummy, empty method for each object type, which will be aliased by each script. So if I have 50 scripts that all ready notes from the database, it's only looping through the database entries once, and only looping through the notes for each entry once, but every script will get a look-in at the individual note lines and be able to grab its data, if it exists.
@Tsukihime - I don't mean aliasing them with the prefix, it's like Shaz's reply, it would be a new method everytime...
@Shaz - well yes, that will do it for every script... Which I think makes a single Note Manager script nice... basically the method just loads each line that is a feature (you specify how to know if it's a feature, something like feature:name:value), then save value into a hash using name as key...
Yeah, I'm more wanting to avoid repeated passes through the notes for each script. I'd rather something that would read through it once, then let each script take a peek and see if there's any data that is useful for that particular script, but without having each script loop through all of the notes.
Or, really, the original question was about how script B can alias the method, when script A may or may not have defined it in the first place, and if it did define it, making the method run in both scripts. I think the method_defined check will do it nicely.
you could still save each one separately... though for things like Mr. Bubble's Tactics ogre crafting, this might make things unnecessarily more complicated... unless you make it such that multilines are saved as an array/hash inside the original hash...
Yeah - I only use complete tags, not opening/closing with other stuff in between.
Yes, this would be difficult if you were doing it like that. I'm only asking this for my own purposes though, for my own scripts, which all contain everything needed in a single line (like your first two examples), not extended or nested (like your third and fourth examples).
I'm not intending to write a tool for other scripters here - I'm just after something to make it easy to share my own multiple scripts that read the note tags, without having them all loop through the same things or stopping other scripts (of mine) from getting their notes.