The right code for a script call

Yulia

Veteran
Veteran
Joined
Dec 25, 2017
Messages
69
Reaction score
164
First Language
Russian
Primarily Uses
RMMV
Hi! Programming for me is like some alien language so I need some help with script calls.
I want to create a common event that will check if an event with id "1" is close to the player (it's a common event because I need to check this on several maps). I've found two versions of a script call that are a little different (it goes into conditional branch -- script):
1. Math.abs($gamePlayer.x - $gameMap._events[1]._x) + Math.abs($gamePlayer.y-$gameMap._events[1]._y) <= 3;
2. Math.abs($gameMap.event(1).x - $gamePlayer.x) + Math.abs($gameMap.event(1).y - $gamePlayer.y) <= 3
Which one is the correct one for a common event? And what is the difference between $gameMap.event(1).y and $gameMap._events[1]._y ??
 

TWings

The Dragon Whisperer
Veteran
Joined
Jul 26, 2017
Messages
527
Reaction score
860
First Language
French
Primarily Uses
RMMV
To keep it simple, both should work.
"$gameMap.event(1)" and "$gameMap._events[1]" are basically refering to the same data.
 

bgillisp

Global Moderators
Global Mod
Joined
Jul 2, 2014
Messages
13,522
Reaction score
14,255
First Language
English
Primarily Uses
RMVXA

I've moved this thread to Javascript Support. Please be sure to post your threads in the correct forum next time. Thank you.

 

Yulia

Veteran
Veteran
Joined
Dec 25, 2017
Messages
69
Reaction score
164
First Language
Russian
Primarily Uses
RMMV
To keep it simple, both should work.
"$gameMap.event(1)" and "$gameMap._events[1]" are basically refering to the same data.
Thank you!
 

caethyril

^_^
Veteran
Joined
Feb 21, 2018
Messages
2,089
Reaction score
1,508
First Language
EN
Primarily Uses
RMMZ
I realise this is resolved, but to explain a little (since it's been put in Learning JavaScript)...

$gameMap is a Game_Map object. Among other things, this type of object has a list of events present on the map and a "getter" function for getting a value from this list. The former is called the _events property and the latter is the event function. Both belong to the Game_Map object, and since the event function refers directly to the relevant item in _events, they work exactly the same (like @TWings said). Similarly for _x & _y (actual values) vs x & y (getters/setters). =)

It is good practice to use getter/accessor methods like event(id) where possible, since they can help prevent you from (accidentally) changing the value of an object. They do have other uses (e.g. do something whenever the value is checked and/or set) but I don't think MV makes much use of that. :kaoslp:
 

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

Latest Threads

Latest Profile Posts

Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD
How many parameters is 'too many'??

Forum statistics

Threads
105,867
Messages
1,017,062
Members
137,575
Latest member
akekaphol101
Top