Jump to content
daza

"Error Do: type array expected code" error..

Recommended Posts

It's been ages since i did some basic scripting or a mission for that matter getting back into it, i have almost finished a new SP mission that i am carrying over into MP for coop.

So I need a little help with a a simple respawn script here, the error message says for line 2- "Error Do: type array, expected code"..

 

I am using Note ++ (with the Arma language plugin- cool plugin) and when i click on the left curly bracket after 'do' its closing bracket is just before 'else', which i am wondering is the problem that being the IF condition is not fully inside the loop??  I tried adding an extra }; at the very end (but the Note++ did not highlight the bracket which means it doesn't belong there). 

 

Also i have feeling the sleep should be outside of the If/else condition? I tried to give its own {  }; but still gives the same error. 

 

Would it be better for me to use the switch code within the loop? 

if (!isServer) exitWith {};
while {true} do {

If ((alive mhq) and (speed mhq == 0)) then {
"Respawn_West" setmarkerpos getpos mhq;}
} else 
{ "Respawn_West" setmarkerpos (getmarkerpos "alternativespawn"); 
sleep 6;
};

It's been ages since i did some basic scripting or a mission for that matter getting back into it, i have almost finished a new SP mission that i am carrying over into MP for coop.

Share this post


Link to post
Share on other sites

Wrong brace position. should be:

if (!isServer) exitWith {};
while {true} do {
  If ((alive mhq) and (speed mhq == 0)) then {
    "Respawn_West" setmarkerpos getpos mhq;
  } else {
    "Respawn_West" setmarkerpos (getmarkerpos "alternativespawn"); 
  };
  sleep 6;
};

Share this post


Link to post
Share on other sites

What polpox said.

Your example was basically a "while {true} do {} else {}" syntax, which doesn't work.

 

Try working with indents to identify scopes more easily.

 

Cheers

Share this post


Link to post
Share on other sites

Thanks polpx and Grumpy Old Man for your help. Errors are gone now. However my script isn't really working as intended, i am testing it by blowing up the mhq with myself right next to it, and then i respawn right next to the burning wreck instead of at the alternative respawn site. I tried shortening the sleep delay but makes no difference. The alternative spawn works as i swapped them around to see if there was a problem with that. No problem there. Either way of condition if the mhq is destroyed or not you still spawn next to the mhq vehicle. Any ideas why this isn't working as it intended? 

Share this post


Link to post
Share on other sites

Thanks for your reply kylania. I had a go using those function but it still is happening as I described. Here is the change..

if (!isServer) exitWith {};
while {true} do {
If ((alive mhq) and (speed mhq == 0)) then {
   [west, mhq] call BIS_fnc_addRespawnPosition;
  
} else { 
  [west, 1] call BIS_fnc_removeRespawnPosition;
  [west, mhq2] call BIS_fnc_addRespawnPosition;
};

  sleep 2;
};

Im using another vehicle for the second placement as i have yet to work out how to define a marker in that function call, would i just use [west, "markername" ] call... OR like this?.. [west, getmarkerpos "markername"] call etc?  anyway my script is still behaving as if the condition is not true and always going to else.

 

Note: I am using a vehicle respawn script by Tophe, that is set to respawn the destroyed vehicle after 40 seconds, but i don't think this has any impact of why my respawn player isn't working properly, but thought to mention it in any case. 

Share this post


Link to post
Share on other sites


// Create a respawn at MHQ2 labeled as "MHQ Two"

_rspMHQ2 = [west, mhq2, "MHQ Two"] call BIS_fnc_addRespawnPosition;

// Create a respawn at a marker named "respawn_hospital" labeled as "Hospital"

_rspHosp = [west, "respawn_hospital", "Hospital"] call BIS_fnc_addRespawnPosition;

// Remove the points above.

_rspMHQ2 call BIS_fnc_removeRespawnPosition;

_rspHosp call BIS_fnc_removeRespawnPosition;

Share this post


Link to post
Share on other sites

Okay if i have done it right here is the change...again the condition is being ignored and else always wins no matter which way it is, the player dies but MHQ in one piece or both are killed at the same time.

if (!isServer) exitWith {};
while {true} do {
If ((alive mhq) and (speed mhq == 0)) then {
    _rspHosp call BIS_fnc_removeRespawnPosition;
    _rspMHQ2 = [west, mhq, "MHQ Two"] call BIS_fnc_addRespawnPosition;
  
} else { 
  _rspMHQ2 call BIS_fnc_removeRespawnPosition;
  _rspHosp = [west, "respawn_hospital", "Hospital"] call BIS_fnc_addRespawnPosition;
   

  sleep 2;
};
 

I have made a quick demonstration of what is happening if you want to have a look at it. I have been using the Demo Expert character and his ordnance to die and also destroy the mhq. I noticed also that in the Eden editor there are new MP settings for respawn so i wonder if this makes a difference at all which ones are selected in light of using a script to alter the respawn or you can still script around them. The demo is not binarized. I dont understand why the condition in the script is being ignored..

 

https://www.mediafire.com/?owknfjmnqf7bxhi

Share this post


Link to post
Share on other sites

You're missing a }; at the end. 

if (!isServer) exitWith {};
while {true} do {
	If ((alive mhq) and (speed mhq == 0)) then {
		_rspHosp call BIS_fnc_removeRespawnPosition;
		_rspMHQ2 = [west, mhq, "MHQ Two"] call BIS_fnc_addRespawnPosition;
	} else { 
		_rspMHQ2 call BIS_fnc_removeRespawnPosition;
		_rspHosp = [west, "respawn_hospital", "Hospital"] call BIS_fnc_addRespawnPosition;
    };

  sleep 2;
};

Share this post


Link to post
Share on other sites

Thanks for spotting the missing bracket. Added the missing bracket. However it is still spawning at the "else"  even though the mhq is untouched and not moving. I had a similar script working a year or two ago for some of my A2 MP missions that changed the spawn location if vehicle was destroyed, but because i have a new computer i don't have my old files.  Is there another way i can do this, because my script isn't suited to the task it seems?

Share this post


Link to post
Share on other sites

You could switch to eventhandlers, which is the best way to do this.

Killed EH and Engine EH could work out just fine for your case.

 

Cheers

 

Thanks Grumpy

// RespawnCheck
switch (true) do {
case (alive mhq && (speed mhq ==0)): {"Respawn_West" setMarkerPos (getpos mhq); hint "Moving Marker to MHQ";};
case (!alive mhq or (speed mhq != 0)): {"Respawn_West" setMarkerPos (getMarkerpos "respawn_hospital"); hint "Moving Marker to Tent";};
};

I got the eventhandler setup okay. Which runs this script (above) when player is killed.

 

Respawn West marker is placed in a neutral area. 

1# Death: Firstly i kill my PC away from the mhq.  The hint for testing, shows ingame "Moving Marker to MHQ" 

But instead i respawn where the Respawn_West was placed in the editor. 

2# Death: I repeat the above (in same instance of demo) and now i get moved to MHQ as it should.

 

Now next to MHQ: (same instance of demo)

When i blow up PC and mhq, i respawn next to the wreck of mhq.

Repeat death, i am now respawn near the tent like its suppose to as mhq hasnt respawned yet.

 

I also tried this:


// RespawnCheck


_rspHosp = [west, "respawn_hospital", "Hospital"];
_rspMHQ2 = [west, mhq, "MHQ Two"];
switch (true) do {
case (alive mhq && (speed mhq ==0)): {
     _rspHosp call BIS_fnc_removeRespawnPosition;
     _rspMHQ2 = [west, mhq, "MHQ Two"] call BIS_fnc_addRespawnPosition; hint "Moving Marker to MHQ";};
case (!alive mhq or (speed mhq != 0)): {
     _rspMHQ2 call BIS_fnc_removeRespawnPosition;
    _rspHosp = [west, "respawn_hospital", "Hospital"] call BIS_fnc_addRespawnPosition; hint "Moving Marker to Tent";};
};

I tried also the addRespawnPosition fnc but this doesn't work at all, give me an error for line 23 on one of the function calls scripts. I declared the variables outside the case because earlier i was getting a unknown variable error for one of them.

 

So i will stick with the move Respawn_West marker method for the respawn script, its nearly there just need to know why it ONLY works on the 2nd death every time. The hints are showing the script is working and the conditions are correct.  

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

×