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 - kyonides - 11-12-2018 Once upon a time, in a very far away sea, there was a hungry shark named $hark who kept lurking around searching for little @fish to bite about 50 times each. Little @fish knew it was better to wait for the best moment to get out of their hiding places so they could find some delicious plancton to eat. If there was any sign of $hark surrounding the area, little @fish would go home immediately. The same happens whenever the plancton is scarce in any particular region of the sea. By the way, I am a shark or that is what some people made me think. RE: RGSS scripting dissections and explinations - Siletrea - 11-13-2018 (11-11-2018, 09:28 PM)DerVVulfman Wrote: Full understanding of what wings are, type of wings... joint coordinate with each other???? ok firstly I have no idea what a XEROX is...and secondly...the superclass thing...its a way of...adding new things into a prexisting system without having to go back to the old script right? the @ symbol still confuses me but I understand the $ alot more now! thanks! RE: RGSS scripting dissections and explinations - DerVVulfman - 11-14-2018 The @ symbol is confusing? Well, it basically means that the variable belongs to THAT particular class. If I made a class called Shelley and a class called Miriam, each might have a variable called @hair_color. I could set the @hair_color variable in the Shelley class to 'sandy_blonde', and set the @hair_color variable in the Miriam class to 'auburn_brown '. Each has its own variable, even though they have the same name. If I tried using the $hair_color value in either class, one would overwrite the other. STUDY TIME: Look at any of the initialize methods in the default classes. They tend to have @instance variables belonging just to them.... mostly. Oh, wow. Um... Yeah. Xerox is the manufacturer of a a popular office copy machine. In fact, it was the essential STANDARD for copiers. So back in the day, we just called copiers 'Xerox', just like how we call adhesive bandages 'Bandaids' Hey, I use phrases like 'oft' for often and other old phrases from before I was borne. BUT I don't think I have ever used 'nary'. So when I said "that your child is a literal XEROX of the parent", I meant it was a near-perfect copy or duplicate. And well, yeah. The super() statement is a way of letting you add new content to an existing method. It's just that the super() statement "IS" the old content and you're writing the new content around it. Code: def goofy_method We could just say, we're taking the original 'goofy_method' method and adding two more statements to the start, and two more statements when the original method would have been done. TEST TIME: So, show me an example of a method using the super() statement. Just an interpretation of what you think it means. This is a no pressure thingie. Just a gauge for discussion to see how I'm doing as a teacher and stuff. More like a test on ME. RE: RGSS scripting dissections and explinations - kyonides - 11-14-2018 Let's make the board's mockup class now! Code: class Forum Now we're gonna create our forum... $save_point = Forum.new $save_point.name = "Save-Point" $save_point.address = "https://www.save-point.org" Mmm it looks fine so far but we do need people populating it, don't we? Code: class ForumMember So let's go make new forum members! @Siletrea = ForumMember.new @Siletrea.name = "Siletrea" @Siletrea.legend = "Making a game about a forgotten robot" @Siletrea.title = "YesterYear developer" @Siletrea.hobbies = ["Play Ace Attorney games too many hours a day", "Reading Dune series of books?", "Dream on making robots", "Love Spyro just because", "3D animation", "Collect stray cats"] @Kyonides = ForumMember.new @Kyonides.name = "Kyonides" @Kyonides.legend = "A lazy scripter that needs to get some sleep" @Kyonides.title = "Dark Scripter" @Kyonides.hobbies = ["Making scripts", "Compiling stuff", "Use Linux distros", "Pick on Siletrea because it's fun!", "Laughing at Spyro", "Calling PodPod Evil PodPöd", "Ignore evil bounter hunters", "Sadly talking to an Argentinian that prefers to use floats and the to_i method instead of multiplying by m and later dividing by 100"] Adding new members to the forum $save_point.members << @Siletrea << @Kyonides But there is no point in registering members only so let's add some admins as well! Code: class ForumAdmin < ForumMember @DerVVulfman = AdminMember.new @DerVVulfman.name = "DerVVulfman" @DerVVulfman.legend = "Looking as furry and ugly as Dilgear" @DerVVulfman.title = "Administrator" @DerVVulfman.hobbies = ["Eating ramen just because", "Skipping lunch almost every single day", "Talk about Doctor Who like a parrot", "Collect stray cats"] @Kirito = AdminMember.new @Kirito.name = "Kirito" @Kirito.legend = "I randomly post stuff on the board unless I broke something!" @Kirito.title = "Technical Administrator" @Kirito.hobbies = ["Making chat bots that only know how to bother innocent sharks but lick anybody else's face instead"] Let's add those new members to the forum's list of admins. $save_point.admins << @DerVVulfman << @Kirito Updating the forum status... $save_point.status = "Avatars are broken, thank Kirito for it :P" Think that super or super() or super(argument1, argument2) and etc. are like a Siletrea that runs to her mother crying a lot because some guy named Kyonides laughed at Spyro the dragon. It's like asking your mother to do you a favor (no arguments needed here) or updating her about what has happened if super gets some arguments like. i.e. Code: class SiletreasMom < Person At the same time it's also what wulfo said, a way that prevents you from typing the same stuff all over again because you got stuff from your mother like, err, hair and eye color, height, a couple of her old books, dunno what else... @instance variable... Why don't we define the term instance first? Let's check what the search box tells us about it. Quote:in·stance It's not extremely simple so let's go rephrase it a little bit... Case 1: Something I can use to teach something to Siletrea or anybody else or anything I can use as a warning in case they are about to make a terrible mistake or somebody that is practically flawless and other people should follow that very same person or a case of a corrupt politican that steals money or pollutes a river while other local politicians haven't done such terrible things before, etc. As a summary it is linked to number one 1 alias picking a single thing. Case 2: Being unique or specific to a person or some stuff, where specific stands for something that describes that person or thing but not another. A good example would be me picking on you while nobody else like wulfo or lani or kirito does the same here. So what's an instance variable? A unique or specific trait or feature that is included in a class and will be sent to a specific copy of that class but not to another unless you pass the same value on purpose. Code: class Female @siletrea = Female.new @siletrea.name = "Siletrea" @another_girl = Female.new @another_girl.name = "Siletrea" In that case both girls would call themselves Siletrea but only because I did it on purpose. @another_girl.name = "Puma" Now the other girl is your cat Puma! Well, that's possible only because I didn't define Female as a human exclusive class so female cats are also included by default. So if we compare both names we can quickly notice that their names are unique, different, specific, not a simple photocopy. Warning! If I go pay a visit to another script, both @siletrea and @another_girl would mean nothing to it so it will tell you they can't be found anywhere. Instance @variables might disappear if they aren't stuck to anything that won't be forgotten by the game any time soon. One "solution" would be using the dollar sign $, which in Siletrea's own dialect it might be called the bunny ear. Making a global variable $girls = [@siletrea, @another_girl] will store them till the game is closed by the player. A better method could be using $game_temp or $game_system or $game_party or even $game_actors to store them via a method (the def guys we keep typing here), just pick a good name for that new method. One could also create a new module like: Code: module Girls RE: RGSS scripting dissections and explinations - DerVVulfman - 11-14-2018 Mr. Potato Head from the movie WARGAMES ©1983 A movie about a gaming hacker who didn't realize he broke into NORAD to play the game 'Globalthermonuclear War' Yeah... um.. Siletrea? Let's ignore him for now. I don't want you to go through sensory or information overload when you're just starting out. And I do want to know how much you comprehend on the current discussion. RE: RGSS scripting dissections and explinations - Siletrea - 11-14-2018 (11-14-2018, 04:05 AM)DerVVulfman Wrote: The @ symbol is confusing? Well, it basically means that the variable belongs to THAT particular class. ok so the @ symbol helps to organize things! even if they have the same name! as long as its in a different line of code it can help differentiate things? hmm the "super" statements... its like small bakesale! the original list of items for sale would be muffins and cupcakes and brownies! BUT somewhere down the line a new seller in the bakesale comes in with cookies and tarts! instead of going to the computer and building up a whole new list from scratch and then having to print everything out and replace the old sign they just take a pen and add the new items on at the bottom of the list! right? RE: RGSS scripting dissections and explinations - DerVVulfman - 11-14-2018 Bottom or TOP actually. I'll be back tonight with the NEXT lesson about the super() statement. UP! UP! AND AWAAAAYYYY!!!! RE: RGSS scripting dissections and explinations - kyonides - 11-15-2018 Siletrea Wrote:hmm the "super" statements... its like small bakesale! $save_point.members << @Siletrea << @Kyonides Girls.add(@siletrea, @another_girl) Those lines would be quite similar to what you described above, even if they handle people or cats. Continuing with your bakery example... Code: class Business Code: class FlourDistribuitor < Business Code: class Bakery < Business Code: @flour_distributor = FlourDistributor.new As you can see both the flour distributor and Puma's Bakery are businesses so they both need to do one thing in common, to prepare their products for distribution or sale at the store. There we called super to let both of them create a new list of products available at the time. It's like a distributor and a bakery sharing the same purchase / stock software like some basic system based on Excel? to make lists. Take into account that both have their own procedures meaning they don't need to do the same steps another business did. So super allowed us to complete a series of required steps to keep both businesses running smoothly. RE: RGSS scripting dissections and explinations - DerVVulfman - 11-17-2018 Before I begin discussing more about methods, I think we should tackle one more type of variable. You've already learned about $global values, variables so powerful that they can be used throughout your project... but also use more memory resources and runs a risk of being overwritten. You've just learned about @instance values, variables that are unique and only get shared throughout a single class... uses less memory resources and lets you stay a bit more organized. Now to learn about local variables!!! Local variables are extremely short-ranged variables and only operate within the method they were created. I could make five methods with a local variable called "julius", and the value of julius won't be shared between them without a lot of effort. Code: def add_values Very basic as examples, these three perform different math functions and the result shows up in the 'my_result' local variable. And when each runs, the my_result value begins as an empty variable holding absolutely NOTHING. So if I was to first run the mult_value method, and then run the add_values method, the value of my_result when I start running the add_values method is absoluely nothing until I add 4+2. It may seem pretty short-sighted. But actually, local variables are easy to use and you can use the same simple names over and over among multiple methods. Code: #-------------------------------------------------------------------------- These three methods are in the Game_Battler class. And guess what? Each has a local variable that all three use! See that letter 'i'? That 'i' is a local variable. Oh, they could have given it another name, but they went with just one letter. In all three methods, the 'i' is a variable that acts like a counter or number-holder. They could have called it index_value with statements like "for index_value in @states", but that might have made too MUCH sense. And I won't go further on what these methods are even doing. Just note that they all use a local value and none of these methods share the value of this local variable between them. So the most powerful is the Global variable (works throughout the largest area) The next powerful is the Instance variable (works throughout a class) The least powerful is the Local variable (stuck to the method it's in) RE: RGSS scripting dissections and explinations - Siletrea - 11-17-2018 Hmmm so global$ accesses everything but is clumsy and takes to much resources to run Instance @ accesses everything within its script andor scripts connected with Pac-Man< Local can only work within one closed off section of its script and is used mostly for clarification or “if” statements Ok... the shark has also made a reasonably understandable example with superclass as well so thanks for that But what does double Pac-Man mean? << does it accesses the entire tree instead of just the prior script? |