Aerosys

Veteran
Veteran
Joined
Apr 23, 2019
Messages
582
Reaction score
551
First Language
german
Primarily Uses
RMMZ
Hey all,

I'm currently practicing Named Parameters. At the moment my code looks like this:

JavaScript:
drawPath({
    start = "south",
    end = "north",
    mapName = "Path",
    weightFunction = undefined,
    thickness = 3,
    mode = "smooth"
} = { }) {

So I can call it by e.g.

Code:
drawPath({ start: "west", end: "east", thickness = 4 })

or

Code:
drawPath()

I'm just wondering if this is the right method to do it, as the method signature with {...} = { } looks a bit weird IMO. By the way, I want to have my code to be compatible with MV.
 

caethyril

^_^
Global Mod
Joined
Feb 21, 2018
Messages
2,743
Reaction score
2,095
First Language
EN
Primarily Uses
RMMZ
This uses two concepts:
  • Destructuring assignment (function arguments { arg1, arg2, arg3 })
  • Default parameters (= {})
It's important to use default parameters because otherwise passing in a non-destructurable value like undefined will cause an error when it attempts to get the parameter values:
  • Uncaught TypeError: Cannot destructure property `arg1` of 'undefined' or 'null'.

Both of these concepts were introduced in ES6. At some point (v1.6.0?) RMMV updated its playtest & deployment apps from ES5 to ES6, so this will work with the latest versions of RMMV. If you want to support older versions then you may have to change your approach a bit. In that case you might find this post helpful:
 

Latest Threads

Latest Posts

Latest Profile Posts

I forgot that forums have profile walls that you can post or comment on, guess I found a new platform to specifically rant about game-related deranged thought or problems that I have. Salut mes amis!
I couldn't help myself, so I edited the tiles a bit and made a birdhouse :LZSsmile: I hope I will finish the town today!Screenshot 2021-09-17 134349.png
How do I find the threads I have watched? It's been so long I've forgotten :kaoswt:
So far, this is how the wall tileset its looking in-editor. :kaoswt2:
1631863283853.png
Still thinking on details to add.
Added a plugin to RMMV Plugin Releases with all relevant info but it looks like the topic wasn't approved for whatever reason. Cool.

Forum statistics

Threads
115,132
Messages
1,087,472
Members
149,637
Latest member
3hunnaz
Top