Jump to content
Sign in to follow this  
Scatoogle

Request Variable from another script

Recommended Posts

I was wondering how I could request a varible from a script.

Kind like this

public static void main (String[] args){
System.Out.Print(Hello());
}

Public Static String Hello (){
RetVal = "Hello";
}

I don't think SQF is object oriented so I don't know how to call a variable like in Java or CPP because there are no classes. If you know of any Tuts that would delve deep into Arma Scripting it would be much appreciated.

And I did google how to do it but they were talking Arma 2 Scripting and I don't speak that fluently yet.

Share this post


Link to post
Share on other sites

No I mean how to I request a variable from another class or script. like Script one has Varible A this is = to 5. And I what to know what Variable A is equal to.

Share this post


Link to post
Share on other sites

You Call a script and get a return variable..... like a Quadric Formula Class.

Share this post


Link to post
Share on other sites
You Call a script and get a return variable..... like a Quadric Formula Class.

Some people like to a single function in its own file so it looks like this, My_Quadractic.sqf:

private ["_a","_b","_c","_result","_D"];
_a = _this select 0;
_b = _this select 1;
_c = _this select 2;

_result = [];
//Even quadratic / divide by zero?
if (_a == 0) then {
//Just return the solution to a linear equation
_result = [-_c / _b]; // bx + c = 0
} else {
_D = _b * _b - 4 * _a * _c;
if (_D == 0) then {
	_result = [-(_b / (2 * _a))];
};
if (_D > 0) then {
	_result = [(-_b + (sqrt _D)) / 2, (-_b - (sqrt _D)) / 2]
};
};
//Return result
_result   //No semicolon on return value - common convention

Others prefer more function in the same file, MyFunctions.sqf:

QuadraticRoots = {
private ["_a","_b","_c","_result","_D"];
_a = _this select 0;
_b = _this select 1;
_c = _this select 2;

_result = [];
//Even quadratic / divide by zero?
if (_a == 0) then {
	//Just return the solution to a linear equation
	_result = [-_c / _b]; // bx + c = 0
} else {
	_D = _b * _b - 4 * _a * _c;
	if (_D == 0) then {
		_result = [-(_b / (2 * _a))];
	};
	if (_D > 0) then {
		_result = [(-_b + (sqrt _D)) / 2, (-_b - (sqrt _D)) / 2]
	};
};
//Return result
_result   //No semicolon on return value - common convention
};

MyOtherFunc = {
//....
};

MyThirdFunc = {
//....
};

//.......

Here it how you would use it:

//How: Load from single function file:
QuadraticRoots = compile preProcessFile "My_Quadractic.sqf";

//How: Load from multi function file. (You just run the file, then the variables are created in memory)
[] call compile preProcessFile "MyFunctions.sqf";
//You would only use one of the above depending on your preference.


//Use it
//Find roots to  2x^2 + 0x - 40
_roots = [2, 0, -40] call QuadraticRoots;

hint format ["There are %1 roots and they are: %2", count _roots, _roots];

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×