Default Variables

Default Variables v1.0​
by futrchamp​
 ​
This script simply allows you to set certain variables to have a value that is set when the game starts.

Instructions:

Paste into the script editor below materials and above main.

Change the numbers in the Variables= line to whichever variables you want to set.

Change the numbers in the Values= line to the corresponding values for each variable.

For example:

Variables=[2,3,6,8,9]

Values=[1,2,3,10,56]

Would set variable 2 to 1, variable 3 to 2, variable 6 to 3, and so on.

You can have as many variables in the array as you want, as long as each is assigned a value.

 

Compatibility:

Should be compatible with just about any script that doesn't modify the same things. Report any issues and I will try to make a patch for the script in question.

 

Terms of Use:

Usable in any project, commercial or non-commercial, with credit appreciated, but not required.

 

Code:
# Default Variables v1.0# by futrchamp# This script simply allows you to set certain variables to have a value that is # set when the game starts.# Instructions:# Change the numbers in the Variables= line to each variable you want to set.# Change the numbers in the Values= line to the corresponding values for each # variable.# For example:# Variables=[2,3,6,8,9]# Values=[1,2,3,10,56]# Would set variable 2 to 1, variable 3 to 2, variable 6 to 3, and so on.# You can have as many variables in the array as you want, as long as each is # assigned a value.module FutrDefaultVar  # Set the variables to be changedVariables=[2,3,6,8,9]  # Set corresponding valuesValues=[1,2,3,10,56]endclass Game_Variablesalias initialize_futrdefaultvars initializedef initialize(*a,&    initialize_futrdefaultvars(*a,&    i=0    while i<FutrDefaultVar::Values.length    @data[FutrDefaultVar::Variables[i]] = FutrDefaultVar::Values[i]    i+=1    endendend

 

 

 
You're a life saver thanks! I've been looking for something like this for a while.  Is it possible to set conditional branches with that script too? 

Meaning:

if variable 1 = 2

then make variable 3 = 3

else if variable 1 = 3

then make variable 3 = 2

Variable 1's value could depend on something like the year or time of day (I'm using a real time clock script).

This would be so useful for me if it's possible to do this calculation beforehand instead of need to make an autorun script event for everything involving variables at the start of a map. 

12.jpg
Is it possible to write something like thIs?

Variables=[1, 2]

Values=[graphics.width, graphics.height]

It would be super useful for me. 🙂 (\s/)
But your script is allready amazing, because I've got tons of variables that need to be set up at the beginning of the game. 🙂 /)

Edit: It works so far, tried that. But it can't actually read out the changed resolution I have only shows me up the 544x416 that is basic resolution. :/
Is there a chance to change that?
Just a small tip on your code, you could use a hash(key-value pair) to make the configuration a little bit easier for the user.

Nevertheless its a simple and nice idea and can save some work for the user, well done 🙂
Is it possible to write something like thIs?

Variables=[1, 2]

Values=[graphics.width, graphics.height]

It would be super useful for me. 🙂 (\s/)

But your script is allready amazing, because I've got tons of variables that need to be set up at the beginning of the game. 🙂 /)

Edit: It works so far, tried that. But it can't actually read out the changed resolution I have only shows me up the 544x416 that is basic resolution. :/

Is there a chance to change that?
I'm actualy curious why you need to do that.  Want the game to be changing window size on the fly?
Yes, I have a different resolution sizes.
But allready got a script, that does this trick without writing to a variable. 😀
But may use it anyway, for things like write a character level to a variable. (\s/)
Fixed script format, credit futrchamp. And thank you Roninator2 for your help/ input.
Edit: included (*argv, &argb) after def initialize (thanks for the update)

Code:
# Default Variables v1.0
# by futrchamp
# This script simply allows you to set certain variables to have a value that is
# set when the game starts.
# Instructions:
# Change the numbers in the Variables= line to each variable you want to set.
# Change the numbers in the Values= line to the corresponding values for each
# variable.
# For example:
# Variables=[2,3,6,8,9]
# Values=[1,2,3,10,56]
# Would set variable 2 to 1, variable 3 to 2, variable 6 to 3, and so on.
# You can have as many variables in the array as you want, as long as each is
# assigned a value.

module FutrDefaultVar
# Set the variables to be changed
    Variables=[2,3,6,8,9]
# Set corresponding values
    Values=[1,2,3,10,56]
end

class Game_Variables
    alias initialize_futrdefaultvars   initialize
   def initialize(*argv, &argb)
        initialize_futrdefaultvars(*argv, &argb)
        i=0
        while i < FutrDefaultVar::Values.length
            @data[FutrDefaultVar::Variables[i]] = FutrDefaultVar::Values[i]
            i+=1
        end
    end
end

Original thread: https://forums.rpgmakerweb.com/threads/default-variables.19230/