Sup... I've been with some problems with scripting :wacko:
My first question is:If I wanted to add some methods to a script, can i use something like...
class Game_Map
def add_method
#all stuff here
end
end
?
I've seen something as creating a module instead, with a method inside.
Then using like this:
class Game_Map
include Add_module
end
But, for instances...I've seen Blizzard Time and Environment System and he used something like the first code... xD and i really didnt get it...
Now, another problem of mine...For example, yesterday I was changing a script of mine and...it changed scene_map.
I needed to create pictures (on main obviously) and then dispose them right? Something like this:
class Scene_Map
alias apid_change_main main
alias apid_change_update update
def main
@pict = Sprite.new
@pict.bitmap = RPG::Cache.picture("anything")
#.......
apid_change_main
@pict.bitmap.dispose
@pict.bitmap = nil
@pict.dispose
@pict = nil
end
def update
apid_change_update
#stuff using the pict created on main
end
end
This code raised errors as... Sprite disposed and that...
When I tried to do all the script...but not using alias, just changing Scene_Map instead, it worked perfectly xD
So, if someone can help me out with this...(the use of alias and the add of methods into a class...) I would really appreciate (:
See you ~ :)
Ugh... >.< Including modules is bad practice in RMXP. That's why I avoid it like the plague.
As for the problem, don't dispose the bitmap. Since you are loading it through RPG::Cache, you don't need to worry about that.
hmmm why is it a bad practise? if it is can u say me what's the good one? xD
I've seen that logic of including a module in Xiderowg Action Battle system... he really uses it a lot xD
About the bitmap, should i delete this then?
@pict.bitmap.dispose
@pict.bitmap = nil
or just delete first part and leave ' = nil' ?
Remove both parts.
Well, there are several reason why it's bad practice in RMXP.
The first thing is that it's ambiguous to the reader. If you have defined A#method1 and B#method1 and then include B in A which method1 is called?
Second would definitely be stuff that is aliased. You simply can't insert code into an already existing method by including a module.
Another two things are that the code usually becomes very confusing and save data problems. Before I made my own caterpillar script, I was using Fukuyama's and those two problems were present. Are you familiar with the term "spaghetti code"? Well, that was what Fukuyama's script looked like. There was a bunch of modules and class and none of them really made sense. Of course, that could have been because the code was maybe badly structured. As for the save data, since module data was saved, all savegames became completely corrupted when I removed the script. With aliasing you have usually two scenarios. One is that you have additional only classes/methods in the code and the other is that you have additional variables that are being saved. With the latter you can still make a piece of code to "repair" all data corruption in the save files after loading (which basically occurs because the variables are set to nil since they weren't there when the save file was created). Editing any methods which includes adding, removing and aliasing does not affect the save data. Including a module in a class, though, will crash it. Of course, if you add new classes to the save data, they will also crash the game if you try to load the data once the script has been removed, but those are quite rare cases as you don't need to save instances of additional class in most cases.
Hmm I see xD
Well, I really think that XAS system is a "spaghetti code", he uses that logical of including modules into classes and it is all a mess...
Anyway, now i know why to not use that include stuff XD, especially if it deals with save data...
Now, talking about the use of alias...I've tried (again) to use it, this time without bitmap dispose as u said to, and it raises no error...But, the pictures don't even appear XD
Summarizing, no errors are raised...although, the pictures are not used as it is 'coded' on def update xD
Try "@pict.z = 1000" or something like that. The picture is probably just not visible because it's "behind" other stuff.
Well it worked <.< I thought that pictures had a standart priority so i didnt even think it would be a problem xD
Thanks for everything :haha: