Jump to content
  • 0

Init.sqf vs Variables.sqf


Pavillin

Question

Quick question here. I see all the variables in the variables.sqf but I also see people putting them in their init.sqf file too. If I put variables in the init.sqf does it overwrite the variable in the variables.sqf?

If it set in the variables.sqf:

ZE_GodModeBase = false

but in the init.sqf put:

ZE_GodModeBase = true

what one takes priority? Will there be god bases or no god bases?

Link to comment
Share on other sites

11 answers to this question

Recommended Posts

  • 1

The variables you put in init.sqf will be the one that take priority. If no variable is set for an option in the init.sqf, then it will set a default option set from the variables.sqf

Wrong.

init.sqf is the first ever script to be loaded in mpmissions. It can be used for anything - from defining variables to compiling functions (just like any other file... filenames means nothing, any file can be used for any task).
function is also just a variable that is defined by compiling a file (read by engine in form of string), preprocessor takes care of comments and defines if exists.

Down the list comes compiles and variables files, which are nothing different from init.sqf - they all are just files to be processed.

When it comes to programming - when you set a variable, it is created in a namespace (a group of blocks in your RAM), if you redefine variable later, it is overwritten.

This means that there is no such thing as priority. Last defined is the variable that is used.

To answer your question - if you define same variable in 2 different places, last one to be loaded will be the one used, and since init.sqf is always first file to be loaded and it is used to load variables.sqf, then variable inside variables.sqf is used instead.

Link to comment
Share on other sites

  • 0

The variables you put in init.sqf will be the one that take priority. If no variable is set for an option in the init.sqf, then it will set a default option set from the variables.sqf

So variables.sqf will only select that option if nothing is set in the init.sqf

So from init.sqf   "DZE_GodModeBase = true"    will activate that options and will skip the  "DZE_GodModeBase = false" from variables.sqf since the option is already written in your init.

From the variables.sqf you can see this:

if (isNil "DZE_GodModeBase") then {
	DZE_GodModeBase = false;
};

So this mean, if no option is set from init.sqf, then the default option will be set from the variables.sqf, in this case, to false.

I suggest you go take a look here for options you can add in your init

Edited by TolH
Link to comment
Share on other sites

  • 0

Ahh ok so what's the point of putting variables in the init.sqf if it always takes the value from the variables.sqf instead?

 

EDIT: If you put the variable in the init.sqf should you remove it from the variables.sqf so the value in the init.sqf is used?

Edited by Pavillin
Link to comment
Share on other sites

  • 0

 

This means that there is no such thing as priority. Last defined is the variable that is used.

To answer your question - if you define same variable in 2 different places, last one to be loaded will be the one used, and since init.sqf is always first file to be loaded and it is used to load variables.sqf, then variable inside variables.sqf is used instead.

Always used this in init.sqf, never had a problem. Just one time i think the number of zombies had to be put under the call compile preprocessFileLineNumbers. Either than that, every option i was putting in init.sqf was getting activated by init.sqf and not default option from variables.sqf unless the option was not set in init.sqf

If init is the first to load and variables overwrite the setting you made in your init.sqf, how come the option you set in init.sqf works when for exemple you have in init.sqf "DZE_BuildingLimit = 450;" and default from variables let's say "DZE_BuildingLimit = 50;"

The "DZE_BuildingLimit = 450"  will be selected over "DZE_BuildingLimit = 50;"  So why is it that the 450 is used instead of the variables.sqf one?

exemple:

DZE_BuildingLimit = 500;


//Load in compiled functions
call compile preprocessFileLineNumbers "compile\variables.sqf";

Ahh ok so what's the point of putting variables in the init.sqf if it always takes the value from the variables.sqf instead?

Easier to keep track of all the option to changes i would guess, from the init.sqf instead of scrolling up and down trying to find all the options from your variables.sqf

EDIT:

Also, from wiki for the if (isNil something) then {};  it's saying:

(Tests whether the variable defined by the String argument is undefined, or whether an expression result passed as Code is undefined.
The command returns true if the variable or the expression result is undefined (i.e. the expression result is Void), and false in all other cases.)

So:

From the variables.sqf you can see this:

if (isNil "DZE_GodModeBase") then {
	DZE_GodModeBase = false;
};

So this mean, if no option is set from init.sqf, then the default option will be set from the variables.sqf, in this case, to false.

I was not totally wrong i guess.

Edited by TolH
Link to comment
Share on other sites

  • 0

 if he inserted the same line in 2 places which would be used.

The one in init.sqf because:

(Tests whether the variable defined by the String argument is undefined, or whether an expression result passed as Code is undefined.
The command returns true if the variable or the expression result is undefined (i.e. the expression result is Void), and false in all other cases.)

So since the variable is already defined in init.sqf, the code in red won't be applied from variables.sqf  (So having both set the same in init and variable sqf won't active both of em but only the one in init.sqf)

if (isNil "DZE_GodModeBase") then {
    DZE_GodModeBase = false;
};

Edited by TolH
Link to comment
Share on other sites

  • 0

Hehe, I think we are talking in parallel here. The line you are showing is in the default variables.sqf and you are correct if it is defined already it will by pass that if not false becomes the value of the variable.

I took his question to be what if you have added the line DZE_GodModeBase=true to his init.sqf and then added the same line but set to false in the variables.sqf. The line you are quoting would still be there and be bypass as you say, however the last variable loaded of the 2 added lines would be the one that would be used. So we are saying sorta the same thing just along a different path.

Link to comment
Share on other sites

  • 0

I took his question to be what if you have added the line DZE_GodModeBase=true to his init.sqf and then added the same line but set to false in the variables.sqf.

Sorry, i often misread or not understanding everytime :D  But as for the text i quoted, DZE_GodModeBase=true from init.sqf will be taken instead of the one in variables.sqf because DZE_GodModeBase=something already defined in init.

Hope i got it right this time if not i give up.

Excuse my french.

Link to comment
Share on other sites

  • 0

nil is a value of nothing. It is not equal to anything including itself. It can be used to delete variable. isNil is a command to check if variable exists.

apples = 0;

apples = nil;

if (isNil "bananas") then {oranges = 5;}; // only oranges exists from this point

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement
  • Discord

×
×
  • Create New...