Plugin Parameters Struct Problem

Status
Not open for further replies.

Eliaquim

Raze: The Rakuen Zero's Guardian!
Veteran
Joined
May 22, 2018
Messages
1,358
Reaction score
605
First Language
Portuguese - Br
Primarily Uses
RMMV
Hi people!

Well, I was finishing my plugin when I decided to take all parameters and make a struct for them, to be more organized in the plugin parameters for the users.

Before I make the changes, everything worked fine.

But now, after I have struct parameters, it doesn't work anymore.

In the console, all my parameters(besides the struct ones, the others are returning to me as "undefined").








What's going on?
Do I have to reference them in another way now?
Like:
Eli.Param.SuperTimer.Features["Hold Count?"]
return > "false"
Do I have to parse the parameters again?
 

ct_bolt

Creator
Veteran
Joined
May 3, 2012
Messages
840
Reaction score
341
First Language
Javascript
Primarily Uses
RMMV
There is an example in that timer plugin I gifted to you a few days ago.
(Though that script is pretty intense, and very code heavy, so might not be the best starter example)

At work now but I will help more if you don't get it by time I get home.

Edit:
I think you have it...
Eli.Param.SuperTimer.Features["Hold Count?"]

Does it not work with that?

Edit #2:
Looks like you use spaces in the parameters but not in your actual script. Make sure to have exact property names.
Screenshot_20200207-202536_Chrome.jpg
Correctly done I think it would be:
Eli.Param.SuperTimer.Features["End Common Event"]
 
Last edited:

chaucer

Veteran
Veteran
Joined
Aug 6, 2014
Messages
277
Reaction score
438
First Language
English
Primarily Uses
RMMV
Ok so looking at your script, particularly this section here...

JavaScript:
var Imported = Imported || {};
Imported.Eli_SuperTIler = true;

var Eli = Eli || {};
// TIP : the below line should just be Eli.SuperTImer = {};
// The way it's written insinuates that this name space may already be taken,
// which would only happen if the end user has your plugin installed twice. :x
Eli.SuperTImer = Eli.SuperTImer || {};

// TIP : I would change this to ...
// Eli.SuperTimer.Parameters = PluginManager.parameters('Eli_SuperTimer');
// the reason being, if you make another plugin, and do the same thing,
// you are going to overwrite the parameters for one of the pluigns, which
// could lead to some problems.
Eli.Params = PluginManager.parameters('Eli_SuperTimer');

Eli.SuperTimer.Params = {
    Features: JSON.Parse( Eli.Parameters['Feature'] ),
    // PROBLEM IS BELOW CODE:
    StartCommonEvent: Number( Eli.Parameters['Start Common Event'] ),
    MiddleCommonEvent: Number( Eli.Parameters['Middle Common Event'] ),
    PauseCommonEvent: Number( Eli.Parameters['Pause Common Event'] ),
    EndCommonEvent: Number( Eli.Parameters['End Common Event'] )
    // Insert other parameters here( too lazy ).
}
The issue here is as you stated, you moved these parameters from the main plugin parameters values to a struct.

The way a struct works is just like a javascript object, meaning that these parameters moved into the "Feature" struct. the way you would access them would be as follows.


JavaScript:
Eli.SuperTimer.Params = {
    Features: JSON.Parse( Eli.Parameters['Feature'] ),
    // Below we are still saying that start common event is set at "Start Common Event", and it's not :
    StartCommonEvent: Number( Eli.Parameters['Start Common Event'] ),
}

// the correct way to do this would be like so...

Eli.SuperTimer.Params = {};
Eli.SuperTimer.Params.Features = JSON.Parse( Eli.Parameters['Feature'] ),
Eli.SuperTimer.Params.StartCommonEvent = Number( Eli.Params.SuperTimer.Features['Start Common Event'] );
}
The reason, for this is that all of your parameters are now inside the feature parameter, which you turned into a javascript object, by using JSON.Parse, so now all your parameters must be accessed through that features object that you created.

It's kind of a pain to do this for every plugin, so you can use this code if you'd like it'll automatically parse out your object for you whenever you pass a string to it.

JavaScript:
//--------------------------------------------------------------------------
  function Parse( object )
  { // parse all data in an object
//--------------------------------------------------------------------------

    try {
      object = JSON.parse( object );

     } catch (e) {
      object = object;

     } finally {

      if ( Array.isArray( object ) ) {
        var l = object.length;
        for ( var i = 0; i < l; i++ ) { object[i] = Parse( object[i] ); };

      } else if ( typeof object === 'object' ) {
        for ( var key in object ) { object[key] = Parse( object[key] ); };
      }

     }

     return object;

  };
just add this to your plugin, and just type out...


JavaScript:
Eli.SuperTimer.Params = Parse( PluginManager.parameters('Eli_SuperTimer') );
Edit : sorry my code might be all over the place, xD I accidentally pressed enter so I had to try to type it out quickly so it all made sense, also I was a bit lazy in typing it from the screenshot. :x
 
Last edited:

Eliaquim

Raze: The Rakuen Zero's Guardian!
Veteran
Joined
May 22, 2018
Messages
1,358
Reaction score
605
First Language
Portuguese - Br
Primarily Uses
RMMV
@ct_bolt and @chaucer thank you guys!
I think I get it now.
@chaucer I will try your code! It is a method, right?
The way you explain, I have to change a couple things, but it's not everything as I was thinking.
Thank you!
 

chaucer

Veteran
Veteran
Joined
Aug 6, 2014
Messages
277
Reaction score
438
First Language
English
Primarily Uses
RMMV
No problem at all, and yes, it is indeed a method, just pass the parameters of your plugin to it and it'll return a parsed object of the parameters for you :)
 

Eliaquim

Raze: The Rakuen Zero's Guardian!
Veteran
Joined
May 22, 2018
Messages
1,358
Reaction score
605
First Language
Portuguese - Br
Primarily Uses
RMMV
@chaucer I tested and it works great!
I think the problem is solved then.
But I have one more question:
I know that with your method I can save some time instead of typing every parameter and convert one by one...
But I notice too that it uses a recursive function, right?
I have heard that is a thing that can mess a little bit with performance.
So, using that in plugin parameters, it would be the case?

Write everything one by one, can be tedious work, but it will be best for performance? Even slightly?
Like this: (hahaha)


Do I have to worry about these lots of objects that I made?
OR do I have not to worry about the recursive function and use it without fear?
 

caethyril

^_^
Veteran
Joined
Feb 21, 2018
Messages
1,657
Reaction score
1,110
First Language
EN
Primarily Uses
RMMV
But I notice too that it uses a recursive function, right?
I have heard that is a thing that can mess a little bit with performance.
:kaoswt2: I'm not sure why someone would say that...recursive functions are pretty much equivalent to loops, but often encouraged for readability. I think it should all be OK with @chaucer's solution. :kaojoy:

Just a couple of points on code style...
JavaScript:
// TIP : the below line should just be Eli.SuperTImer = {};
// The way it's written insinuates that this name space may already be taken,
// which would only happen if the end user has your plugin installed twice. :x
Eli.SuperTImer = Eli.SuperTImer || {};
A bit obscure, but it can be handy in situations where someone writes an add-on for the plugin: it allows values to be defined on the plugin's namespace prior to its initialisation and (if the original plugin is written to accommodate it) be retained if appropriate. Can make it easier to write compatibility patches etc, particularly in cases like "sandwich" aliases (added code before and after original method call) which may otherwise require specific replacements or edits of the original plugin.
JavaScript:
      if ( Array.isArray( object ) ) {
        var l = object.length;
        for ( var i = 0; i < l; i++ ) { object[i] = Parse( object[i] ); };

      } else if ( typeof object === 'object' ) {
        for ( var key in object ) { object[key] = Parse( object[key] ); };
      }
This'll work, but I think the Array.isArray part is redundant: arrays are objects (e.g. typeof [1,2,3] yields "object") and their properties can be referenced just like any other object, so you could eliminate the "array" branch. Indexing by number is generally only relevant for arrays when it's important to preserve the order: "10" comes before "2" (string), but 2 comes before 10 (number). :kaothx:
 

ct_bolt

Creator
Veteran
Joined
May 3, 2012
Messages
840
Reaction score
341
First Language
Javascript
Primarily Uses
RMMV
:kaoswt2: I'm not sure why someone would say that...recursive functions are pretty much equivalent to loops, but often encouraged for readability. I think it should all be OK with @chaucer's solution. :kaojoy:
Yep recursive functions are fine just like loops are fine until you use too many or place them incorrectly.
(that's probably where people go wrong and think it's problematic)

JavaScript:
// TIP : the below line should just be Eli.SuperTImer = {};
// The way it's written insinuates that this name space may already be taken,
// which would only happen if the end user has your plugin installed twice. :x
Eli.SuperTImer = Eli.SuperTImer || {};
A bit obscure, but it can be handy in situations where someone writes an add-on for the plugin: it allows values to be defined on the plugin's namespace prior to its initialisation and (if the original plugin is written to accommodate it) be retained if appropriate. Can make it easier to write compatibility patches etc, particularly in cases like "sandwich" aliases (added code before and after original method call) which may otherwise require specific replacements or edits of the original plugin.
Yes indeed I do this with all my plugins anymore just in case anyone wants to create addons and such, or in some rare cases the plugin itself can be installed multiple times such as Hudell's HUD Line plugin. (Which to create multiple lines needed to be installed multiple times by renaming the file).
 
Last edited:

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,003
Reaction score
11,325
First Language
English
Primarily Uses
RMVXA
[CLOSED].[/CLOSED]
 
Status
Not open for further replies.

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

Latest Threads

Latest Posts

Latest Profile Posts

Brioche with a crème patissiere filling is so tasty!
A group of Game creators and others who trying to revive the Feel of Multiplayer and TOWN/ROLEPLAY games
Wow, lots of RPG Maker MV stuff on sale on Steam for 50%-75% off. Steam, why you not tell me?!
looking for help on top secret project
The nick "Toeuia" that I'm using comes from a, idk, you okay the chess game while chit chatting them. The first two are students. Then you know, finally, the champion, and then the champion's sensei. I played like this so many times until suddenly there's another chess master. Very naive but super smart. After he lost, he kinda advised me not to give up on chest. Because the next one was never seen beaten. Touya.

Forum statistics

Threads
99,383
Messages
964,652
Members
131,002
Latest member
SaltedFish
Top