Alternate setting up method for disable-able scripts
ForewordThis is more of for static set-ups (cannot be changed in-game), and also more of just an optimization (I think) from the normal way we set-up scripts in a way that would allow the user to disable it via a setting on the script itself.
Normal Way
Normally, you would do something like this
module SETUSE=trueendclass Game_Battleralias initialize_sample initializedef initialize initialize_sample if SET::USE #do other things endendendPROS: If you swap the module's constant with a game variable/switch for example, then you could dynamically enable/disable the script's works. Again, that is not the purpose of this.Alternate way
Given that the constant could never be changed in-game, it seems a waste to actually do that check everytime, isn't it?
So, take a look at this
module SETUSE=trueendif SET::USEclass Game_Battler alias initialize_sample initialize def initialize initialize_sample #do other things endendendHere, we enclosed the whole class itself within an if. This way, the class itself will only exist if the constant was true (AFAIK, based on minor tests and my limited knowledge). AFAIK, it will only be evaluated once per session, when the scripts are initialized by the engine.Q: Why not just delete the whole script?
A: What if you're just testing yet, and might need to put it back later? This will make that easier to achieve
Q: There's select all then comment out method
A: The examples uses only 1 class, and in that case, yes, the method would suffice. But imagine if you have a script like
module SETUSE_1 = trueUSE_2 = true#and so onendif SET::USE_1class oneendendif SET::USE_2class twoendendthen your user would need to go inside the script and find the specific parts to comment out, you would want to avoid that.Closing
I know this might not really be useful, but I figured I'd present it anyway for the benefit of knowledge. If somebody has a more in-depth tests about this matter, feel free to comment.
data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7
本贴来自国际rpgmaker官方论坛作者:Engr. Adiktuzmiko处,因国际论坛即将永久关站,为了存档多年珍贵资料,署名转载到本论坛存档,由于官方帖子为英文原帖,需要中文翻译请点击论坛顶部切换语言为中文就可以将帖子翻译成中文浏览,方便大家随时查看,原文地址:https://forums.rpgmakerweb.com/threads/alternate-setting-up-method-for-disable-able-scripts.35871/
页:
[1]