OFPEC Forum

Editors Depot - Mission Editing and Scripting => ArmA - Editing/Scripting General => Topic started by: Sparticus76 on 01 Mar 2009, 03:38:20

Title: ArmA Starting Script from Script and exiting script problem
Post by: Sparticus76 on 01 Mar 2009, 03:38:20
G'day, I'm having problems with this script. I have a vehicle moving to a marker. If an enemy is detected in one of two "bluefor detected by opfor" triggers, then crp_assault script is called, and the current script is exited. Well that's what's supposed to happen. Can someone with know how lay their eyes on these and tell me where I'm going wrong with this.

Init.sqf
Code: [Select]

advance_vehicle = compile preprocessfilelineNumbers "advance_vehicle.sqf";
crp_assault = compile preprocessFilelineNumbers "CRP_Assault.sqf";


advance_vehicle.sqf
Code: [Select]
// Processed in Init.sqf by.. advance_vehicle = compile preprocessfilelineNumbers "advance_vehicle.sqf"
// Initiated by [vehicle, leadergroup, unitsgroupgroupleader] call advance_vehicle
if (!isServer) exitWith {};
Private ["_nul","_exit","_current_marker","_random_number","_vehicle","_leader","_units","_first_move_markers","_first_first_move_markers","_first_second_move_markers","_first_third_move_markers","_second_first_move_markers","_second_second_move_markers","_second_third_move_markers"];
_vehicle = _this select 0;
_leader = _this select 1;
_units = _this select 2;
_first_move_markers = ["move_marker_1","move_marker_2"];
_first_first_move_markers = ["move_marker_11a","move_marker_11b"];
_second_first_move_markers = ["move_marker_21a","move_marker_21b"];
_first_second_move_markers = ["move_marker_12a","move_marker_12b"];
_second_second_move_markers = ["move_marker_22a","move_marker_22b"];
_first_third_move_markers = ["move_marker_13a","move_marker_13b"];
_second_third_move_markers = ["move_marker_23a","move_marker_23b"];
_current_marker = "";
_exit = false;
// moving the vehicle
while { alive _vehicle } do
{
// Chose a random number to radomize the marker to move to
_random_number = random 100;
// 80% chance to move to move_marker_1
      if (_random_number > 20) then
{
    _vehicle domove getmarkerpos (_first_move_markers select 0);
    _current_marker = _first_move_markers select 0;
} else
{
_vehicle domove getmarkerpos (_first_move_markers select 1);
_current_marker = _first_move_markers select 1;
};
// Checks two triggers for detection of enemy. If detected, calls crp_assault script
while { (_vehicle distance (getmarkerpos _current_marker) >= 7) } do
{
sleep 1;
if ((BLUEFDET1 >= 1) or (BLUEFDET2 >= 1)) then
{
_nul = _vehicle call crp_assault;
exitwith {_exit = true};
}else
{
hint "crp_assault.sqf not initiated";
sleep 5;
};
      };
      // exitwith only exits out of the current loop, so exit again if _exit = true
      if (_exit) exitwith {};
};


CRP_Assault.sqf
Code: [Select]

private ["_vehicle"];

_vehicle = _this;

while { alive _vehicle } do
{
hint "CRP_Assault has been called";
sleep 1;
};


At the moment, there's alot of hints for fault finding. I found the faults, but dont know how to fix them.
It's not initiating the script CRP_Assault.sqf for some reason. And line 39 is apparently missing a ";".
I'm at a loss.
Title: Re: ArmA Starting Script from Script and exiting script problem
Post by: i0n0s on 01 Mar 2009, 13:02:53
"exitWith" only works in combination with "if":
Code: [Select]
if Boolean exitWith {Value};and
Code: [Select]
_nul = _vehicle call crp_assault;will wait until the crp_assault script is terminated.
Title: Re: ArmA Starting Script from Script and exiting script problem
Post by: Deadfast on 01 Mar 2009, 13:07:48
i0n0s is right, rewrite this part:
Code: [Select]
while { (_vehicle distance (getmarkerpos _current_marker) >= 7) } do
{
sleep 1;
if ((BLUEFDET1 >= 1) or (BLUEFDET2 >= 1)) then
{
_nul = _vehicle call crp_assault;
exitwith {_exit = true};
}else
{
hint "crp_assault.sqf not initiated";
sleep 5;
};
};

into this:
Code: [Select]
while { (_vehicle distance (getmarkerpos _current_marker) >= 7) } do
{
sleep 1;
if ((BLUEFDET1 >= 1) or (BLUEFDET2 >= 1)) exitWith
{
_nul = _vehicle spawn crp_assault;
_exit = true;
};
hint "crp_assault.sqf not initiated";
sleep 5;
};

Note call being replaced by spawn (run in parallel).
Title: Re: ArmA Starting Script from Script and exiting script problem
Post by: Spooner on 01 Mar 2009, 15:11:17
You only need to assign the value returned by spawn/execVM in the editor. In scripts, you can just ignore it:
Code: [Select]
_vehicle spawn crp_assault;
Title: Re: ArmA Starting Script from Script and exiting script problem
Post by: Rommel92 on 01 Mar 2009, 22:51:01
Code: [Select]
while { (_vehicle distance (getmarkerpos _current_marker) >= 7) } do
{
sleep 1;
if ((BLUEFDET1 >= 1) or (BLUEFDET2 >= 1)) exitwith {
_vehicle spawn {
while { alive _this } do
{
hint "CRP_Assault has been called";
sleep 1;
};
};
_exit = true;
};
hint "crp_assaultnot initiated";
sleep 5;
};
Why waste a script file, for something that you obviously wanted in parallel, just use spawn.
Title: Re: ArmA Starting Script from Script and exiting script problem
Post by: Sparticus76 on 02 Mar 2009, 07:01:21
Thanks alot gents, I'll try it all out now. Rommel92, that's not my real CRP_Assault.sqf, it's going to be much more than a hint. Although I think you're saying I could put that whole planned script into the exitwith code. Does the script run the whole extra scripting and then exit, or does it exit that while loop and continue while the spawned code is running?
Title: Re: ArmA Starting Script from Script and exiting script problem
Post by: Deadfast on 02 Mar 2009, 11:03:25
spawn creates a new instance for the executed code that runs in parallel with the old code.

(http://i182.photobucket.com/albums/x279/deadfastcz/junk/spawn.gif)