11-20-2018, 05:07 AM
(This post was last modified: 11-20-2018, 05:10 AM by DerVVulfman.)
(11-17-2018, 06:10 AM)Siletrea Wrote: Instance @ accesses everything within its script andor scripts connected with Pac-Man<
Almost. Not everything within its script. Only everything within its class.
But it CAN be accessed by other classes if some special commands are added. An example of an instance variable being accessed from another script would be like $game_temp.battle_calling scene within the "call_battle' method in Scene_Map. That statement is accessing the 'battle_calling' instance variable in the Game_Temp class.
But accessing instance variables or commands from other classes is another subject.
I love horizontal rule...
Now I take it that you have seen some methods that have parenthesis after their names, methods in the default scripts like this one from Window_Base:
Code:
#--------------------------------------------------------------------------
# * Draw Graphic
# actor : actor
# x : draw spot x-coordinate
# y : draw spot y-coordinate
#--------------------------------------------------------------------------
def draw_actor_graphic(actor, x, y)
bitmap = RPG::Cache.character(actor.character_name, actor.character_hue)
cw = bitmap.width / 4
ch = bitmap.height / 4
src_rect = Rect.new(0, 0, cw, ch)
self.contents.blt(x - cw / 2, y - ch, bitmap, src_rect)
end
Well, you have TWO different names you can use to describe these variables. You can call them Parameters or you can call them Arguments. And in the above example's case, you have three arguments: an actor variable, an x variable and a y variable. They will generally act as local variables for this method and are immediately put to use.
I'm not going to describe all the stuff in this method. HECK no. Not going after graphic manipulation, caches or stuff quite yet. Instead, I want to discuss something else.... The super() statement that I've been talking about.
Have you noticed that I've talked about it having those parenthesis????
The super statement may or may not have parenthesis. But if it does, it might ALSO have arguments thrown in the mix. For those making a window, here is an example of the super statement with parameters thrown in... from the Window_Help class:
Code:
#==============================================================================
# ** Window_Help
#------------------------------------------------------------------------------
# This window shows skill and item explanations along with actor status.
#==============================================================================
class Window_Help < Window_Base
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
super(0, 0, 640, 64)
self.contents = Bitmap.new(width - 32, height - 32)
end
Now you notice that this time the super statement reads: super(0, 0, 640, 64). And this Window_Help class is a child of the Window_Base class. So, it appears that we're copying and using the initialize method from Window_Base, right? Here's the Window_Base.....
Code:
#==============================================================================
# ** Window_Base
#------------------------------------------------------------------------------
# This class is for all in-game windows.
#==============================================================================
class Window_Base < Window
#--------------------------------------------------------------------------
# * Object Initialization
# x : window x-coordinate
# y : window y-coordinate
# width : window width
# height : window height
#--------------------------------------------------------------------------
def initialize(x, y, width, height)
super()
@windowskin_name = $game_system.windowskin_name
self.windowskin = RPG::Cache.windowskin(@windowskin_name)
self.x = x
self.y = y
self.width = width
self.height = height
self.z = 100
end
This initialize method in Window_Base has four parameters/arguments: x, y, width and height. So when we threw in the command of adsf, we basically told Window_Base to use those four values like so...
Yep. It just filled in the BLANKS.
Now that's what it is like if you have a super statement with parameters. It MUST be duplicating a method with an equal number of parameters.
If you are using a super statement with no parenthesis at all, you must be duplicating a method from a parent class that has no arguments or parameters of its own. The update method within Window_Selectable has a super statement that has no parenthesis and no arguments. But that is because it is copying the update method from Window_Base, its Parent class. And the update method in Window_Base has no arguments. Both match!!!!
Now as to super() statements.... a super statement that DOES have parenthesis but no arguments in it.... This is a weird case, and might be easier to see visually. Here's an example of the initialize method in Game_Actor:
Code:
#--------------------------------------------------------------------------
# * Object Initialization
# actor_id : actor ID
#--------------------------------------------------------------------------
def initialize(actor_id)
super()
setup(actor_id)
end
This initialize method has a parameter: actor_id. This method basically CREATES YOUR ACTOR, but you gotta supply the actor's ID from the database.... the actor_id value. However, it has a super() statement. Hrm....
Now, the Game_Actor class is a child of the Game_Battler class. So it is copying the initialize method from its initialize method. Hold up, lookie here!!!
Code:
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
@battler_name = ""
@battler_hue = 0
@hp = 0
@sp = 0
@states = []
@states_turn = {}
@maxhp_plus = 0
So the super() command is used when the method you're creating does have a parameter, but the one it is copying doesn't.
Any questions? Comments? Pastry?
.