Hello,
I am new to javascript, and I currently have a .js file with
//Game_System variables and functions
Game_System.prototype.variable = "value";
Game_System.prototype.print_variable = function(){
console.log(this.variable);
}
I try to make a call to the function in RPG Maker MV
$gameSystem.print_variable();
,and I get an error message reading
Undefined is not a function.
I'm not entirely sure what I'm doing wrong, but any help would be greatly appreciated.
Thank you.
I've moved this thread to Learning Javascript. Please be sure to post your threads in the correct forum next time. Thank you.
When I get home I can send you a ex of how it should look so you can see how the .js should be formatted
When I get home I can send you a ex of how it should look so you can see how the .js should be formatted
Are you sure your plugin is enabled, and thus adding the variable and function to Game_System? If you just print out the $gameSystem variable itself, you can check to see if it has your variable in it.
My plugin is enabled, and I changed to in-game code to
window.alert($gameSystem.variable);
and it says the variable is undefined as well as the function. I'm sure I must be doing something wrong, but I can't figure it out.
I've still been unsuccessful with my issue. Maybe 2DGameStudios could send that text file if it's not too much trouble.
Do you really need to use Game_System.prototype.variable = "value"? I'm new to this kind of stuff too so I might not be grasping what is your goal, but I think that you can just make:
var myVar1 = 45; // your custom global variable
// you could also use $gameVariables.value(12); ingame global variable. 12 is the id of the variable (you can see from the editor), change it to any other id you want like "0030" without the "00" and quotes.
Game_System.prototype.print_variable = function(){
var myVar2 = 110; // same things as myVar1 except this one has a local scope
console.log(myVar1, myVar2);
}
Maybe is this what you want? Anyway, you should reall reall really start using the console to debug and watch your variables and functions. Press F8, go to sources, find your plugin and breakpoint the hell out of stuff. Trust me, it saved me from a lot of headaches.
Sorry for the double post,and the reason I'm trying to use game_system is because I'm following a tutorial on YouTube, and I'm having trouble getting past my problem. I've already finished 2 JavaScript tutorials on codeacademy but I'm trying to learn the rpg maker engine now. I've written scripts in the past with Ruby, and now having to learn another language and rpg core is a bit overwhelming.
Then I suggest you give us a link to that tutorials, so we can check if the tutorial is simply wrong here or did something differently.
But really? Video tutorials are probably the worst way to learn scripting/programming - simply because they are usually too short and skip over too much details for time restrictions.
And that doesn't even adress the problem of visibility (there are a lot of script videos where it is difficult to see the difference between () and []) or the fact that you can't type in the code as fast as a video describes it.
You should better look for a written tutorial in a PDF or so.
Sorry I tried two different ones on YouTube one bu SumRndmDude and one by soulpour. I would link but I'm on my phone now. Could you maybe suggest a non video tutorial I'm not opposed to learning with a document, but I would like to find a good one.Sorry, again. I just saw the links in your post, and I'll try those out. Thanks for your help.