Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 RGSS scripting dissections and explinations
#6
A variable is like a storehouse to keep data that can be changed. If the data was unchanging, it wouldn't be 'variable' :P

There is a storehouse thingie we have called a 'constant' which also holds data, but it is unchanging. Best to use those in configuration sections where it NEVAH CHANGES!!!!

DEF.... does mean 'define' You use it to define your 'methods'. Methods are those blocks of statements in a class that are meant to do ... something... when it is called. If you call '$game_party.lose_gold', you are running the 'lose_gold' method in the Game_Party class. BUT... you need the 'def' in the start of the name to begin defining the whole block of statements as a method. Methods used to be called 'functions' or 'subroutines' back in the day.

Code:
def my_whole_freakin_example_subroutine
  my statement
  my 2nd statement
  my third statement
end
running 'my_whole_freakin_example_subroutine' would run all the statements inside, and ONLY those inside. Keeps them cozy.

A scripter 'can' write a method that is not part of a CLASS (a collection of methods for you), but it's better to have them inside of a class. You could have a 'lose_gold' method in Game_Party, and a 'lose_gold' method in Game_Troop... and they'd be separate! Seriously? Can a ghost lose gold?

A class is defined as 'a data or code structure'... in other words, it is a BLOCK OF STUFF!!! Basically, a class is a block of methods. A method is ALSO a 'data structure', but it is smaller as it is the block of actual statements performed. Guess what? You can have a thingie that is a collection of classes!!! It's called a module! So a module is a block of classes which is a block of methods which is a block of statements!!!! A module is the "largest" of these stuctures... nothing bigger.

Whoh... brainfreeze

For us scripters, the most edited (module/class/method) of these for RMXP is the RPG::Sprite module, as it houses the method that deals with damage pops n stuff. It kinda looks like this:

Code:
module RPG
  class Sprite
    def damage(value, critical=false)
      my code
      my code
      my code
    end
  end
end

YOU... won't be messing with modules much... unless someone makes a CONFIG module just to keep script settings.

Now, insofar as what Kyo said with the whole *arguments thingie.... This is more for us coders and more advanced.

*arguments (or *args for short) allows you to send MULTIPLE things into a method with just one variable... sorta. Let's look at his code:
Code:
def my_method(name, *arguments)
print name, arguments.class
end

His method called 'my_method' accepts 'what looks like' two parameters ( aka values, variables, arguments, whatever).

The first parameter (value) is a variable named 'name'.

Fine enough. When it gets to print name, it will print the data held in the 'name' variable.

The next parameter is called *arguments. The *arguments parameter is more like a storehouse of MULTIPLE VALUES!!! In otherwords, he shoved a lot of variables into this one sucker. His *arguments value may hold five different defined values, that being class, race, sex, age and weight. [I]Nope, he's defining a character class like 'fighter', 'wizard', 'frog') Not many use *arguments (or *args), but it is a space saver coding-wise.

So when we get to it saying [I]print name, arguments.class[I], it is actually printing the 'name' and whatever the 'class' was passed into *arguments. The end result may print : Aluxes Waste-of-a-hero
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 - 09-07-2017, 12:13 AM

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



Users browsing this thread: