How to get events' screen coords through javascript?

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,123
Reaction score
10,618
First Language
Czech
Primarily Uses
RMMV
Well, for once Poryg needs help too :D

I want to save coordinates on screen through javascript.

In rpg_objects I found this function, which corresponds to Game data inside Variable operations.
Game_Interpreter.prototype.gameDataOperand

However, when I try to use it, it always throws 0. I noticed that $gameMap has its own interpreter, but doesn't help...

I wouldn't wonder if it couldn't be used as a function though, because there is only one function calling to it, and that is Variable operations, which would mean this function would be accessed only by the engine itself.
 

Jonforum

Veteran
Veteran
Joined
Mar 28, 2016
Messages
1,623
Reaction score
1,431
First Language
French
Primarily Uses
RMMV
rephrase your question, it is not understandable.
and I do not see any script here, you seem are in wrong forum.
add your code and i will try to help you
 

waynee95

LunaTechsDev
Veteran
Joined
Jul 2, 2016
Messages
676
Reaction score
588
First Language
German
Primarily Uses
RMMV
Code:
$gameMap.event(ID).x
$gameMap.event(ID).y
Edit: Sorry, misread that. :rswt
 
Last edited:

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
39,950
Reaction score
13,585
First Language
English
Primarily Uses
RMMV
That's the map coordinates, not the screen coordinates.

Do you NEED to do it via script? The Control Variables command will let you do it, through Game Data.

If you are doing it via a script call, you can use this.character(n).screenX() and this.character(n).screenY(), where n is the event id (no leading zeros).

If you are making a plugin, use $gameMap.event(n).screenX() and $gameMap.event(n).screenY()
 

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,123
Reaction score
10,618
First Language
Czech
Primarily Uses
RMMV
@waynee95 that is map x and map y, not screen x/y :D

@Jonforum I'm trying to get x and y screen coordinates of an event. But not through default rpg maker commands, but through javascript instead.
The function I provided was found inside rpg_objects.
Code:
Game_Interpreter.prototype.gameDataOperand = function(type, param1, param2) {
    switch (type) {
    case 0:  // Item
        return $gameParty.numItems($dataItems[param1]);
    case 1:  // Weapon
        return $gameParty.numItems($dataWeapons[param1]);
    case 2:  // Armor
        return $gameParty.numItems($dataArmors[param1]);
    case 3:  // Actor
        var actor = $gameActors.actor(param1);
        if (actor) {
            switch (param2) {
            case 0:  // Level
                return actor.level;
            case 1:  // EXP
                return actor.currentExp();
            case 2:  // HP
                return actor.hp;
            case 3:  // MP
                return actor.mp;
            default:    // Parameter
                if (param2 >= 4 && param2 <= 11) {
                    return actor.param(param2 - 4);
                }
            }
        }
        break;
    case 4:  // Enemy
        var enemy = $gameTroop.members()[param1];
        if (enemy) {
            switch (param2) {
            case 0:  // HP
                return enemy.hp;
            case 1:  // MP
                return enemy.mp;
            default:    // Parameter
                if (param2 >= 2 && param2 <= 9) {
                    return enemy.param(param2 - 2);
                }
            }
        }
        break;
    case 5:  // Character
        var character = this.character(param1);
        if (character) {
            switch (param2) {
            case 0:  // Map X
                return character.x;
            case 1:  // Map Y
                return character.y;
            case 2:  // Direction
                return character.direction();
            case 3:  // Screen X
                return character.screenX();
            case 4:  // Screen Y
                return character.screenY();
            }
        }
        break;
    case 6:  // Party
        actor = $gameParty.members()[param1];
        return actor ? actor.actorId() : 0;
    case 7:  // Other
        switch (param1) {
        case 0:  // Map ID
            return $gameMap.mapId();
        case 1:  // Party Members
            return $gameParty.size();
        case 2:  // Gold
            return $gameParty.gold();
        case 3:  // Steps
            return $gameParty.steps();
        case 4:  // Play Time
            return $gameSystem.playtime();
        case 5:  // Timer
            return $gameTimer.seconds();
        case 6:  // Save Count
            return $gameSystem.saveCount();
        case 7:  // Battle Count
            return $gameSystem.battleCount();
        case 8:  // Win Count
            return $gameSystem.winCount();
        case 9:  // Escape Count
            return $gameSystem.escapeCount();
        }
        break;
    }
    return 0;
};

However, when I try to use it (which would in this case be something like Game_interpreter.prototype.gameDataOperand(5, 2, 3) for event 2 and screen x, the code throws me 0 every time.
 

Jonforum

Veteran
Veteran
Joined
Mar 28, 2016
Messages
1,623
Reaction score
1,431
First Language
French
Primarily Uses
RMMV
i think he talk about the
DataManager.
for save
am not shure !???
 

Jonforum

Veteran
Veteran
Joined
Mar 28, 2016
Messages
1,623
Reaction score
1,431
First Language
French
Primarily Uses
RMMV
@pory
look at
PHP:
var myScreenEvent = ($gameMap.event(1).x*48); // screen
var myReelScreenMapEvent = $gameMap._displayX * (myScreenEvent); // bindToMap
am not shure but experimente and study this
 
Last edited:

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,123
Reaction score
10,618
First Language
Czech
Primarily Uses
RMMV
@Jonforum I don't think datamanager would hide the screen coords, but will look there just for clarification.

@Shaz Thanks :D Completely forgot about these!
Btw. Since I was building a PIXI based dialog system, where I'm centering dialogs over events, it could do with the variables, but through the script it is much cleaner. Because I already have to take care of 2-5 events (depending on dialogues) and having to use 10 variables to save event locations plus 5 variables to know the event Ids... This way it's just cleaner, having only to save the event IDs.
 
Last edited:

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
39,950
Reaction score
13,585
First Language
English
Primarily Uses
RMMV
The reason your first attempt didn't work is that it's a function of the Game_Interpreter object. If you're building a plugin, unless you put the code in the Game_Interpreter class, it doesn't have access to that object. You were running it out of scope, so there was no this to get the character (event) from. But you could have looked further into that function and seen that, once it has the character (event), it calls exactly the same functions that I gave you :)
 

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,123
Reaction score
10,618
First Language
Czech
Primarily Uses
RMMV
I looked further than that, just not at the right place :D
Well, that was overlooking forest through a tree. Thanks a bunch, you have definitely saved my nerves for a couple of weeks :)
 

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

Latest Threads

Latest Posts

Latest Profile Posts

just mechin' around this morning - MZ edit, feel free to use, must own MZ
I think it is absolutely adorable how Korone says "Eekum Bokum" and the fact she seems so amused by it. :LZSproud:

Justice is "Just ice" without a space
Hi, I was only a silent reader for years, finally I decided to create an account. Greetings all. :)
Hello guys im new here an i hope i can learn something. I am work actully on my own Plugin for a Tactical Grid Based Battle System.

Forum statistics

Threads
103,302
Messages
998,659
Members
134,813
Latest member
Mussman
Top