RMRK is retiring.
Registration is disabled. The site will remain online, but eventually become a read-only archive. More information.

RMRK.net has nothing to do with Blockchains, Cryptocurrency or NFTs. We have been around since the early 2000s, but there is a new group using the RMRK name that deals with those things. We have nothing to do with them.
NFTs are a scam, and if somebody is trying to persuade you to buy or invest in crypto/blockchain/NFT content, please turn them down and save your money. See this video for more information.
Comprehensive Tutorial: Simple Ruby

0 Members and 1 Guest are viewing this topic.

*
Rep:
Level 82
The initialize method gets called whenever the .new method is called on a class object. So doing something like Scene_Menu.new will implicitly invoke the initialized method. Because this method is usually concerned with setting up default properties, it's worth using it in that manner. You can, however, do what you want. Whatever state the object leaves the initialize method is how that object will appear after the .new is called - until you do something else with the object naturally.

The important thing to check is that the method name you use does not overwrite an existing method that shares the same name. For example, the Object class - which is the superclass of all classes in Ruby - has methods like clone and to_s. If you use those names yourself in a class - without aliasing them first - you will end up overwriting them effectively destroying whatever it used to do. So unless this is intentional, it's worth checking the help file to make sure that the name is free.

So to answer the question, yes you can use any name for a method and put anything in the definition. But if the name already exists, it will be overwritten, which can lead to unknown effects such as not setting up the object correctly or destroying the functionality of an object.
(Why do I always feel like it's the end of the world and I'm the last man standing?)

*
my name is Timothy what's yours
Rep:
Level 79
Hello
2014 Most Missed Member2014 Zero to Hero2014 Best IRC Quote2012 Zero To HeroSecret Santa 2012 ParticipantContestant - GIAW 9For frequently finding and reporting spam and spam bots2011 Zero to Hero
Specific methods are designed to do specific things in RGSS. For example, in some Game classes and all Window and Scene classes, the update method is always used to keep the class' information up to date. The refresh method is called to change the data, what's displayed, etc.. In Scene classes, the main method is used to run the game (VXA handles this differently, though. It uses the SceneManager module to do this), and start is used to set up the scene. Thus, when creating a new Window or Scene class, if you overwrite update, main, or start, make sure you call super. Super calls the method with the same name from the superclass. I really should go over that in the tutorial.
it's like a metaphor or something i don't know

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Best Member2012 Best RPG Maker User (Scripting)2012 Favorite Staff Member2012 Most Mature MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Veteran2011 Favourite Staff Member2011 Most Mature Member2011 Best RPG Maker User (Scripting)2011 Best Use of Avatar and Signature Space2010 Best RPG Maker User (Scripting)2010 Best Use Of Avatar And Signature Space
In Scene classes, the main method is used to run the game (VXA handles this differently, though. It uses the SceneManager module to do this)

What do you mean? In RMVXA, the #main method of Scene classes is still used to process scenes; it's just called from the SceneManager module.

*
my name is Timothy what's yours
Rep:
Level 79
Hello
2014 Most Missed Member2014 Zero to Hero2014 Best IRC Quote2012 Zero To HeroSecret Santa 2012 ParticipantContestant - GIAW 9For frequently finding and reporting spam and spam bots2011 Zero to Hero
I meant that it differs in that VX's main loop calls several methods in its' run (all setting up for and shutting down after the game's processing), one of which is $scene.main, and VXA only calls one, rggs_main{SceneManager.run}. Everything is handled by the SceneManager, but in VX only the Scene's processing is handled by $scene.main.

In other words, I'm not quite sure what I meant.
it's like a metaphor or something i don't know

*
Rep:
Level 82
You're confusing #main with the scripts called Main I think. These Mains are typically run first because the code is not bound within a method and is executed immediately - like the attr_x calls and alias_method are. If you do similar things, like the ever popular

Code: [Select]
($imported ||= {})[:CUSTOMSCRTIPXYZ] = true

then these end up running before Main script is compiled and executed, providing they are above that script. Any scripts below don't execute because Main has told it to call other methods and a cycle continues until the program is closed. That's why the scripts below it are never called - they never get chance to be seen.

The class method called #main isn't the same as calling the contents of the Main script. #main is a method that resides in Scene_Base and is called via $scene.main more often than not - where $scene is simply a variable containing the current Scene object. In #main are the methods for setting up the transition between one scene object and the next, the executing of the current $scene object and the final processing (like deleting any resources) before the object is deleted and the new scene object enters the - well - scene.

When you compare the two #main methods they may look different, but they aren't really. VXA just bundles parts of the method into other methods, whereas VX just lays it all out in #main.

Regarding the differences between the two Main script executions: VX places it's code in a begin/end layout, to show where essentially a block of code exists to be executed in which exceptions and errors can be watched out for. Should an error occur during runtime, it is caught and rescued to give the error notice.

In VXA, the built in function rgss_main is called with SceneManager.run as it's block argument. rgss_main is given it's name by Enterbrain to show where the code begins but all it really does is run the block contents once. You can use it as many times as you want to should you have a use for it. However, it does have the added ability to detect the F12 key being pressed, in which the block is then executed from the beginning again. If you used rgss_main after the default used one in Main, you would likely lose the capability to reset the game using F12, so extreme care should be taken if you ever wanted to use that method for something.
(Why do I always feel like it's the end of the world and I'm the last man standing?)

***
Rep:
Level 83
King in the North!
I hope that since this is stickied I am allowed to post in it even if it is a few months old.  :-[

I wanted to say this was the most comprehensive tutorial on (basic) Ruby I have ever read, and I've been searching for a lot of them for a while now. All the other tutorials seemed to have been written towards people with some knowledge of Ruby, RGSS or whatnot, at least for the ones I've seen. I was surprised I understood it so well because I read things with difficulty (dyslexic). So I'm very happy!  ^-^

Thanks for writing and sharing with us!  :lol:

I hope to see some form of updates in the future!
Winter is Coming


*
my name is Timothy what's yours
Rep:
Level 79
Hello
2014 Most Missed Member2014 Zero to Hero2014 Best IRC Quote2012 Zero To HeroSecret Santa 2012 ParticipantContestant - GIAW 9For frequently finding and reporting spam and spam bots2011 Zero to Hero
Thanks! The age of this topic is in no way relevant to replies.

I would definitely expand on this tutorial if I knew exactly where to go with it. I'm not sure what to do next.
it's like a metaphor or something i don't know

***
Rep:
Level 83
King in the North!
I've seen some lists of "Basic Ruby" before on the web and have seen them mention things called range, loops and conditions included in it. Would they be basic? If so, maybe that...? :)
Winter is Coming


*
Rep:
Level 102
2014 Biggest Narcissist Award2014 Biggest Forum Potato2014 Best Non-RM Creator2013 Best IRC Chatterbox2013 Best Game Creator (Non-RM)Participant - GIAW 112012 Best Use Of Avatar and Signature space2012 Most Successful Troll2012 Best IRC Chatterbox2012 Funniest MemberSecret Santa 2012 ParticipantProject of the Month winner for November 2009For being a noted contributor to the RMRK Wiki2010 Biggest Forum Couch Potato2010 Most Successful Troll2010 Best IRC Chatterbox
This is a good tutorial, Pacman. I don't know where you should expand this to, but you totally should.

*
my name is Timothy what's yours
Rep:
Level 79
Hello
2014 Most Missed Member2014 Zero to Hero2014 Best IRC Quote2012 Zero To HeroSecret Santa 2012 ParticipantContestant - GIAW 9For frequently finding and reporting spam and spam bots2011 Zero to Hero
Thanks Irock :)
it's like a metaphor or something i don't know