Indie Dev

Hello Guest!. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, sell your games, upload content, as well as connect with other members through your own private inbox!

learning to create plugin , having some problem

nickaqua

Villager
Xy$
0.00
Hello , fellow RM-user !
right now , i'm learning Js basic and more specifically , creating plugin

I wanted to create plugin that disable drawing level , HP and MP on MenuStatus, and it works by aliasing the drawActorSimpleStatus and make the level HP and MP draw function disabled

now, I wanted to use Param as a conditional for if ( ), so if the value is true , then the level HP and MP will still drawn and while false , the condition wont met and level HP and MP wont be drawed.

Code:
var Imported = Imported || {};
Imported.Naqua_HideStatus = true;

var Naqua = Naqua || {};

 /*:
 * @plugindesc v 1.0 Hide Status from status bar
 * @author nickqua
 * @version 1.0

 * @param levelstatus
 * @desc
 * Show or hide level on MenuStatus
 * true will show the level
 * @default true
 *
 * @param hpbar
 * @desc
 * Show or hide hp bar on MenuStatus
 * true will show the hp bar
 * @default true
 *
 * @param mpbar
 * @desc
 * Show or hide mp bar on MenuStatus
 * true will show the mp bar
 * @default true
 */
 Naqua.Param = Naqua.Param || {};
(function() {
Naqua.Parameters = PluginManager.parameters('Naqua_HideStatus');

Naqua.Param.level_status = string(Naqua.Parameters['levelstatus'];                        //Boolean(Naqua.Parameters["level status"]);
Naqua.Param.hp_bar = string(Naqua.Parameters['hpbar'])
Naqua.Param.mp_bar = string(Naqua.Parameters['mpbar']);
                                          
Naqua.drawStatus = Window_Base.prototype.drawActorSimpleStatus; //aliasing

Window_Base.prototype.drawActorSimpleStatus = function(actor, x, y, width) {
    var lineHeight = this.lineHeight();
    var x2 = x +180;
    var width2 = Math.min(200, width - 180 - this.textPadding());
    this.drawActorName(actor, x, y);
    this.drawActorIcons(actor, x, y + lineHeight * 2);
    this.drawActorClass(actor, x2, y);
    if(Naqua.Param.hp_bar == true){
     this.drawActorHp(actor, x2, y + lineHeight * 1, width2);
    }
    if(Naqua.Param.mp_bar == true){
      this.drawActorMp(actor, x2, y + lineHeight * 2, width2);
    }
    if(Naqua.Param.level_status == true){
      this.drawActorLevel(actor, x, y + lineHeight * 1);
  }
}

 

}) ();
I have tried changing Naqua.Param into boolean ,string , number etc. but no luck. its like the if( ) there is ignored and param value seems didnt taken correctly.

also, is there a way to take param value to be shown in console / game ? just to make sure the value is right
 

LTN Games

Master Mind
Resource Team
Xy$
0.01
All parameters that come in from the plugin manager are string, to begin with, so your conversion to a string is not required.
JavaScript:
Your String() method had a lower case s and it should be an upper case S
Naqua.Param.level_status = String(Naqua.Parameters['levelstatus'];
Do that for the rest of them if you insist on using the String() method otherwise remove the String() method entirely.

For your conditonals you are using == and not === this is okay in this case but don't get in the habit of using == it's prone to bugs and you shouldn't use it unless you fully understand what it does and even then you can find other ways to achieve what == does. So, because you're comparing to a string you should make sure that true and false are a string as well so 'true', 'false'.
JavaScript:
  if(Naqua.Param.hp_bar === 'true'){
     this.drawActorHp(actor, x2, y + lineHeight * 1, width2);
    }
    if(Naqua.Param.mp_bar === 'true'){
      this.drawActorMp(actor, x2, y + lineHeight * 2, width2);
    }
    if(Naqua.Param.level_status === 'true'){
      this.drawActorLevel(actor, x, y + lineHeight * 1);
  }
Alternatively, you could convert your parameters to a boolean before they reach your core plugin, which is something I do for all my parameters. The snippet below will evaluate your parameter, so if your parameter is equal to the string 'true' it will return true else return false.
JavaScript:
Naqua.Param.level_status = String(Naqua.Parameters['levelstatus'] === 'true' || false;
Now your string will always be true or false as a boolean not as a string which means now your conditionals can check for an actual boolean.

JavaScript:
    if(Naqua.Param.level_status === true){
      this.drawActorLevel(actor, x, y + lineHeight * 1);
  }
To check your plugin parameters as they are in the editor you simply console.log your Parameters object.
Code:
console.log(Naqua.Parameters)
If this returns null or undefined it means your plugins filename is not the one you set here PluginManager.parameters('Naqua_HideStatus');

I hope this helps.
 
What @LTN Games said.

To check your plugin parameters as they are in the editor you simply console.log your Parameters object.

PluginManager.parameters('Naqua_HideStatus');
You can - or should be - able to type directly in the console log (press F8 and it'll bring it up) during playtesting. Then you can test which things work; it'll do an autocomplete for you.

So if you type in Naqua it should return an object.

Or if you type in Naqua.Param.mp_bar it'll tell you what the Boolean value is.

I actually find this very useful to check things, especially during development of my QEngine plugin. A lot of things don't work, so often typing functions or objects help in determining what's working and what's not. It's usually better to output to the console using console.log, but there might be occasions where you either want to test something directly or when console.log can't output properly.
 

nickaqua

Villager
Xy$
0.00
All parameters that come in from the plugin manager are string, to begin with, so your conversion to a string is not required.

For your conditonals you are using == and not === this is okay in this case but don't get in the habit of using == it's prone to bugs and you shouldn't use it unless you fully understand what it does and even then you can find other ways to achieve what == does. So, because you're comparing to a string you should make sure that true and false are a string as well so 'true', 'false'.

Alternatively, you could convert your parameters to a boolean before they reach your core plugin, which is something I do for all my parameters. The snippet below will evaluate your parameter, so if your parameter is equal to the string 'true' it will return true else return false.
JavaScript:
Naqua.Param.level_status = String(Naqua.Parameters['levelstatus'] === 'true' || false;
To check your plugin parameters as they are in the editor you simply console.log your Parameters object.
Code:
console.log(Naqua.Parameters)
I hope this helps.
This works like charm ! , 1st the String converter is ultimately not needed, and booelan convert method is new to me and helped a lot !

I also googled and found that == actually convert the value (which is lead to bug) rather than rawly comparing 2 variable. In my College they taught me the == , I guess for the sake of study simplicity

also I realized that there is a javascript subforum xD , I Have continuation question , do you think I should create a new thread there or just continue asking here?


You can - or should be - able to type directly in the console log (press F8 and it'll bring it up) during playtesting. Then you can test which things work; it'll do an autocomplete for you.

So if you type in Naqua it should return an object.

Or if you type in Naqua.Param.mp_bar it'll tell you what the Boolean value is.
Just tried it and it works, sure this help a lot rather than repeat-playtesting , altough I confused with "true" or "false" there is a boolean or a string, so sometimes I still need to create conditional to actually check the value, but new information never hurts!
 
Top