Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 RGSS scripting dissections and explinations
#84
(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.



Laughing 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
Yes, Window_Base has a super of its own... it's a child of the hidden Window class

This initialize method in Window_Base has four parameters/arguments:  x, y, width and height.  Laughing  So when we threw in the command of adsf, we basically told Window_Base to use those four values like so...


@windowskin_name = $game_system.windowskin_name
self.windowskin = RPG::Cache.windowskin(@windowskin_name)
self.x = 0
self.y = 0
self.width = 640
self.height = 64
self.z = 100


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
THE INITIALIZE METHOD IN GAME BATTLER DOESN'T HAVE ANY ARGUMENTS OR PARAMETERS!!!!   Shocked  

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?



.
Up is down, left is right and sideways is straight ahead. - Cord "Circle of Iron", 1978 (written by Bruce Lee and James Coburn... really...)
[Image: QrnbKlx.jpg]
[Image: sGz1ErF.png] [Image: liM4ikn.png] [Image: fdzKgZA.png] [Image: sj0H81z.png]
[Image: QL7oRau.png] [Image: uSqjY09.png] [Image: GAA3qE9.png] [Image: 2Hmnx1G.png] [Image: BwtNdKw.png%5B]
Above are clickable links

Reply }


Messages In This Thread
RE: RGSS scripting dissections and explinations - by DerVVulfman - 11-20-2018, 05:07 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
   Help iwth script (RGSS Player crash) Whisper 3 7,675 06-17-2017, 05:03 PM
Last Post: Whisper
  How can I use the cmd of "require" in rgss superegp 2 5,384 11-03-2015, 06:16 AM
Last Post: kyonides
   Scripting in VX vs VX Ace Miharu 5 8,207 02-21-2015, 10:10 AM
Last Post: Taylor
   Combat animations via scripting; How? ZeroSum 2 4,572 09-20-2013, 06:58 PM
Last Post: ZeroSum
Question  RGSS stoped to work Chaos17 5 6,930 02-14-2013, 05:13 PM
Last Post: DerVVulfman
   Ruby, RGSS & General Code Discussion Kain Nobel 6 9,916 12-22-2012, 05:11 AM
Last Post: MechanicalPen
   [Request] Tut. for RGSS Eldur 9 10,612 12-07-2012, 04:27 AM
Last Post: DerVVulfman
   [ASK-RGSS] Behemoth's CBS alike Getsuga_kawaii 0 3,864 04-29-2010, 03:07 PM
Last Post: Getsuga_kawaii
   Scripting I think spazfire 7 8,984 04-12-2010, 03:21 AM
Last Post: DerVVulfman
   Beginner Scripting Tuts? KDawg08 1 3,685 03-31-2010, 11:03 PM
Last Post: Hsia_Nu



Users browsing this thread: