Default Variable Values

ItsAlterity

Mirroraculous Developer
Veteran
Joined
Feb 13, 2018
Messages
65
Reaction score
132
First Language
English
Primarily Uses
RMMV
Bit of a simple though odd one to ask, but wanted to ask for the idea of adding a default value to certain variables at the start of the game. For example, say I have an Approval/Trust system for my partners and I want them at default to start at 50, I want it to be able to immediately set it to that for each possible partner, as is with other values for my partners. I use 1.5.1, so I need it compatible with that, as I do need this compatible with Yanfly and all of that, though I'm not sure how important that is to this specific plugin. To all those who consider my request, thank you and a big thanks to advance to those who put it in!
 

TheoAllen

Self-proclaimed jack of all trades
Veteran
Joined
Mar 16, 2012
Messages
5,594
Reaction score
6,525
First Language
Indonesian
Primarily Uses
RMVXA
Can do this in VXA, should be doable in MV too.
But any specific reason as for why can't you just use autorun event to set variables from the start of the game?
 

Jeremiah Eastman

Gladiator
Veteran
Joined
Apr 24, 2017
Messages
510
Reaction score
315
First Language
English
Primarily Uses
RMMV
You can just create an auto run event on your first map or wherever that sets the variable to what you want then use like a self switch to a second auto run event page that only has an erase event tag in it. You will likely have a bunch of variables and maybe switches you want to set a certain way at the beginning, you can toss all of those items into the same page 1 of the auto run event. Well hope that helps and you get it all dialed, best of luck to ya.
 

ItsAlterity

Mirroraculous Developer
Veteran
Joined
Feb 13, 2018
Messages
65
Reaction score
132
First Language
English
Primarily Uses
RMMV
Can do this in VXA, should be doable in MV too.
But any specific reason as for why can't you just use autorun event to set variables from the start of the game?
Four main reasons actually:
A) I have a rather large amount of these
B ) The autorun at the start of my game launches a personality quiz to get things started (Though I guess it COULD be added along with that)
C) The way my game runs its Approval system, it might actually be necessary
D) It's rather inconvenient, and I don't get why this isn't available by default if I am being honest
 

Aloe Guvner

Walrus
Veteran
Joined
Sep 28, 2017
Messages
1,628
Reaction score
1,115
First Language
English
Primarily Uses
RMMV
Like the others said, this is best done with an autorun event, no reason to have code/plugins.
Personally, I put all "game initialization" stuff within a Common Event, and my autorun event just calls the Common Event. It keeps it clean and I never forget where it is or have to go find it. I would recommend doing it this way, you already have an autorun event so it's just adding one more Event Command at the beginning of it to call the Common Event.
If you really wanted to do it with code...
Code:
(function() {
    var alias_DataManager_setupNewGame = DataManager.setupNewGame;
    DataManager.setupNewGame = function() {
       alias_DataManager_setupNewGame.call(this);
       $gameVariables.setValue(ID, VALUE);
       $gameVariables.setValue(ID, VALUE);
       //and so on...
    };
})();
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
31,370
Reaction score
7,678
First Language
German
Primarily Uses
RMMV
I suggest sticking with autorun as well, because even with a plugin you'll always need to manually specify which variables need that other default and which ones do not.
So the only difference between event and plugin is how to write the commands that change the default value of zero, and it's actually less work to include a control variable command in an autorun than to write the same command inside a JavaScript plugin.
 

ItsAlterity

Mirroraculous Developer
Veteran
Joined
Feb 13, 2018
Messages
65
Reaction score
132
First Language
English
Primarily Uses
RMMV
I suggest sticking with autorun as well, because even with a plugin you'll always need to manually specify which variables need that other default and which ones do not.
So the only difference between event and plugin is how to write the commands that change the default value of zero, and it's actually less work to include a control variable command in an autorun than to write the same command inside a JavaScript plugin.
Well then..... this is a bit awkward. Not a lot to say. I had thought I'd been onto something, but I suppose I may have dun goofed. My apologies
 

Frogboy

I'm not weak to fire
Veteran
Joined
Apr 19, 2016
Messages
1,704
Reaction score
2,208
First Language
English
Primarily Uses
RMMV
You could also put this in a common event with a switch to activate it. At the beginning of your game, flip the switch and then have the common event flip it back when it's done. All this does is pull the initialization out from within the game itself and allows you to run it again easily if needed (which is rare).

This would be an easy plugin to write but I don't see how it would be any easier to set up than just using the editor as others have described. If you want to eliminate the clutter of having 50 set variable commands getting your way, you can try my method.
 

TheoAllen

Self-proclaimed jack of all trades
Veteran
Joined
Mar 16, 2012
Messages
5,594
Reaction score
6,525
First Language
Indonesian
Primarily Uses
RMVXA
Although, I do admit that using event to setup default variable is rather,... inconvenient.

Reason is, you need to exactly start at the map where the switch is flipped, event is triggered, or whatever it is that set the default value of some variables. Using custom plugin, you can configure it inside the code, always initialized, and basically you can move starting position everywhere for whatever reason (such as debugging or so) without you forgot to set the default variable.

Personally though when I'm developing a game myself, I often use scripted approach, in fact I use scripted approach more even some of it can be evented. As long as you know what you're doing, it's good anyway.

Aloe Guvner already give you a snippet code that would initialize a default variable value upon starting a new game, so I guess it's solved?
 

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

Latest Threads

Latest Profile Posts

I should realize that error was produced by a outdated version of MZ so that's why it pop up like that
Ami
i can't wait to drink some ice after struggling with my illness in 9 days. 9 days is really bad for me,i can't focus with my shop and even can't do something with my project
How many hours have you got in mz so far?

A bit of a "sparkle" update to the lower portion of the world map. :LZSexcite:
attack on titan final season is airing tomorrow, I'm excited and scared at the same time!

Forum statistics

Threads
105,882
Messages
1,017,230
Members
137,607
Latest member
Maddo
Top