RMMV Struct parameter problem- JSON.parse doesn't work

A_Higher_Plane

Veteran
Veteran
Joined
Oct 3, 2015
Messages
339
Reaction score
48
First Language
Russian
Primarily Uses
RMMV
Please help me out. I have been doing just this for hours. I am learning RMMV plugin development. Here is my code:

/*:
*@author Yevgeniy Kizhner
*@plugindesc This is a testing plugin.

*@param Cus
*@type struct<Custom>

*@help Just testing things out!
*/

/*~struct~Custom:
*@param Custom Energy
*@type boolean
*@default false

*@param Custom Energy Name
*@type text
*/

var params = PluginManager.parameters("MyPlugin")["Cus"];
console.log(params);
console.log(params["Custom Energy Name"]);
//console.log(JSON.parse(params));
var val = JSON.parse(params);
console.log(val);
console.log(val['Custom Energy Name']);

var Win = Window_Gold.prototype.refresh;
Window_Gold.prototype.refresh = function() {
Win.apply(this, arguments);
var energy1 = JSON.parse(params);
var energy2 = energy1["Custom Energy Name"];
this.drawText(energy2, 2, 0, 20, 'left');

I get the error "unexpected end of json input" at the Json.parse code.
 
Last edited:

Dev_With_Coffee

Veteran
Veteran
Joined
Jul 20, 2020
Messages
778
Reaction score
385
First Language
PT-BR
Primarily Uses
RM2k3
From what I've seen, the spaces between the letters don't work, you need to use underline.
  • Custom_Energy
  • Custom_Energy_Name
Because the JSON function will convert to an object and the space will make it understand that it is not an "Object":

{"Custon_Energy":123,"Custom_Energy_Name":"Fire"}
Object.Custom_Energy return 123
 
Last edited:

A_Higher_Plane

Veteran
Veteran
Joined
Oct 3, 2015
Messages
339
Reaction score
48
First Language
Russian
Primarily Uses
RMMV
@Dev_With_Coffee seems to have solved this issue for me! Thanks. But please help me with my one other issue in this code. Here it is:

I have added a conditional about a boolean parameter in the plugin. But it executes the first condition regardless of whether that plugin's parameter is true or false. It always fulfils that condition. What is wrong? Please help me out!!

Here is the code:

var energyType;
var energy1 = JSON.parse(params);
var chosenNRG = energy1["Custom_Energy"];
if(!chosenNRG) {energyType = "Ki"; console.log(1);}
else{
console.log(2);
energyType = energy1["Custom_Energy_Name"];

}
 

Beckx

Villager
Member
Joined
Mar 29, 2021
Messages
28
Reaction score
246
First Language
german
Primarily Uses
RMMV
this could on the one hand be one of those examples where Javascript is really wonky.
is your value really a boolean value or maybe a string "true" or a number?
have you logged chosenNRG?
the "!" in front negates the value you're getting, so in your condition you're actually asking if chosenNRG is false or not set and then executes the first stuff.
(sorry english isn't my first language and i can't explain stuff right now)

try removing the ! in your condition, i think that's you're problem
edit: wait no. that's what you want to do here right? if there is no value, set it to "Ki" otherwise use the value? if so, the "!" should be correct... i think it's one of those JS issues, but it's hard to tell without knowing what chosenNRG is supposed to be. at least if you're actually getting something from energy1 it should work, so you should log that before and check what you're getting

you could try setting your variable with var chosenNRG = energy1["Custom_Energy"] || false;
(or || null)

edit 2:
Do you actually have a value at "Custom_Energy" or is the name of that energy maybe something different and you maybe forgot to set the correct name here?
Because there would also be a potential error in your else part where you want to set your energy to params["Custom_Energy_Name"]
 
Last edited:

A_Higher_Plane

Veteran
Veteran
Joined
Oct 3, 2015
Messages
339
Reaction score
48
First Language
Russian
Primarily Uses
RMMV
@Beckx I have done some of the things you have said but nothing. Thanks for at least trying to help me out though!

I still need help. Anyone can help me out here.

Here is the JS struct in my code:

/*~struct~Custom:
*@param Custom_Energy
*@type boolean
*@default false

*@param Custom_Energy_Name
*@type text

*/
 

Dev_With_Coffee

Veteran
Veteran
Joined
Jul 20, 2020
Messages
778
Reaction score
385
First Language
PT-BR
Primarily Uses
RM2k3
chosenNRG will always exist, so use the "!" in the condition it will have no effect.

Try:
JavaScript:
if (chosenNRG == false) {
    energyType = "Ki";
}else{
    energyType = energy1["Custom_Energy_Name"];
}

Try to make code cleaner visually, because at first I barely understood.
 

Dev_With_Coffee

Veteran
Veteran
Joined
Jul 20, 2020
Messages
778
Reaction score
385
First Language
PT-BR
Primarily Uses
RM2k3
It could be that the parameter is returning a String, try with quotes:
== "false"

Good luck
 

A_Higher_Plane

Veteran
Veteran
Joined
Oct 3, 2015
Messages
339
Reaction score
48
First Language
Russian
Primarily Uses
RMMV
You've solved it for me! If these threads get locked, then you guys can lock this thread.
 

Latest Threads

Latest Profile Posts

Doing RPG Maker News for 28th September 2021

RMMV - Skip script errors:

For game developer testing purposes.
You know, I really get to farm likes since I post all of @Avery and @hiddenone 's blog tutorials on the forums...
Back from a very long hiatus with a new project woo
This is my battler placeholder image trying out art styles too I want to fake a backview battle system
I think I will want portraits and battle sprites to be 2D and stick to pixel art for overworld not 100%sure but pretty sure its easier to make pixel art for overworld sprites, events and maps and stuff.
Placeholder.png
$Syringer.png
toying with a brand new monster design

Forum statistics

Threads
115,440
Messages
1,089,933
Members
150,215
Latest member
Cam2244
Top