Linker Split 0 Posted January 16, 2015 Hello again, I've created a script called GlobalPos.sqf in which there are all the positions I need in array format like this: _GlobalPOS = [ [3232,455,21], [576,65,80], [1232,1425,33], [4232,5455,90], [11232,8455,67] ]; Now If I want to call this array from another script, should I add something to GlobalPos.sqf? Share this post Link to post Share on other sites
austin_medic 109 Posted January 16, 2015 Hello again,I've created a script called GlobalPos.sqf in which there are all the positions I need in array format like this: _GlobalPOS = [ [3232,455,21], [576,65,80], [1232,1425,33], [4232,5455,90], [11232,8455,67] ]; Now If I want to call this array from another script, should I add something to GlobalPos.sqf? you either need to execute the other script from globalpos.sqf with the variable as a parameter or make thevariable global (remove the underscore) so it can be referenced from the other script (other script also needs to run after the variable has been defined). Share this post Link to post Share on other sites
das attorney 858 Posted January 16, 2015 nvm 5chars Share this post Link to post Share on other sites
Linker Split 0 Posted January 16, 2015 (edited) nvm 5chars Ok. So 'm removing the underscore. Should I make it public with publicVariableServer/client also? This file basically is used to spawn cars in random points selected from the array #EDIT also, I'm adding in the init.sqf this line: [] execVM "globalPos.sqf" is it right? Or should I compile it? Edited January 16, 2015 by Linker Split Share this post Link to post Share on other sites
austin_medic 109 Posted January 16, 2015 (edited) Ok. So 'm removing the underscore.Should I make it public with publicVariableServer/client also? This file basically is used to spawn cars in random points selected from the array 1. I would assume you'd use publicVariable "myVariable"; 2. That should work, all compile does (to my knowledge) is load the script into the RAM so it doesnt need to access the hard drive to get the file contents the next time its called. Downside of that is that the CPU needs to waste time rewriting it to the RAM over and over (though I doubt that would matter much, the CPU is capable of millions of calculations in less than a second). Also might bog down the scheduler for the game as well. Though this is getting more complex than it needs to be. Edited January 16, 2015 by austin_medic Share this post Link to post Share on other sites
cuel 25 Posted January 16, 2015 Either you'd execute the file on every machine, or only have the server execute it and then you'd use globalVariable. Share this post Link to post Share on other sites
Linker Split 0 Posted January 16, 2015 Guys assuming my public Variable is ChernogorskPOS, once in another script should I call the content of this variable like this? _content1 = ChernogorskPOS select 0; Share this post Link to post Share on other sites
dreadedentity 278 Posted January 16, 2015 Guysassuming my public Variable is ChernogorskPOS, once in another script should I call the content of this variable like this? _content1 = ChernogorskPOS select 0; chernogorskPOS execVM "myNewScript.sqf"; //your data will be available using the magic variable "_this" Share this post Link to post Share on other sites
das attorney 858 Posted January 16, 2015 (edited) Hi, So that any PC can use this variable, put it in the init.sqf. GlobalPOS = [ [3232,455,21], [576,65,80], [1232,1425,33], [4232,5455,90], [11232,8455,67] ]; Then you don't need to make it public as it is automatically made public purely by being in the init.sqf. Then, any connected PC could do something like this: _thirdPos = GlobalPOS select 2; // works on any PC as long as the var is declared in init.sqf. If you are worried about someone hacking it and changing the value on their PC, then: yourScript.sqf is: [ [3232,455,21], [576,65,80], [1232,1425,33], [4232,5455,90], [11232,8455,67] ]; Then when you want to access the variable: _thirdPos = (call compileFinal preProcessFileLineNumbers "yourScript.sqf") select 2; Edited January 17, 2015 by Das Attorney read on... Share this post Link to post Share on other sites
dreadedentity 278 Posted January 16, 2015 Adding on to Das' post because this is worth mentioning, unchangeableVariable = compileFinal preProcessFileLineNumbers "yourScript.sqf"; //in init.sqf publicVariable "unchangeableVariable"; //all clients will have this variable now, and it will still be unchangeable Share this post Link to post Share on other sites
Linker Split 0 Posted January 16, 2015 Ok Guys so basically the name of the variable should be declared into the init.sqf to be automatically public, and then in the sqf there should be only the array. Ok testing! Share this post Link to post Share on other sites
dreadedentity 278 Posted January 16, 2015 Ok Guys so basically the name of the variable should be declared into the init.sqf to be automatically public, and then in the sqf there should be only the array.Ok testing! I'm not trying to be rude but you seem very inexperienced, and the way you're trying to do this is weird. Why not just have the array declaration in init.sqf to begin with and eliminate the need for a second script? Also, I'm not sure about how to "lock" values to prevent them from being changed. But there is Arma 3 Mission Parameters, which will totally negate even having to put your array in init.sqf anyway Share this post Link to post Share on other sites
killzone_kid 1331 Posted January 16, 2015 If you are worried about someone hacking it and changing the value on their PC, then: anUnchangeableGlobalVariable = compileFinal preProcessFileLineNumbers "yourScript.sqf"; // in init.sqf anUnchangeableGlobalVariable will be code, so to get third element it will need to be called: _thirdPos = (call anUnchangeableGlobalVariable) select 2; Share this post Link to post Share on other sites
das attorney 858 Posted January 17, 2015 @DE - not to be a pain mate, but if it is already declared as compileFinal'd in init.sqf, then everyone will be running it, so you don't need to send it to them as they already have it from the declaration in init.sqf. (Unless they are hacking and found a way NOT to run init.sqf, but I don't even want to think about that) :) edit: new post re: call Share this post Link to post Share on other sites
Linker Split 0 Posted January 17, 2015 (edited) I'm not trying to be rude but you seem very inexperienced, and the way you're trying to do this is weird. Why not just have the array declaration in init.sqf to begin with and eliminate the need for a second script? Also, I'm not sure about how to "lock" values to prevent them from being changed. But there is Arma 3 Mission Parameters, which will totally negate even having to put your array in init.sqf anyway Because it's not a single array, and an array contains about 200 position arrays inside, without considering the directional arrays saved, along with other info... it's a global spawn system for cars that goes with the persistent database :D I'm a bit inexperienced when coming to MP scripting (about declaring public variables, about trying to take rid of Hackers etc...) Edited January 17, 2015 by Linker Split Share this post Link to post Share on other sites
das attorney 858 Posted January 17, 2015 anUnchangeableGlobalVariable will be code, so to get third element it will need to be called:_thirdPos = (call anUnchangeableGlobalVariable) select 2; Good spot :) I should have put: anUnchangeableGlobalVariable = call compileFinal preProcessFileLineNumbers "yourScript.sqf"; // in init.sqf Then _thirdPos (anUnchangeableGlobalVariable select 2) would equal the _thirdPos from the first example. Edit: amended the example (just for anyone reading this later on). Share this post Link to post Share on other sites
dreadedentity 278 Posted January 17, 2015 @DE - not to be a pain mate, but if it is already declared as compileFinal'd in init.sqf, then everyone will be running it, so you don't need to send it to them as they already have it from the declaration in init.sqf. (Unless they are hacking and found a way NOT to run init.sqf, but I don't even want to think about that) :) Sure, but some people love to incorrectly use a little command called exitWith: if (!isServer) exitWith {}; Ever seen one of these before? Share this post Link to post Share on other sites
das attorney 858 Posted January 17, 2015 Lol yeah, that's very true :) As you say, it's not good practice using one of them bad boys in init.sqf. edit: Thinking about it; if the mission maker is that bad that he exits the init.sqf before he makes important declarations, then he probably deserves to be hacked! XD Share this post Link to post Share on other sites
Linker Split 0 Posted January 17, 2015 (edited) Guys, I did this: in the init.sqf I wrote down ChernogorskPOS = call compile preProcessFileLineNumbers (DZ_DIR_P + "ChernogorskPOS.sqf"); ChernogorskDIR = call compile preProcessFileLineNumbers (DZ_DIR_P + "ChernogorskDIR.sqf"); Then in a script (car.sqf) called from init.sqf, I wrote: _content1 = (call ChernogorskPOS select 4); _content2 = (call ChernogorskDIR select 21); diag_log format["GLOBALSPAWNINGSYSTEM: CONTENT IS %1, %2",_content1,_content2]; It returns me any, any even if I change to _content1 = (ChernogorskPOS select 4); _content2 = (ChernogorskDIR select 21); why? any suggestions? BTW the mission gets loaded correctly btw #EDIT btw, the sqf the variables are attached to are like this: [ [numbers,numbers,numbers]; [numbers,numbers,numbers]; [numbers,numbers,numbers]; [numbers,numbers,numbers]; [numbers,numbers,numbers]; [numbers,numbers,numbers]; [numbers,numbers,numbers]; ]; Edited January 17, 2015 by Linker Split Share this post Link to post Share on other sites
killzone_kid 1331 Posted January 17, 2015 Good spot :)I should have put: anUnchangeableGlobalVariable = call compileFinal preProcessFileLineNumbers "yourScript.sqf"; // in init.sqf Then _thirdPos (anUnchangeableGlobalVariable select 2) would equal the _thirdPos from the first example. Edit: amended the example (just for anyone reading this later on). I doubt this will achieve desired result as your variable will be a normal array wether you compile or compilefinal the code. The return of final function is not final. The only way to make sure it cannot be changed is to keep it stored as final code and call it when needed, see my previous post. Share this post Link to post Share on other sites
das attorney 858 Posted January 17, 2015 Ok I see what you are driving at now. So: anUnchangeableGlobalVariable = call compileFinal preProcessFileLineNumbers "yourScript.sqf"; Can be altered with: anUnchangeableGlobalVariable = nil; So keep calling the code as per your example instead of setting to a variable and it will remain unchangeable. Share this post Link to post Share on other sites
Linker Split 0 Posted January 17, 2015 thank you guys worked like a charm :) Share this post Link to post Share on other sites