Lihinel

Veteran
Veteran
Joined
Nov 9, 2013
Messages
271
Reaction score
339
First Language
German
Primarily Uses
Okay, it just hit me, it should have been this.drawName(); so it was a Syntax error on my part, problem is no tutorial I read said how to use a method/function, only how to define it.


-------------------------
Just started out with JS and am a bit uncertain why the following code works, but my attempt at changing and modularising it lead to some problems. First the original:
Scene_Title.prototype.drawGameTitle = function() {

// Background
var bitmap = ImageManager.loadTitle1('TitleBG');
var bg = new Sprite(bitmap);
this._bg = bg;
this.addChild(bg);

...

// Title Name
var bitmap = ImageManager.loadTitle1('TitleName');
var titleName = new Sprite(bitmap);
this._titleName = titleName;
this._bg.addChild(titleName);
}

I wanted to change it so that all my sprites are added in their own sub-methods, or in this case functions:

...


// Title Name
Scene_Title.prototype.drawName();
}

Scene_Title.prototype.drawName = function() {
var bitmap = ImageManager.loadTitle1('TitleName');
var titleName = new Sprite(bitmap);
this._titleName = titleName;
this._bg.addChild(titleName);
}
Appearently this._bg is undefined in the new function, so what am I doing wrong? Is it a simple Syntax error or have I missed something deeper? (I am most familiar with Ruby where this kind of thing should have worked)
 
Last edited:

TheoAllen

Self-proclaimed jack of all trades
Veteran
Joined
Mar 16, 2012
Messages
6,315
Reaction score
7,845
First Language
Indonesian
Primarily Uses
RMVXA
You don't do this
Code:
Scene_Title.prototype.drawName();
You do this
Code:
this.drawName();

What you're calling is a prototype function.
 

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,147
Reaction score
10,708
First Language
Czech
Primarily Uses
RMMV
problem is no tutorial I read said how to use a method/function, only how to define it.
Go through some c++ tutorials on object oriented programming. The basics should be enough.
 

MushroomCake28

KAMO Studio
Global Mod
Joined
Nov 18, 2015
Messages
3,941
Reaction score
4,853
First Language
EN, FR
Primarily Uses
RMMZ
Theo nailed it: use
Code:
this.drawName();
and not the prototype.
 

Latest Threads

Latest Posts

Latest Profile Posts

 …I think I might need to switch from standard ATK/DEF up/down buffs to parameter altering states. I just had an actor whose usual attack against an enemy does ~25 do a buffed attack against a debuffed enemy for ~600…
just saw that titan quest is free on steam until the 23rd
Zombie status is now complete. I didn't have to do much in the way of changing how healing is applied to undead targets, was just a simple 3 line code. I thought I had to overhaul Game_Action lol. Everything else was doable by events. So.. Zombie: You turn undead. Your element changes to darkness. You're weak to light, you're strong to physical attacks and healing hurts you and revival items will kill you.
My Overworld might be a mix of inspiration from 2D Final Fantasy games, Breath of Fire, Battlechasers: Nightwar, Super Mario World, and Pillars of Eternity. If I can make it more in-depth than just walking from point A to point B, that might do a lot for the gameplay experience. Hmm...

Forum statistics

Threads
115,225
Messages
1,088,218
Members
149,815
Latest member
MaeBski
Top