c# to javascript problems

Ninekorn

Villager
Member
Joined
May 19, 2015
Messages
12
Reaction score
0
First Language
English
Primarily Uses
Hi Rpg Maker Community. Ive got only a couple of months under my belt of c# programming with Unity. Things is i've used rpg maker vx ace 1-2 years ago to try up sideview battle poses and things alike but now i am into trying to get a hack and slash game going with Quasi's pluggins. Also I am trying to jump right into scripting but it's different than what I am used to do in Unity. Is it possible to pass an argument to another function just like we do in Unity C#? for example in Unity I would do:


Vector3 playerPos;


Vector3 enemyPos;


Vector3 distanceToEnemy;


public Transform Player;


public Transform Enemy;


void Start()


{


playerPos = transform.position;


getDistance(playerPos);


}


void getDistance(Vector3 playerPos)


{


   enemyPos = Enemy.transform.position;


  Vector3 distanceToEnemy  = playerPos - enemyPos ;


  Debug.Log(distanceToEnemy);


}


How do I translate that do Rpg Maker MV Javascript Scripting lol


(function () {


    Game_Player.prototype.locate = function (x, y) {
        Game_Character.prototype.locate.call(this, x, y);


        var actorX = $gamePlayer.x;
        var actorY = $gamePlayer.y;
        getPos(actorX,ActorY);
            
    };   
})();



(function getPos(actorX, ActorY) {


    Game_Event.prototype.initialize = function (mapId, eventId, actorX, ActorY) {
        Game_Character.prototype.initialize.call(this, actorX, ActorY);


        this._mapId = mapId;
        this._eventId = eventId;
        var array = [];
        array.push(eventId);


        if ((eventX - actorX) <= 1 && (eventX - actorX) >= -1 && (eventY - actorY) <= 1 && (eventY - actorY) >= -1) {
            console.log(this._eventId);
        };


    }
})();


The thing is I don't know how to pass an argument from function to function so in this example I cant access actorX and ActorY from the getPosfunction and can't access this._eventId from the first function. I am a bit confused here. In Unity C# it is so easy to do.
 
Last edited by a moderator:

Zeriab

Huggins!
Veteran
Joined
Mar 20, 2012
Messages
1,269
Reaction score
1,423
First Language
English
Primarily Uses
RMXP
I recommend reading JavaScript: The Good Parts if you can get your hands on it.


JavaScript contains pitfalls when coming from other languages like the weird way scoping works. JavaScript also contain inherently bad design decisions like the implied globals. Knowing about these issues will hopefully help you solve issues faster and encounter less frustration down the line.


From a semantic perspective I find that JavaScript is fairly close to Ruby. So personally I find the Ruby-style of programming is easier translated to JavaScript than C#. Especially code that lends itself towards a functional programming style.


Good luck~
 
Last edited by a moderator:

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

Latest Threads

Latest Posts

Latest Profile Posts

Day 9 of giveaways! 8 prizes today :D
He mad, but he cute :kaopride:

Our latest feature is an interview with... me?!

People4_2 (Capelet off and on) added!

Just beat the last of us 2 last night and starting jedi: fallen order right now, both use unreal engine & when I say i knew 80% of jedi's buttons right away because they were the same buttons as TLOU2 its ridiculous, even the same narrow hallway crawl and barely-made-it jump they do. Unreal Engine is just big budget RPG Maker the way they make games nearly identical at its core lol.

Forum statistics

Threads
106,040
Messages
1,018,470
Members
137,821
Latest member
Capterson
Top