What does .new mean?

BlueMage

Slime Lv99
Veteran
Joined
Apr 13, 2019
Messages
116
Reaction score
147
First Language
English
Primarily Uses
RMVX
Hi guys,
I want to ask does it mean to create a new object if we run:
abc = abc.new(1,2)

But then, for example that i need object abc to insert into: tint_start(abc)
how can i straightly write something like: tint_start({1,2}) instead of using .new key
 

MushroomCake28

KAMO Studio
Moderator
Joined
Nov 18, 2015
Messages
2,209
Reaction score
3,577
First Language
English
Primarily Uses
RMMV
.new simply creates an object based on the object you're calling. It comes from C++, where you have static classes. Imagine that you have a prototype model and you want to mass produce it. You're going to reproduce it. That's exactly what .new does: it takes an object and creates another object with the same properties.

In your case:

Code:
abc = Abc.new(1, 2) # By convention, we start classes with a upper case.

# This will create an object based on the Abc class and will name it abc. It will call the initialize function from the Abc class and give it the
# parameter 1 and 2.
# It's also important to note that abc != Abc. You've created a new object.
# You should have somewhere a class to define Abc

class Abc
   def initialize(x, y)
      self.x = x;
      self.y = y;
   end
end
 

BlueMage

Slime Lv99
Veteran
Joined
Apr 13, 2019
Messages
116
Reaction score
147
First Language
English
Primarily Uses
RMVX
Hey thank you very much @MushroomCake28
Your answer helped me understood the problem!
So RPG::BGM.new("BGM Name", volume, pitch).play
mean re-produce BGM class from module RPG?
 

MushroomCake28

KAMO Studio
Moderator
Joined
Nov 18, 2015
Messages
2,209
Reaction score
3,577
First Language
English
Primarily Uses
RMMV
No, "Objects are instances of the class." (https://www.tutorialspoint.com/ruby/ruby_classes.htm , I actually recommend reading this to help you). Vocab, Cache, Sound, DataManager, SceneManager, and BattleManagers are modules, not classes, and therefore you can't really create an object out of them (well... it wouldn't do anything). They are acting more like static classes from C++ (someone should double check this statement cause I'm not a professional programmer that has a degree).

So basically for audio, you don't create an object to play it, you simply call it:

Code:
Sound.play_cursor                        # plays the cursor SE
Audio.bgm_play(name, vol, pitch)  # plays a bgm which is defined in the parameters
What exactly are you trying to accomplish? Or is this a simple learning experience?
 

Engr. Adiktuzmiko

Chemical Engineer, Game Developer, Using BlinkBoy'
Veteran
Joined
May 15, 2012
Messages
14,651
Reaction score
2,978
First Language
Tagalog
Primarily Uses
The default engine uses the RPG::BGM object simply to hold the data needed to be passed on to the Audio.bgm_play method.

So yeah, strictly speaking, you don't even need to use the BGM object to play an audio.

Also, using .new doesnt exactly reproduce the class, it creates an instance of that class. The new object being just an instance of the class, can only access anything the class has.

Reproduction would be more akin to making child classes. They have all properties of the parent class, and can have their own properties not in the parent class.
 
Last edited:

BlueMage

Slime Lv99
Veteran
Joined
Apr 13, 2019
Messages
116
Reaction score
147
First Language
English
Primarily Uses
RMVX
Thanks guys. I got it!
I have another question.
Is there a way to store a script snippet in script list and call it later via script call command in game?
Like create a module/class/method?? and call it? =D
 

Engr. Adiktuzmiko

Chemical Engineer, Game Developer, Using BlinkBoy'
Veteran
Joined
May 15, 2012
Messages
14,651
Reaction score
2,978
First Language
Tagalog
Primarily Uses
If you write it in the script editor, you can call it using the script call event command.

For example, I put this code in the script editor, close it and save the game.

Code:
module Adik
  def test
    p "test!"
  end
end
In game, if I use the script call Adik.test this will call my method above and print the message into the console.
 

BlueMage

Slime Lv99
Veteran
Joined
Apr 13, 2019
Messages
116
Reaction score
147
First Language
English
Primarily Uses
RMVX
If you write it in the script editor, you can call it using the script call event command.

For example, I put this code in the script editor, close it and save the game.

Code:
module Adik
  def test
    p "test!"
  end
end
In game, if I use the script call Adik.test this will call my method above and print the message into the console.
Awesome! Thanks @Engr. Adiktuzmiko , i used to insert bunches of scripts into Game_Interpreter to call them = D
 

Engr. Adiktuzmiko

Chemical Engineer, Game Developer, Using BlinkBoy'
Veteran
Joined
May 15, 2012
Messages
14,651
Reaction score
2,978
First Language
Tagalog
Primarily Uses
The good thing if you put them inside the GE class is that you can script call the method name directly since the script call box is processed inside the GE class itself.

Its useful for small snippets that wont be called by other scripts..

Code:
class Game_Interpreter
  def test
  end
end
If you do it that way, you can just script call it on the event as test
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Please don't create long, boring cutscenes in which characters do nothing but stand around talking.
What if I took a lesson from Half Minute Hero? Let the player get dumb powerful each area, but reset them down to just slightly stronger than before for the next map?
Been averaging 2-3 hours sleep for almost a month now. Starting to space out all the time ^^;
loopk wrote on whtdragon's profile.
Nice to meet you. My name is loopk.
May I use the materials distributed here for adult games for sale?

Thank you in advance.
loopk wrote on Avery's profile.
Nice to meet you. My name is loopk.
May I use the materials distributed here for adult games for sale?

Thank you in advance.

Forum statistics

Threads
94,258
Messages
919,466
Members
123,977
Latest member
Panam
Top