Status
Not open for further replies.

werzaque

Canned Dinosaur
Regular
Joined
May 30, 2023
Messages
440
Reaction score
264
First Language
EN/JP/NL
Primarily Uses
RMMZ
This is something that started in a thread in RMMZ Support.

Characters with "isObjectCharacter" set to true will have a offset of 0 (shiftY is 0), as opposed to the default offset of -6 (shiftY is 6) for, errr, normal characters.

The question in the thread was to have a offset for a large car sprite, which would mean that the anchor would have to be more to the middle of the image. So I thought of just creating a "isCarCharacter" that is true when the filename starts with a "#". Downstream, I assign a shiftY of -42 when isCarCharacter is true. Upon testing, this plugin results in all characters to be offset as if isCarCharacter is true... and i can't figure out why this is... please help.

JavaScript:
(function() {
    'use strict';
ImageManager.isCarCharacter = function(filename) {
    const sign = Utils.extractFileName(filename).match(/^[#!$]+/);
    return sign && sign[0].includes("#");
};
ImageManager.isObjectCharacter = function(filename) {
    const sign = Utils.extractFileName(filename).match(/^[#!$]+/);
    return sign && sign[0].includes("!");
};
ImageManager.isBigCharacter = function(filename) {
    const sign = Utils.extractFileName(filename).match(/^[#!$]+/);
    return sign && sign[0].includes("$");
};
Game_CharacterBase.prototype.shiftY = function() {
    return this.isObjectCharacter() ? 0 : (this.isCarCharacter ? -42 : 6);
};
Game_CharacterBase.prototype.setImage = function(
    characterName,
    characterIndex
) {
    this._tileId = 0;
    this._characterName = characterName;
    this._characterIndex = characterIndex;
    this._isObjectCharacter = ImageManager.isObjectCharacter(characterName);
    this._isCarCharacter = ImageManager.isCarCharacter(characterName);
};
Game_CharacterBase.prototype.isCarCharacter = function() {
    return this._isCarCharacter;
};
})();
 
Last edited:

AmVa

Regular
Regular
Joined
Jul 6, 2022
Messages
123
Reaction score
44
First Language
English
Primarily Uses
RMMV
The problem is here:
Game_CharacterBase.prototype.shiftY = function() {
return this.isObjectCharacter() ? 0 : (this.isCarCharacter ? -42 : 6);

The syntax is incorrect... I believe what you intended is this:

Game_CharacterBase.prototype.shiftY = function() { if (this.isObjectCharacter()) return 0 else if (this.isCarCharacter()) return -42 else return 6 };
 

ATT_Turan

Forewarner of the Black Wind
Regular
Joined
Jul 2, 2014
Messages
12,705
Reaction score
11,289
First Language
English
Primarily Uses
RMMV
The syntax is incorrect... I believe what you intended is this:
You're right, but the rest of your post seems misleading to me.

It reads like you're saying the nested ternary statements are incorrect syntax, and they're not.

The error is that isCarCharacter is missing the parentheses to be identified as a function call. Otherwise it's simply checking for the existence of the function, and that's always true.

(also, the parentheses around that second ternary statement are unnecessary)
 

werzaque

Canned Dinosaur
Regular
Joined
May 30, 2023
Messages
440
Reaction score
264
First Language
EN/JP/NL
Primarily Uses
RMMZ
The error is that isCarCharacter is missing the parentheses to be identified as a function call.
The mother of all mothers! I kept combing through rmmz_managers.js to see if there's a step I was missing! Thank you!

(also, the parentheses around that second ternary statement are unnecessary)
I figured, but this was me grabbing at straws lol. Also tried to add a patch for the initMembers. Not sure if needed since apparently it defaults to false anyway...

JavaScript:
(function() {
    'use strict';
ImageManager.isCarCharacter = function(filename) {
    const sign = Utils.extractFileName(filename).match(/^[#!$]+/);
    return sign && sign[0].includes("#");
};
ImageManager.isObjectCharacter = function(filename) {
    const sign = Utils.extractFileName(filename).match(/^[#!$]+/);
    return sign && sign[0].includes("!");
};
ImageManager.isBigCharacter = function(filename) {
    const sign = Utils.extractFileName(filename).match(/^[#!$]+/);
    return sign && sign[0].includes("$");
};
Game_CharacterBase.prototype.shiftY = function() {
    return this.isObjectCharacter() ? 0 : (this.isCarCharacter() ? -42 : 6);
};
Game_CharacterBase.prototype.setImage = function(
    characterName,
    characterIndex
) {
    this._tileId = 0;
    this._characterName = characterName;
    this._characterIndex = characterIndex;
    this._isObjectCharacter = ImageManager.isObjectCharacter(characterName);
    this._isCarCharacter = ImageManager.isCarCharacter(characterName);
};
Game_CharacterBase.prototype.isCarCharacter = function() {
    return this._isCarCharacter;
};
})();

void (alias => {
    Game_CharacterBase.prototype.initMembers = function() {
        alias.apply(this, arguments);
        this._isCarCharacter = false;
    };
})(Game_CharacterBase.prototype.initMembers);
 
Last edited:

Ms Littlefish

Time Traveling Victorian Vampire
Global Mod
Joined
Jan 15, 2014
Messages
9,007
Reaction score
14,555
First Language
English
Primarily Uses
RMMV
This thread is being closed due to being solved. If you need it later, report it to let us know why. Thank you~!
 
Status
Not open for further replies.

Latest Posts

Latest Profile Posts

Help, I can't stop! :kaohi:

alice_ornament.png
I'm happy to join this community.
about this argument. I expressed myself badly, I did it on my own, my English was mixed with Google Translate. And I believe chatGPT didn't even exist in 2016
I have to take sleeping pills :rtear:
Now that the forum is running smoothly, I can run around and react to posts the millisecond they're posted.
patrick-star-spongebob.gif

Forum statistics

Threads
136,812
Messages
1,270,316
Members
180,574
Latest member
PastorGary
Top