RGSS scripting dissections and explinations - Printable Version +- Save-Point (https://www.save-point.org) +-- Forum: Games Development (https://www.save-point.org/forum-4.html) +--- Forum: Code Support (https://www.save-point.org/forum-20.html) +--- Thread: RGSS scripting dissections and explinations (/thread-7103.html) |
RE: RGSS scripting dissections and explinations - DerVVulfman - 09-07-2017 The 'include' command to which Kyo is referring to is one that allows you to 'copy' said methods from one into another. So don't worry about the heiarchy. Modules are the largest of the structures and can hold classes.... and yes, can hold methods. But not the other way around. The include command makes it hella easy, like if two or more classes need the same methods or stuff. EXAMPLE: The Dance Revolution system I am writing has both a player and an editor. Each needs to read a song, play a song and stop the song from playing. Instead of having the same methods appear in both the player and the editor, I could make a single DDR module that has those methods defined, and then use 'INCLUDE' in both my player class and my editor class!!! So the player can just open, play, close the song. And the Editor can open, play, and close the song too. I just create the methods ONCE and include them! Now there is another thing SIMILAR to the include system, and that is called INHERITANCE, but it is not called by any phrase like Inherit Dancing. Nope nope nope. It might be easier for you to see it. Go and look at the 'Window_Selectable' class in your editor, and you may see this: class Window_Selectable < Window_Base Looks odd, no? The '< Window_Base' thingie says 'WE CHEATED!!!' We just made a whole class called Window_Selectable, and we're re-using material from Window_Base without needing to retype it!!! So the Window_Selectable class is not just what you see there, but it also 'inherits' every method found in Window_Base. And if that doesn't blow ya away, look at Window_Command! class Window_Command < Window_Selectable OMG, that's right! Not only is Window_Command everything you read in that script, but everything from Windows_Selectable 'AND' from Window_Base. That is a HELL of a shortcut. But that does explain why Window_Command refers to 'normal_color' which was defined as a method in Window_Base. Window_Command 'inherited' the method and is using it. .... Now before you ask, I know. The Window_Base class begins with class Window_Base < Window Window_Base is actually inheriting special 'hidden' methods from the hidden WINDOW class. The Window class is a special hidden class that deals with things like reading the individual chunks from the windowskin and how to draw them, the borders, etc. WE don't have access to the actual code for the Window class itself, and it might not even be in Ruby but C++. BUT, the Window_Base class can still access the methods and use them. Kewl? RE: RGSS scripting dissections and explinations - Siletrea - 09-07-2017 WOW cool! so basically if I have a 3 module "barns" and I want to merge 1 and 2 into a jumbo module a "warehouse" I can do that by simply including them together like putting fruits into a blender? thats neat! Quote:R,G,B,A? shoudent it be R,G,B,L as in Red Green Blue Luminescence/Light whats the A mean?(me while looking in a mirror) Hello stupid why diddent you think of that!? (my brain) I'm on coffee break leavemealone! in all seriousness though its not brightness but transparency? that makes sense Quote:+ for sums, - for substractions, / for divisions, * for multiplications and % for modulowhat is modulo? I see percentage...like for a grade point average from a school... what is percentage/modulo and what does it DO in scripting? also I keep seeing += and -= and =< and => and == why is the equal sign always there and how does "pacman" and "reverse pacman" work? (also thank you! the more info this thread can gather the better it is for not just me but other noobs reading! please keep going! don't hesitate! my mind is actively cramming this info into every available position to the point where I'm probably gonna forget how to eat for a day or two!) RE: RGSS scripting dissections and explinations - Siletrea - 09-07-2017 (09-07-2017, 05:43 AM)DerVVulfman Wrote: The 'include' command to which Kyo is referring to is one that allows you to 'copy' said methods from one into another. So don't worry about the heiarchy. Modules are the largest of the structures and can hold classes.... and yes, can hold methods. But not the other way around. The include command makes it hella easy, like if two or more classes need the same methods or stuff.so "include" is a common thing for scripting and "pacman" < allows scripters to cheat by using other scripts by effectively piggybacking while still adding something new? and by the looks of things THIS is all throughout the BASE coding for XP! so "Pacman" < can om-nom its way through the program itself and create lil portals between preexisting scripts at any given point so that scripters don't have to rewrite everything everytime? thats sneaky! but actually puts a good use to my naming convention of "Pacman"!...which is ironic as I've called it that for YEARS! what about "reverse pacman" > I see it a few times in the base scripts RE: RGSS scripting dissections and explinations - kyonides - 09-07-2017 Some of your previous questions were answered in my previous post that I kept updating without noticing there were new posts available here... < is lesser than anything you can find to its right hand side 1 < 2 yeah, a one year old baby is younger than a two year old baby, the first one has less experience in general, has not attempted to utter a single word like dad or mom. class MotherClass def how_to_eat @use_fork_or_spoon = true end end class ChildClass < MotherClass end Child inherits attributes or abilities from his or her mother so it learns stuff so the child has learned how to eat properly at the table. Really, he or she will use a fork or spoon to pick a vegetable instead of using his or her hands to lift it. And << two lesser than symbols means an assignment by pushing a value, a kiwi, a number, a name or just anything to an Array. @ary = [] @ary << 1 print @ary #=> [1] RE: RGSS scripting dissections and explinations - Siletrea - 09-07-2017 (09-07-2017, 06:05 AM)kyonides Wrote: Some of your previous questions were answered in my previous post that I kept updating without noticing there were new posts available here... "Pacman" < has been solved but not "reverse Pacman" > along with += -= <= >= any definitions on these would be great! if you have time I wouldn't want to be a bother! RE: RGSS scripting dissections and explinations - kyonides - 09-07-2017 I already explained += with my age example on the first page so take a look at that post to find the answer. >= greater than or equal to if age >= 21 Siletrea.drinks_beer else Siletrea.gets_arrested_for_being_a_minor end modulo... well, it's a leftover, really, that's all the mystery behind it. 7 % 4 = 3 Why 3? Well, 3 doesn't fit in 4 so we still got 3 guys that couldn't enter in a cabinet to make a phone call to Shanghai while the other 4 are calling people in Minnesota, Hawaii, Guatemala and Turkey. You may wonder why most classes define a specific method namely initialize class AOne def initialize @teacher = 'Siletrea' @students = [] @scores = {} end end Well, it tells Ruby, not RGSS, that you need to make a new copy of Class A so every year you can accept new pupils in your AOne class (meaning A-1). You were hired to teach them how to bake stuff in an oven. In 2016 you did this @my_class = AOne.new This year you repeated the same process. @my_class = AOne.new Why it isn't called new? It's complicated, it's Ruby's fault. new does exist, or else you wouldn't get a new class at all, the catch is that its contents are protected except for a method namely initialize. Instead of making you create the whole AOne class object, Ruby does it for you (you or me or VVulf would get headaches if we had to do it manually by coding that on our own.) Since Ruby's intention is to make it easy for us to make new classes, guess what? It simplified it by making stuff for us and it's free as in beer and freedom of speech. This way we will only change or add stuff that we really care about like your students or their scores. RE: RGSS scripting dissections and explinations - Siletrea - 09-07-2017 (09-07-2017, 06:13 AM)kyonides Wrote: I already explained += with my age example on the first page so take a look at that post to find the answer. lol in canada the legal drinking age is 19! so "reverse pacman" is more powerful then "pacman"? but what if you just wanted a number higher then and not equal to? like if age > 18 canadians can get drunk else canadians goto juvi would just having "reverse pacman" > give you an error if the = isent there? RE: RGSS scripting dissections and explinations - Siletrea - 09-07-2017 (09-07-2017, 06:05 AM)kyonides Wrote: Some of your previous questions were answered in my previous post that I kept updating without noticing there were new posts available here... OK so a child is weaker then mom (that makes sense!) even if its written as Mom>child or child<Mom its pretty much the same thing? @ary? ok so @ means instance which is tighter scripting for calling up different parts of the script while $ can jump scripts but is wiggly like a loose cord so the @ means its strong but whats "ary"? and using 2 "pacman's"<< will launch whatever you use it on into a array/boxlist for sorting stuff? RE: RGSS scripting dissections and explinations - DerVVulfman - 09-07-2017 += Now that's a shortcut. Instead of saying a = a + 1, you say a += 1. So each time we see a value of 'a', we add 1 to it. -= Another shortcut. Just like above, this one subtracts from the value in question. < is a 'comparison' operator. It means 'lesser than', and is used in checks like if a < b. If the value of a is 15 and the value of b is 4, then it would be like if 15 is less than 3... Obviously not! That test would FAIL. And yeah, it is also used for the whole inheritance thing. Pacman here does double duty. > is another 'comparison' operator. It means 'greater than', and is used in checks like if a > b. So again, if the value of a is 15 and the value of b is 4, then it would be like if 15 is greater than 3... NOW it works! So that IF... block of code will run! <= and >= respectively mean 'less than or equal to' and 'greater than or equal to' Remember the test of if a < b? If a was set to 5 and b was set to 5, then it would be if 5 was less than 5.... and again, FAIL. But if we did if a <= b, it would work because it was not if a was less than OR EQUAL TO!!! Equal signs!!! What is different between = and == ? Well, the first replaces the contents of a variable and one does a comparison test. a = 4 .... this replaces the contents of variable 'a' with the value of '4' if a == 4 .... this tests if the contents of variable 'a' equals '4' Oh, the MODULO symbol!!! It means the 'remainder' %... otherwise the percentage symbol, it is used in programming to get the REMAINDER value of a division. Like... um... If you divide 9 by 3, your value is 3, right? There's no remainder. It's clean and has nothing fractional. But if you divide 9 by 2, you get 4 1/2 (or 4.5) NOW unless you tell the program that you are dealing with numbers with decimal values (we call them floats), you're only going to end up with whole numbers. So an INTEGER version of 9 divided by 2 would actually equal 4! That's where modulo comes in... it gets the remainder (or leftover part). So the 9 % 2 would be '1' It can handle dividing 8 by 2, and has a leftover 1 remaining. EDIT: Was I typing so long?????? Oh, a child class is not weaker than the parent. It is inheriting all the goodies from the parent class. BUT, the child class 'IS' dependent upon its parent. Without the Parent class of 'Window_Base', you would not be able to run 'Window_Selectable' unless Window_Selectable had all those methods already in it. BUT, you need to have it written class Child < Parent. You are first defining the class itself (class Child) and then attaching the contents of the parent to it ( < Parent). It cannot go in reverse with class Parent > child. Nope nope nope. RE: RGSS scripting dissections and explinations - kyonides - 09-07-2017 I prefer my phone booth explanation on modulo he he XD Yeah, I updated my previous post on this page again... ary or @ary or $ary would just be a shortcut for array (still different because they can be called from different places, $ is global so it's a data eater that checks all classes and modules looking for some new pizza to eat or a new toy to play with... while the others would just look in fewer places for such stuff) but scripters are lazy and write ary instead XP ...like typing hsh instead of hash. class Child < Mother end Yeah, VVulf is right, it's not weaker, it just LEARNS from Mother what she already knows like how to eat or brush his or her teeth or hair (it learns it can execute those methods at will). |