Jump to content
Sign in to follow this  
hoverguy

SetPos && attachTo loop

Recommended Posts

Hi everyone, first time poster here, hope everything is in place!

In the following examples slidinggate is a fence ("Land_SportGround_fence_F"):

_gate = slidinggate;
_numb = 23487.7;
for "_i" from 1 to 50 do
{	
   _gate setPos [_numb, 18768.7, -0.05];
   _numb = _numb + 0.1;
   sleep 0.1;
};

_gate = slidinggate;
_attach = tower;
_numb = -11.95;
for "_i" from 1 to 50 do
{	
   _gate attachTo [_attach, [_numb,5.8,-2.5]];
   _numb = _numb + 0.1;
   sleep 0.1;
};

These two examples work really well locally, but what if I wanna try it in an dedicated environment?

Answer:

- 1rst one fails to work

- 2nd one still works

So I was asking myself, why isn't this working?

Seems that, in my opinion, the setPos loop is too fast and the network sync too slow. In other words the sync can't be done that fast.


  • What I was expecting:

setPos [23487.7, 18767.7, -0.05] => SYNC => _numb is now 23487.8 => sleep 0.1 => setPos [23487.8, 18767.7, -0.05] => SYNC //etc... etc... You can see the gate moving apart 0.1 by 0.1 for a total of 50 iterations.


  • In reality:

setPos [23487.7, 18767.7, -0.05] => _numb is now 23487.8 => sleep 0.1 => setPos [23487.8, 18767.7, -0.05] => SYNC //You can see the gate moving to where it's supposed to be when the loop is finished

I don't understand why the attachTo command works flawlessly and updates really fast when setPos is really slow for the same action. I really have to use the setPos option because I need object collision (the fences are used as my main gates).

1/ So is it because of the sync being too slow?

2/ Is the engine waiting for packets of things rather than doing the job step by step?

3/ Is the command not being processed onEachFrame?

4/ Is this intended?

PS: This is what I found that (i think) explains this behaviour very well (Sniperwolf572 - #519): http://forums.bistudio.com/showthread.php?160330-Scripting-Discussion-(dev-branch)&p=2791294&viewfull=1#post2791294

Thank you guys.

Edited by HoverGuy

Share this post


Link to post
Share on other sites

Bumpy bump, still need help with this, is there a possible workaround?

Share this post


Link to post
Share on other sites
Bumpy bump, still need help with this, is there a possible workaround?

Could maybe provide a link to maybe a mission? I'm confused as to what you want. Maybe because in a dedicated environment that the commands are only executed on the server and are not sent out globally until maybe a few seconds later.

Share this post


Link to post
Share on other sites
Could maybe provide a link to maybe a mission? I'm confused as to what you want.

Yeah sorry for that, as I said first time poster and i'm aware am not good at explaining things.

Maybe because in a dedicated environment that the commands are only executed on the server and are not sent out globally until maybe a few seconds later.

Agreed, but why the attachTo loop works without noticeable delay (besides the sleep 0.1) when the setPos loop does not and only updates (visually) when the loop has ended...

What am trying to do, basically, is to createVehicle'd two fences and make em slide apart.

Heres the baseBuilder.sqf file (execVM'd in init.sqf located into \@server\addons\server\) - SAMPLE

slidinggate5 = "Land_SportGround_fence_F" createVehicle _markPos; 
slidinggate5 attachTo [tower,[2.5,85,-9.5]]; 
_sl5pos = getPos slidinggate5; 
detach slidinggate5; 
slidinggate5 setDir _dir1; 
slidinggate5 setPos _sl5pos; 
slidinggate5 setVariable ["TOGGLE_3",false,true]; 
slidinggate5 allowDamage false; 
publicVariable "slidinggate5";

slidinggate6 = "Land_SportGround_fence_F" createVehicle _markPos; 
slidinggate6 attachTo [tower,[-2.5,85,-9.5]]; 
_sl6pos = getPos slidinggate6; 
detach slidinggate6; 
slidinggate6 setDir _dir1; 
slidinggate6 setPos _sl6pos; 
slidinggate6 allowDamage false; 
publicVariable "slidinggate6";

tablet1 = createVehicle ["Land_Tablet_01_F", _markPos, [], 0, "CAN_COLLIDE"]; 
tablet1 attachTo [post1,[-0.23,0,1.7]]; 
tablet1 setVectorDirAndUp [[0,1,0],[-1,0,0]]; 
publicVariable "tablet1";

Here is the functions.sqf file (execVM'd in init.sqf located into \@server\addons\server\) - SAMPLE

PP_fnc_addActionMP = compileFinal
"
private[""_object""];

_object = _this select 0;

switch(_object) do
{
   case tablet1:
{
    _object addAction [""Open the gate"", PP_fnc_toggleGates,0,0,false,false,"""", ' vehicle player == player && player distance _target < 2 && (!(slidinggate5 getVariable ""TOGGLE_3"")) ']; 
       _object addAction [""Close the gate"", PP_fnc_toggleGates,0,0,false,false,"""", ' vehicle player == player && player distance _target < 2 && (slidinggate5 getVariable ""TOGGLE_3"") '];
};
};
";

PP_fnc_toggleGates = compileFinal
"
private[""_object"",""_gate1"",""_gate2"",""_var""];

_object = _this select 0;

switch(_object) do
{
   case tablet1:
   {
       _gate1 = slidinggate5;
       _gate2 = slidinggate6;
       _var = _gate1 getVariable ""TOGGLE_3"";

       if(!_var) then 
       {
           _gate1 setVariable [""TOGGLE_3"",true,true];
           _gate1 say3d ""Alarm_BLUFOR"";
           _y = 0.1;
           for ""_i"" from 1 to 50 do
           {
               _gate1 setPos [(getPos _gate1 select 0) + _y, (getPos _gate1 select 1), -0.05];
	        _gate2 setPos [(getPos _gate2 select 0) - _y, (getPos _gate2 select 1), -0.05];
            sleep 0.1;
           };
	}
	else
	{
        _gate1 setVariable [""TOGGLE_3"",false,true];
        _gate1 say3d ""Alarm_BLUFOR"";
        _y = 0.1;
        for ""_i"" from 1 to 50 do
           {	
               _gate1 setPos [(getPos _gate1 select 0) - _y, (getPos _gate1 select 1), -0.05];
	        _gate2 setPos [(getPos _gate2 select 0) + _y, (getPos _gate2 select 1), -0.05];
            sleep 0.1;
           };
       };
}:
};
";

Mission: https://www.dropbox.com/s/cq3zx3b9wogdbj3/GATES.Altis.rar?dl=0 <- This is how it looks like locally

Edited by HoverGuy

Share this post


Link to post
Share on other sites

maybe replace the addaction stuff with this instead (tablet1)

tablet1 addAction ["Open the gate", {["toggleGates.sqf","bis_fnc_execVM",false,true] call BIS_fnc_MP;},0,0,false,false,"", ' vehicle player == player && player distance _target < 2 && (!(slidinggate1 getVariable "TOGGLE")) ']; tablet1 addAction ["Close the gate", {["toggleGates.sqf","bis_fnc_execVM",false,true] call BIS_fnc_MP;},0,0,false,false,"", ' vehicle player == player && player distance _target < 2 && (slidinggate1 getVariable "TOGGLE") '];

Share this post


Link to post
Share on other sites

Thanks for this will give it a go soon enough.

Have you hosted the mission? The example mission is how i want it to be, if you host it dedicated you'll see that the "anim" (gates moving apart) is somewhat laggy, takes too much time to sync (or maybe the render time scope is simulated).

Thats why i wanted to know if its intended or not as i was about to report the issue but wanted some feedback before.

What do you think?

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  

×