[RMMV] HOW DO I USE MY OWN CLASSES IN RMMV?
Posts
Pages:
1
I've been following SRDude's plugin tutorials on Youtube, and have been refactoring the code to fit my style. It worked just fine until I decided to create my own class encapsulating the plugin in the tutorial. The code:
For some reason, just having this class in the plugin file makes it do nothing, even though I didn't instantiate the class. I still had the old code set up to run, and it only works when the class is commented out.
What should I do so that I can use my own custom classes in plugins? If it helps, I'm using V1.5.1.
// [Global scope] For Aliasing
var oldExecuteMove = Game_Player.prototype.executeMove;
class MyFirstPlugin
{
run()
{
Game_Player.prototype.executeMove = this._executeMove;
}
_executeMove(direction)
{
// Call the old version first, then whatever new stuff you want to add. This is
// what people call Aliasing in RMMV coding.
oldExecuteMove.call(this, direction);
this.moveStraight(direction);
$gameMessage.add("Hello World!");
}
}
For some reason, just having this class in the plugin file makes it do nothing, even though I didn't instantiate the class. I still had the old code set up to run, and it only works when the class is commented out.
What should I do so that I can use my own custom classes in plugins? If it helps, I'm using V1.5.1.
Hi Tespy,
"class" is not a keyword in javascript, if you press F12 in playtest mode it will open the debug window, and you'll be able to see the syntax errors that prevented your plugin loading.
The closest equivalent to classes is object prototypes, e.g.
Window_ActorCommand.prototype = Object.create(Window_Command.prototype);
Window_ActorCommand.prototype.constructor = Window_ActorCommand;
As well as that, MV has another way of encapsulating plugins, by wrapping everything in a function declaration.
You'll see that if you look in the kadokawa plugins they all wrap the code with
(function() {
})
Which encapsulates all the variables to be local scope instead of global.
I'd suggest starting with some javascript language tutorials - mozilla and w3schools have some good basics.
If you're coming from Ruby, you might find "coffeescript" useful, but it does add a translation step over just dropping scripts in the plugins folder.
If you're coming from Java, ignore the "java" in javascript - the languages have very little in common.
"class" is not a keyword in javascript, if you press F12 in playtest mode it will open the debug window, and you'll be able to see the syntax errors that prevented your plugin loading.
The closest equivalent to classes is object prototypes, e.g.
Window_ActorCommand.prototype = Object.create(Window_Command.prototype);
Window_ActorCommand.prototype.constructor = Window_ActorCommand;
As well as that, MV has another way of encapsulating plugins, by wrapping everything in a function declaration.
You'll see that if you look in the kadokawa plugins they all wrap the code with
(function() {
})
Which encapsulates all the variables to be local scope instead of global.
I'd suggest starting with some javascript language tutorials - mozilla and w3schools have some good basics.
If you're coming from Ruby, you might find "coffeescript" useful, but it does add a translation step over just dropping scripts in the plugins folder.
If you're coming from Java, ignore the "java" in javascript - the languages have very little in common.
1. What do you mean? This post confirms that classes work in RMMV.
2. Unfortunately, nothing happens when I press F12 as you said.
2. I know I could have plugins encapsulated that way, but it's just so... ugly. I prefer to use straight-up functions, which worked just fine for me.
3. I've already been going through JS tutorials, specifically in Codecademy's Intro to JS course; I didn't even bother going through SRDude's tutorials until it taught me classes, which is fairly deep into the aforementioned Codecademy course.
2. Unfortunately, nothing happens when I press F12 as you said.
2. I know I could have plugins encapsulated that way, but it's just so... ugly. I prefer to use straight-up functions, which worked just fine for me.
3. I've already been going through JS tutorials, specifically in Codecademy's Intro to JS course; I didn't even bother going through SRDude's tutorials until it taught me classes, which is fairly deep into the aforementioned Codecademy course.
Pages:
1













