One of the problems that I run into a lot with RMXP is that some of the methods that I want to make changes to are not easily modified without consequences. Specifically, 'Passable?' for both the Map and Character. The problem is that if I rewrite the entire method, I know it can severely decrease compatability with other scripts. The alternative would be to run through the iterations made in Passable which can sigificantly decrease performance.
Normally, I dont like the RMXP SDK (any version of it) due to compatability issues, so I try to avoid dependancy on it as much as possible. But I now have a situation where I need to directly alter the way Passable works, and have to create an SDK Style script in order to maintain both compatability and performance. The current community SDK, even up to version 2.4 does not offer an alternative to Passable (Map or Character), and I do need to write my own. I have a lot of reasons for needing to do this.
My question about an SDK Style script is rather generalized.
What are some good practices for writing an SDK Style Script?
There are a number of local variables calculated in the method. Should all of these local variables be passed along to the sub-methods, or only ones that are relevant to that method?
My biggest concern is creating other issues with other scripts, and that is what I want to avoid. Next, I want to offer as much functionality and performance as possible.
Here are two examples:
Example 1
def passable?(x, y, d, event, self_event = nil)
# Determine Passability Bit from Direction
bit = (1 << (d / 2 - 1)) & 0x0f
# Some Comment
value = expensive_method(x, y, d, bit, event, self_event)
end
Example 2
def passable?(x, y, d, event, self_event = nil)
# Determine Passability Bit from Direction
bit = (1 << (d / 2 - 1)) & 0x0f
# Some Comment
value = expensive_method(bit)
end
The difference between the two is the arguments passed to expensive_method. Only one argument is needed for normal operations to get back the expected results. However, for other scripts, more arguments may be needed that are either passed as arguments to the main method (like event, new_x, new_y, etc) in order for modified results to be returned by Aliases from other scripts. In order to maintain performace, is it better to prevent recalculations by passing along more arguments? Some arguments, once excluded, as far as I know, cant be retreived, such as a local variable inside of an iteration. Should that local variable be passed along in an argument to methods that are called within the expensive iterations even if they are not needed by that method?
I am aware I can put *args in the Arguments list for each method. Is that a better way to do this? This topic is highly debatable and will vary from Scripter to Scripter. So I just wanted to get a general idea of how people would like an SDK Style script to be written.
Suggestions?