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!

[Solved] How to call var in script instead of number

Status
Not open for further replies.

Bishiba

Villager
Xy$
0.00
Hello!

I would like to call a variable(68) instead of the 1 in the following script.

DataManager.saveGame(1)

So far I've tried:
DataManager.saveGame(var = 68)
DataManager.saveGame(68)
DataManager.saveGame(var68)
DataManager.saveGame(var 68)
DataManager.saveGame(var = 68)
DataManager.saveGame(id68)
DataManager.saveGame(id 68)
DataManager.saveGame(id = 68) //This one seems to save in slot 68... -.-'
DataManager.saveGame(varid = 68) //This one seems to save in slot 68... -.-'


How would I do that?
Thanks in advance.

Solve:

DataManager.saveGame($gameVariables.value(68))
 
Last edited:

MinisterJay

Administrator
Staff member
Administrator
Every now and then ,we do solve our own MV Support question.
[doublepost=1495505061,1495504991][/doublepost]@Bishiba please put the answer again in a reply, so I can mark it as Best Answer and have it officially solved.
 

CT_Bolt

Global Moderator
Staff member
Resource Team
Xy$
0.02
@Bishiba please put the answer again in a reply, so I can mark it as Best Answer and have it officially solved.

Well since @Bishiba has not yet replied again I will elaborate on what @Bishiba found to be a solution...

Also I should note when saving the game it is best practice to call "$gameSystem.onBeforeSave();" before actually saving.
See below for more explanation. (glad)

Control Variables
JavaScript:
var varId = 68; var value = 5;
// This sets the value of variable #68 to 5
$gameVariables.setValue(varId, value);
// This returns  the value of variable #68
$gameVariables.value(varId);
Saving the game
JavaScript:
// This is used to do the following:
//                                  Increase the save count (how many times saved)
//                                  Save the Version ID
//                                  Save Graphics.frameCount
//                                  Save current BGM & BGS
$gameSystem.onBeforeSave();

// Save the game
DataManager.saveGame($gameVariables.value(varId));

// Return the the map scene
SceneManager.goto(Scene_Map);
Extra Information:
Control Switches
JavaScript:
var varId = 68; var enabled = true;
// This sets the value of switch #68 to true
$gameSwitches.setValue(varId, enabled);
// This returns the value of switch #68
$gameSwitches.value(varId);
 

Bishiba

Villager
Xy$
0.00

Well since @Bishiba has not yet replied again I will elaborate on what @Bishiba found to be a solution...

Also I should note when saving the game it is best practice to call "$gameSystem.onBeforeSave();" before actually saving.
See below for more explanation. (glad)

Control Variables
JavaScript:
var varId = 68; var value = 5;
// This sets the value of variable #68 to 5
$gameVariables.setValue(varId, value);
// This returns  the value of variable #68
$gameVariables.value(varId);
Saving the game
JavaScript:
// This is used to do the following:
//                                  Increase the save count (how many times saved)
//                                  Save the Version ID
//                                  Save Graphics.frameCount
//                                  Save current BGM & BGS
$gameSystem.onBeforeSave();

// Save the game
DataManager.saveGame($gameVariables.value(varId));

// Return the the map scene
SceneManager.goto(Scene_Map);
Extra Information:
Control Switches
JavaScript:
var varId = 68; var enabled = true;
// This sets the value of switch #68 to true
$gameSwitches.setValue(varId, enabled);
// This returns the value of switch #68
$gameSwitches.value(varId);
Really elaborate, very good for anyone else browsing it :)
[doublepost=1495667512,1495667399][/doublepost]
Every now and then ,we do solve our own MV Support question.
[doublepost=1495505061,1495504991][/doublepost]@Bishiba please put the answer again in a reply, so I can mark it as Best Answer and have it officially solved.
Was away there for a day so a bit late on the reply, marked CT_bolt's answer as th best answer though :)
 
Status
Not open for further replies.
Top