Jump to content
  • 0

Assign value to a non-existing variable and create it


FragZ

Question

I want it so when a variable is not existing in the server, it will create it on the mission file and assign a default value to it.

Example from variables.sqf:
 

if(isNil "DZE_HeliLift") then {
	DZE_HeliLift = true;
};

I would like it so, in the same principle, a var (lets call it Variable) is supposed to be called from server.pbo. BUT, if that var is not declared/initialized, I would like it to create itself and assign it's value to = false.


 

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

?????
Link to comment
Share on other sites

6 answers to this question

Recommended Posts

  • 0

So:

Look in the init.sqf for a file (or make one) that is executed BEFORE all the var list.

In exmaple, server_monitor.Sqf or compiles.Sqf.

In that file, make a statement, like

If (var = 1) then {variable = true;};

And then, in the init.sqf, you can check after the file has been executed if variable = true by if isNil.

 

I think this is what you look for, but I couldn't really understand what you wanted..

I didn't understand this, sorry :/

 

xBowBii

Pretty much, I have a variable that is called in server.pbo (with publicVariable function too) and I want to use it so when its false, something happens in mission.pbo (I want it so when Variable is set to false, systemchat will display a diff text than if it is set to true) so like...

Var is non existing in server pbo if someone uses your mission file wiothout server file

If it doesnt exist, I want it to auto-create itself with the value false

And then, I have a file which is called serial.sqf:

 

if (variable = true) {
uisleep 25;
titleText ["Text", "PLAIN DOWN", 3];
systemChat "Text";
};
if (variable = false) {
blablablabla };
Link to comment
Share on other sites

  • 0

If I understood you right you want a variable server side which is either true or false. However, if this variable doesn't exist it should be false.

if (isNil "Variable") then {Variable = false;};
if ((typeName Variable) == "BOOL") then { //make sure the variable is a boolean
	if (Variable) then
		uisleep 25;
		_txt = "The variable is true!";
		titleText [_txt, "PLAIN DOWN", 3];
		systemChat _txt;
	} else {
		_txt = "This variable is false or doesnt exist!";
		titleText [_txt, "PLAIN DOWN", 3];
		systemChat _txt;
	};
};

In your server_monitor.sqf you can set

Variable = true;
publicvariable "Variable";
Link to comment
Share on other sites

  • 0

 

If I understood you right you want a variable server side which is either true or false. However, if this variable doesn't exist it should be false.

if (isNil "Variable") then {Variable = false;};
if ((typeName Variable) == "BOOL") then { //make sure the variable is a boolean
	if (Variable) then
		uisleep 25;
		_txt = "The variable is true!";
		titleText [_txt, "PLAIN DOWN", 3];
		systemChat _txt;
	} else {
		_txt = "This variable is false or doesnt exist!";
		titleText [_txt, "PLAIN DOWN", 3];
		systemChat _txt;
	};
};

In your server_monitor.sqf you can set

Variable = true;
publicvariable "Variable";

I did that in another file that I execute with server_functions,sqf, would that not work?

because right now, it does not do what it is supposed to do (execute a file and show text messages like I showed before) it just does nothing

Link to comment
Share on other sites

  • 0

I did that in another file that I execute with server_functions,sqf, would that not work?

because right now, it does not do what it is supposed to do (execute a file and show text messages like I showed before) it just does nothing

 

that script executes on the server. Not for players, so u don't see anything ^^

Link to comment
Share on other sites

  • 0

that script executes on the server. Not for players, so u don't see anything ^^

No good sir, since I use publicVarialbe "variable"; to broadcast it to client side.

It does work now for like 1-2 scripts that are using this system I am talking about on this thread (if nul set it to false). I think the rest is just scripting issues on my end.

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...