Jump to content
Sign in to follow this  
Frostman

Function timing issue - Help Appreciated

Recommended Posts

I need some help with a problem i'm facing.

I have an unit which contains two coded functions (lets call them F1 and F2), F1 contains my units initiation code (F1 runs at map start for each unit), F2 contains my multi-player initialisation code (F2 runs at map start for a single unit only).

Now using pseudo code this is how its meant to work.

-- UNIT1 run F1 on map start

F1:

1) Has F2 has been initialised?

#Yes

Continue F1...

#No

2) Has another unit already started F2?

#Yes

Wait till F2 is initialised.

#No

Run F2...

*When F2 has been run it sets a global boolean to make sure its not run again (else we wipe previously set parameters).

The problem I've got is i can't find a reliable way of getting F1 to wait until F2 has been initialised, this is a problem because F2 sets up global arrays that F1 needs.

I just need these functions to run in the right order over multiple units, so any help would be really appreciated.

Share this post


Link to post
Share on other sites

In F2...

F2HasBeenInit = TRUE;

In F1

waituntil {!isNil "F2HasBeenInit"};

rest-of-code.

That will make F1 wait until F2HasBeenInit has a value, any value.

Edited by Wokstation

Share this post


Link to post
Share on other sites
In F2...

F2HasBeenInit = TRUE;

In F1

waituntil {!isNil "F2HasBeenInit"};

rest-of-code.

That will make F1 wait until F2HasBeenInit has a value, any value.

I agree that that should work but I'm still having issues, here's my exact code with the trouble areas highlighted in bold:

*The addons being built within a mission atm so ignore any path errors you see

F1:

private["_stairs","_height","_dir","_gate","_home","_name","_address","_custom","_InitialArray","_thisgate"];

comment "Function Start";
_gate = _this select 0;
_reverse = _this select 1;
_height = _this select 2;
_type = _this select 3;
_dir = getdir _gate;

comment "Initalize Functions";
if(isnil "RunOnce")then{RunOnce = TRUE;[] execVM "dsf_sg_basecode\fInitFunctions.sqf"};
if(local _gate)then{

comment "Set Default EventHorizion Texture";	
_gate setobjecttexture [18,"\dsf_sg_gate\tex\eh\init1.paa"];
_gate setobjecttexture [18,""];

[b]comment "Initalize Arrays";
if(isnil "DSF_SG_Primary")then{DSF_SG_Primary = TRUE;[] execVM "dsf_sg_basecode\fInitArrays.sqf";}; 
waitUntil{!isnil "DSF_Initialised"};[/b]

comment "Place Stairs";
_stairs = _type Createvehicle[(getpos _gate select 0),(getpos _gate select 1),(getpos _gate select 2)];
_stairs setpos [(getpos _stairs select 0),(getpos _stairs select 1),(getpos _stairs select 2)+(_height)];
if(_reverse)then{_stairs setdir (_dir-180)}else{_stairs setdir _dir};

comment "Create Stargate Variables";
_name = [_gate] call DSF_fCreateName;
_custom = [_gate] call DSF_fAddressGlyphs;
if(count _custom == 7)then{
	_home = _custom select 6;
	_custom resize 6;
	_address = _custom;
}else{
	_address = [_gate] call DSF_fCreateAddress;
	_home = [_address] call DSF_fCreateHome;
};
[_address,_home,_custom] exec "Debug1.sqs";

comment "Set Stargate Arrays";
DSF_SG_StargateArray = DSF_SG_StargateArray + [_gate];
DSF_SG_OriginArray = DSF_SG_OriginArray + [_home];
DSF_SG_AddressArray = DSF_SG_AddressArray + [_address];
DSF_SG_NameArray = DSF_SG_NameArray + [_name];
DSF_SG_ScriptArray = DSF_SG_ScriptArray + [""];
DSF_SG_ActivityArray = DSF_SG_ActivityArray + [[]];
DSF_SG_BufferArray = DSF_SG_BufferArray + [[[]]];
DSF_SG_IncomingArray = DSF_SG_IncomingArray + [[]];
DSF_SG_DHDOutgoingArray = DSF_SG_DHDOutgoingArray + [[]];
DSF_SG_GateOutgoingArray = DSF_SG_GateOutgoingArray + [[]];
DSF_SG_FocusArray = DSF_SG_FocusArray + [""];
DSF_SG_WormholeArray = DSF_SG_WormholeArray + [[]];
DSF_SG_DialingGroups = DSF_SG_DialingGroups + [[]];

comment "Send Stargate Arrays";
publicVariable "DSF_SG_StargateArray";
publicVariable "DSF_SG_OriginArray";
publicVariable "DSF_SG_AddressArray";
publicVariable "DSF_SG_NameArray";
publicVariable "DSF_SG_ScriptArray";
publicVariable "DSF_SG_ActivityArray";
publicVariable "DSF_SG_BufferArray";
publicVariable "DSF_SG_IncomingArray";
publicVariable "DSF_SG_DHDOutgoingArray";
publicVariable "DSF_SG_GateOutgoingArray";
publicVariable "DSF_SG_DialingPorts";
publicVariable "DSF_SG_DialingGroups";
publicVariable "DSF_Initialised";

}else{
comment "Client Wait";
waitUntil{!isnil "DSF_Initialised"};
};
comment "Get Stargate Index";
_thisgate = -1;
while{_thisgate == -1}do{
_thisgate = [_gate,DSF_SG_StargateArray] call DSF_fGetIndex;
};
comment "Launch Dialing Handler";
[_thisgate] spawn DSF_fLocalHandler;

exit

F2:

_InitialArray = [1,2,3,4,5,6,7,8,9,10,11,12,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37];
DSF_Address_Cypher = [];
while {count _InitialArray > 0}do{_i = _InitialArray select floor(random (count _InitialArray)); DSF_Address_Cypher = DSF_Address_Cypher + [_i]; _InitialArray = _InitialArray - [_i];};

DSF_SG_StargateArray = [];
DSF_SG_OriginArray = [];
DSF_SG_AddressArray = [];
DSF_SG_NameArray = [];
DSF_SG_ScriptArray = [];
DSF_SG_ActivityArray = [];
DSF_SG_BufferArray = []; 
DSF_SG_IncomingArray = [];
DSF_SG_DHDOutgoingArray = [];
DSF_SG_GateOutgoingArray = [];
DSF_SG_FocusArray = [];
DSF_SG_WormholeArray = [];
DSF_SG_DHDActivity = [];
DSF_SG_DialingGroups = [];

[b]DSF_Initialised = TRUE[/b];

Honestly it seemed to be working until I tried running it along side the ACE2 Mod, now the timing screws up.

Edited by Frostman

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  

×