09-07-2017, 12:13 AM
(This post was last modified: 09-07-2017, 12:20 AM by DerVVulfman.)
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.
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:
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:
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
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
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