ighrpg

Veteran
Veteran
Joined
Apr 8, 2021
Messages
53
Reaction score
3
First Language
English
Primarily Uses
RMMZ
Hello, I am new to JS and I am trying to get the function to see my var number so my param can use the value.
I can confirm that the var is writing to the console.

I am sure I am missing something but not sure what I am doing wrong.

JavaScript:
(function(){

    
    
    var params = PluginManager.parameters("IGH_OffSet");
    //var text = params["Text Param"];
    var number = params["Number Param"];

    Game_Player.prototype.centerY = function() {

        
        var y =(Graphics.height / $gameMap.tileHeight() - 1) / 2.0;
        y += number;
        return y;
        
    };

    //console.log(text);
    console.log(number);
    

})();
 

Zevia

Veteran
Veteran
Joined
Aug 4, 2012
Messages
668
Reaction score
382
First Language
English
Primarily Uses
RMMV
Is that the whole Plugin? In order for a Plugin to have parameters available (at least in MV, I'm not sure if it works the same in MZ), you have to define them in comments at the top of your file. Something like:
Code:
* @param Number Param
* @desc This parameter holds a number for an unknown purpose
* @default 1

Presumably it's working since you said when you console.log(number);, you're seeing the expected value.

It looks like you've defined a new function to replace Game_Player.prototype.centerY. Have you added your Plugin to your project so that it will overwrite the existing one? If you're just trying to log it inside that file, you'll have to call your function in addition to defining it:
Code:
Game_Player.prototype.centerY = function() {
// your code
};

console.log(new Game_Player().centerY());

When you declare a function, it doesn't actually get called. You'll have to call it to see its results. Right now your console.log(number) statement just logs the number you've put into your Plugin parameters.
 

ighrpg

Veteran
Veteran
Joined
Apr 8, 2021
Messages
53
Reaction score
3
First Language
English
Primarily Uses
RMMZ
Here is the full script:
In the area where it says y+= 5 , this works as expected but as soon as I put the var number there it stops working. The console Log was just to confirm that the value that I put in the value section in the editor was showing and connected to the code.


Code:
/*:
 * @author
 * @plugindesc My Information Here
 * @url
 * @target MZ
 *
 *
 * @param Text Param
 * @type text
 * @default Some text Here!
 *
 * @param Number Param
 * @type number
 * @desc My Number
 * @min 0
 * @max 999
 * @decimals 5

*/

 


(function(){

 
    var params = PluginManager.parameters("IGH_OffSet");
    //var text = params["Text Param"];
    var number = params["Number Param"];


    Game_Player.prototype.centerY = function() {
 
        var y =(Graphics.height / $gameMap.tileHeight() - 1) / 2.0;
        y += 5;
        return y;
       
    };


   
   

    //console.log(text);
    console.log(number);
   

})();
 

ighrpg

Veteran
Veteran
Joined
Apr 8, 2021
Messages
53
Reaction score
3
First Language
English
Primarily Uses
RMMZ
Thank you , I was able to get it working. once its complete I will update the thread.

regards
 

Nolonar

Veteran
Veteran
Joined
Feb 18, 2018
Messages
263
Reaction score
367
First Language
French, German
Primarily Uses
RMMZ
y += 5 works because y is a Number and 5 is also a Number.

However, params["Number Param"] is a String (text). The + operator works differently with strings, and is known as the "concatenation operator" (as opposed to the "addition operator", when numbers are involved).

For example: "Hello" + "World" gives you "HelloWorld". Since you are using the + operator on a number and a string, JavaScript will automatically convert the number to a string and use string concatenation instead of addition.

You can fix this by using:
JavaScript:
y += Number(number);
or alternatively:
JavaScript:
var number = Number(params["Number Param"]);
which will tell JavaScript to convert the string into a number instead.

Note that Number(value) will return NaN (Not a Number) if value is not a number, and so y += Number(value) will result in y being NaN as well.
 

Latest Threads

Latest Posts

Latest Profile Posts

I'm making Toilet in Wonderland 2. and tell vinny about it lol
WE ARE THE BORG. YOUR BIOLOGICAL AND TECHNOLOGICAL DISTINCTIVENESS WILL BE ADDED TO OUR OWN. RESISTANCE IS FUTILE.
D2R save files are so broken. how was the beta test better then the full release. blizzard's last hope crashed and burned.
they're getting no more chances from me.
Anyone going to talk about Chris Pratt Mario?

Forum statistics

Threads
115,336
Messages
1,089,109
Members
150,009
Latest member
biscoitovelho
Top