d3nn16 3 Posted November 25, 2007 This is what I do in my mission : init.sqf : <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">[...] execVM "labyrinth\createLabyrinth.sqf"; createLabyrinth.sqf : <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">//I set up 2 variables edgesTab = []; numElTab = []; //then i have one script called several times inside a loop that modifies them for [{_i=0;}, {_i<param2;}, {_i=_i+1;}] do { [_i, ...] execVM "labyrinth\createPolygons.sqf"; ... }; //and another one that uses the variables with the modifications made by the first script [...] execVM "labyrinth\completeLabyrinth.sqf"; When i use execVM inside createLabyrinth.sqf the code does what I want it to do : it creates a labyrinth. But when I replace "execVM" with "call compile preprocessFile" it doesn't work anymore and the first script doesnt build all the polygons and the second script tries to obtain a value that wasn't inserted/initialized in the variables by createPolygons.sqf (makes a division by zero). It seems the 2 global variables can"t be modified inside the functions (they run like functions since i used the call command). I also set the variables used inside the 2 scripts as private so they don't interfere with the ones inside the calling script. Anyone knows the trick here ? I can send you my mp map to check it if anyone is interested. Share this post Link to post Share on other sites
raedor 8 Posted November 25, 2007 call compile preprocessFile "pastes" the code just in there and executes it then, after executing that, it goes on. execVM opens a new script and immediately goes on with the old one. Share this post Link to post Share on other sites
d3nn16 3 Posted November 26, 2007 knowing that call "pastes" the code, createPolygons.sqf script should be executed entirely before continuing with completeLabyrinth.sqf. That's why I don't understand why execVM which creates a parallel thread works (completeLabyrinth.sqf gets the right variables from createPolygons.sqf which shouldn't be the case) and call doesn't work. Share this post Link to post Share on other sites
UNN 0 Posted November 26, 2007 Quote[/b] ]That's why I don't understand why execVM which creates a parallel thread works Without seeing the code in both of those scripts, it's impossible to say for sure. All we can do is guess. Perhaps your using a command that’s exclusive to ExecVM and won't work with the call command? Also there is locality, any variable that isn't defined as private within the call command, will be global to the calling script and function, so it's prone to being overwritten. Share this post Link to post Share on other sites
d3nn16 3 Posted November 27, 2007 Ok here is the code : I insist that when i use execVM it works fine but when i change to call i have an zero divisor error. If you want to test it I can send the entire map. You can PM me ? INIT.SQF <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> ... _discRadius = 10; _startEdges = 27; _corridorWidth = 5; [_discRadius, _startEdges, _corridorWidth] execVM "labyrinth\createLabyrinth.sqf"; ... CREATELABYRINTH.SQF <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> _discRadius = _this select 0; _startEdges = _this select 1; _corridorWidth = _this select 2; edgesTab = []; numElTab = []; for [{_i=0;}, {_i<param2;}, {_i=_i+1;}] do { edgesTab = edgesTab + [[]]; numElTab = numElTab + [0]; }; for [{_i=0;}, {_i<param2;}, {_i=_i+1;}] do { [_i, position LC, (_discRadius + _i * _corridorWidth), _startEdges, 1.25, "wall1"] execVM "labyrinth\createPolygons.sqf"; _startEdges = _startEdges + 12 + (_i % 2); }; [param2, "Land_brana02nodoor", 0.5, 0.1] execVM "labyrinth\completeLabyrinth.sqf"; ... CREATEPOLYGONS.SQF <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> private ["_numTab", "_center", "_radius", "_numEdges", "_trans", "_object", "_angLap", "_initVect", "_vect", "_ang", "_edgePos"]; _numTab = _this select 0; _center = _this select 1; _radius = _this select 2; _numEdges = _this select 3; _trans = _this select 4; _object = _this select 5; _angLap = 360 / _numEdges; _initVect = [0, _radius]; _vect = [0, _radius]; _ang = 0; _edgePos = [(_vect select 0) + (_center select 0), (_vect select 1) + (_center select 1)]; for [{_i=0}, {_i<_numEdges}, {_i=_i+1}] do { ... edgesTab set [_numTab, ((edgesTab select _numTab) + [_wall])]; numElTab set [_numTab, (numElTab select _numTab) + 1]; ... }; COMPLETELABYRINTH.SQF <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> private ["_numPolyg", "_object", "_transSide", "_transFront", "_solutionGates", "_chosenGates", "_excludedObstacles"]; _numPolyg = _this select 0; _object = _this select 1; _transSide = _this select 2; _transFront = _this select 3; _solutionGates = []; _chosenGates = []; _excludedObstacles = []; ... _excluded = [_numEdge-3, (_numEdge-2)%(numElTab select _c), (_numEdge-1)%(numElTab select _c), _numEdge, (_numEdge+1)%(numElTab select _c), (_numEdge+2)%(numElTab select _c), (_numEdge+3)%(numElTab select _c)]; ... deleteVehicle ((edgesTab select _c) select ((_chosenGates select _c) select _i)); ... _angLap = 360 / (numElTab select _c); <------- here is the error with zero divisor _angLapSup = 360 / (numElTab select (_c+1)); ... Share this post Link to post Share on other sites
raedor 8 Posted November 28, 2007 From a quick view... maybe rename the counter _i in the CREATEPOLYGONS.SQF to _j? The "for" command possibly does not scope the counter correctly -- not sure, though. Share this post Link to post Share on other sites
d3nn16 3 Posted November 28, 2007 Raedor you solved my problem. The 2 _i were interfering. So I just put the _i from createPolygons in the list of private variables. I also have a labyrinth that looks a bit different when i use the call command, probably because createPolygons and completeLabyrinth were running in parallel with execVM. Thanks again Share this post Link to post Share on other sites
UNN 0 Posted November 28, 2007 Never mind, problem solved Share this post Link to post Share on other sites