Jump to content
Sign in to follow this  
publicfunction

Passing a Task to addAction

Recommended Posts

Hi all,

I am trying to get a task to update when passed through addAction as an argument, but the argument being passed is not behaving as I expect. Accoriding to the docs I should be able to post a Task object as an argument in the addAction function. here is the code:

briefing.sqf

player createDiaryRecord ["Diary", ["Mission: Recover the Intel", "Your mission is to recover an important piece of intel from OPFOR hands. You must try remain undetected during the mission, it will make for you easier."]];

objTaskOne = player createSimpleTask ["Recover the Intel."];
objTaskOne setSimpleTaskDescription ["In Camp Rogain, the OPFOR have valuable intel we need, go recover it.", "Get the Intel", "Pickup the Intel"];
objTaskOne setSimpleTaskDestination (getMarkerPos "objTask1");

objTaskTwo = player createSimpleTask ["Kill the Bad Guy", objTaskOne];
objTaskTwo setSimpleTaskDescription ["Kill the Bad Guy", "Kill the Bad Guy", "Kill the Bad Guy"];
objTaskTwo setSimpleTaskDestination (getMarkerPos "objTask2");

player setCurrentTask objTaskOne;
player setCurrentTask objTaskTwo;

addAction on the object in question

Adding the addAction and 2 arguments one being the task and the other an integer for the _rotation for setdir.

player_objective addAction ["Pickup Intel", "objectiveGather.sqf", [objTaskOne, 158], 1, false, false, "", ""];

objectiveGather.sqf

This is the sqf file is supposed to deal with knowing the task object to update its state and assign the _object to the player by attachTo.

_object = (_this select 0); 
_soldier = (_this select 1); 
_actionid = (_this select 2);
_thetask = (_this select 3) select 0;
_rotation = (_this select 3) select 1;

diag_log format["Task: %1", _thetask];
diag_log format["Rotation: %1 for %2", _rotation, _object];

_object attachTo [_soldier, [-0.18, -0.03, 0.03], "Pelvis"];
_object setdir _rotation;

//_the_task setTaskState "Succeeded";

The issue I see in the dial_log command is it reports _thetask as being "any" and not the Task object itself. I have tried initialising _thetask as objNull, but that didnt help.

Anyone got an ideas, is this a bug or do I need to call BIS_fnc_addAction, I am at a loss. I got around the problem by adding a trigger on the map and getting it to listen for an variable change and trigger the task update from that, but I wanted a more elegant solution.

Share this post


Link to post
Share on other sites

The main issue you're probably having is you capture the task as _thetask but then you try to use it as _the_task, with an extra underscore.

Also, since this script is specifically designed to complete that task and to set the rotation after attaching the object you don't need to pass anything since you already know the task and the rotation you want. If you're not reusing this for multiple tasks all attaching different objects at different rotations and completing multiple tasks just keep it simple.

_object = (_this select 0); 
_soldier = (_this select 1); 
_actionid = (_this select 2);

_object removeAction _actionid;

_object attachTo [_soldier, [-0.18, -0.03, 0.03], "Pelvis"];
_object setdir 158;

objTaskOne setTaskState "Succeeded";

Edited by kylania

Share this post


Link to post
Share on other sites

@kylania

_the_task is commented out, so ignore that.

The point of the script is to allow you to pass any task into it to update it, that means this single script is not locked to a single task, but can be reused by any object that needs to have an addAction and have a Task assigned to it for completion, allowing you to be able to add it to anything at any time, making it reusable and an elegant solution. The script is designed to be able to pass these additional parameters for that reason, hard coding them into the script is not really a great idea as that means you would need to create a single script for every time you wanted to achieve this, but under the solution you provide this means more sqf files and a multitude of triggers and other elements needing to be created to handle each one, this inflates your code and makes it bulky and full of unnecessary files, when a single solution should suffice. As developer I want to write a single solution to be able to handle its given parameters so that I do not have to repeat code again and again to be able to use it.

The problem I am trying to solve is: Why cant I pass this Task object into the script like the ARMA3 Documentation says I can! The args parameter of addAction states that Anything can be passed to it in ARMA 3, clearly that is not the case.

Edited by publicfunction
Grammar

Share this post


Link to post
Share on other sites

As a work-around if it's actually not accepting task objects, put all created tasks into an array and just pass the index number as the action parameter?

Share this post


Link to post
Share on other sites

@Shuko

Yeah I tried that by passing currentTasks player, but this would still mean that I would still need to know in the code before hand what task I want to update. The only viable solution that would work seamlessly is to pass the Task object in directly.

So you guys are aware I have tried multiple permutations of getting this to work, the big issue is that _thetask states it is "any", and not the actual Task object. It may be as simple as I need to use an alternative addAction function as I know this ability is only available with ARMA 3 and the older version only accept limited paramaters.

Share this post


Link to post
Share on other sites

Where is that addAction happening? from init.sqf, init box, some other script , object or trigger??

Share this post


Link to post
Share on other sites

@larrow

The addAction is on the objects Initialization field, I know using this is good enough, but I used the objects name directly.

Share this post


Link to post
Share on other sites

Because the addAction is in the initialization of the object the addaction is getting processed before the task actually exists.

Try something like this in the init box instead.

h = this spawn {
   waitUntil {!(isnil "objTaskOne")};
   _this addAction ["Pickup Intel", "objectiveGather.sqf", [objTaskOne, 158], 1, false, false, "", ""];
};

Edited by Larrow
edit code : missing bracket

Share this post


Link to post
Share on other sites

I would imagine the parameters would be used at the time the action is called/used and not when added, but of course my guess could be totally wrong.

Share this post


Link to post
Share on other sites

@larrow

You are a star, that is the explanation I was looking for. This must be down to the way ARMAs engine compiles its files, with the briefing.sqf file being one of the last and therefore as you said objTaskOne is not initialised when the addAction is compiled. This is the whole set of scripts I use now.

The objects initialization field:

i = this spawn { waitUntil {!(isNil "objTaskOne")}; _this addAction ["Pickup Intel", "objectiveGather.sqf", [objTaskOne, 1, 158], 1, false, false, "", ""]; };

objectiveGather.sqf

_object = _this select 0; 
_soldier = _this select 1; 
_action_id = _this select 2;
_task = _this select 3 select 0;
_status = _this select 3 select 1;
_rotation = _this select 3 select 2;

_object attachTo [_soldier, [-0.18, -0.03, 0.03], "Pelvis"];
_object setdir _rotation;

[_task, _status, "You have the Objecive, Now get out off there!", objTaskTwo, player] call updateTask;

updateTask.sqf

_task = _this select 0;
_status = _this select 1;
_hint = _this select 2;
_next_task = if (count _this > 3 ) then { _this select 3 } else { false };
_player = if (count _this > 3 ) then { _this select 4 } else { false };

switch (_status) do {
case 0: { _task setTaskState "Failed" };
case 1: { _task setTaskState "Succeeded" };
case 2: { _task setTaskState "Canceled" };
case 3: { _task setTaskState "Created" };
case 4: { _task setTaskState "Assigned" };
};

hint _hint;

if (typeName _next_task == "TASK") then {
diag_log format["PARAM 3: %1", typeName _next_task];
if (typeName _player == "OBJECT") then {
	_player setCurrentTask _next_task;
}
}

I might just swap the _status to be the String variable needed and that would get rid of the switch statement.

This means that I can use updateTask independently of all other scripts or as I have in objectiveGather.sqf, call if from any other script that requires a task update.

Edited by publicfunction
Update

Share this post


Link to post
Share on other sites

Does not seem to be the case Shuko, its as if when the addAction command is initiated it caches everything up and then when the action is used this cached call back happens.

You can try it quite easily. In the editor place the player with

player addAction ["hint Task", {hint format["%1", (_this select 3) select 0];}, [objTaskOne]];
objTaskOne = player createSimpleTask ["Recover the Intel."]; 

in the init box.

On using the action ANY will be displayed as the hint.

Turn the two commands around

objTaskOne = player createSimpleTask ["Recover the Intel."]; 
player addAction ["hint Task", {hint format["%1", (_this select 3) select 0];}, [objTaskOne]];

and everything works fine.

_____________________

This is a handy list to keep in mind, from the WIKI under functions library

Initialization Order

When mission is starting, its components are initialized in the following order:

  1. Functions with recompile param set to 1 are recompiled
  2. Functions with preInit param set to 1 are called
  3. Object Init Event Handlers are called
  4. Object initialization fields are called
  5. init.sqs is executed in singleplayer
  6. init.sqf is executed in singleplayer
  7. Persistent multiplayer functions are called (client only)
  8. Modules are initialized
  9. initServer.sqf is executed (server only)
  10. initPlayerLocal.sqf is executed
  11. initPlayerServer.sqf is executed (server only)
  12. Functions with postInit param set to 1 are called
  13. BIS_fnc_init" variable is set to true
  14. init.sqs is executed in multiplayer
  15. init.sqf is executed in multiplayer

Edited by Larrow

Share this post


Link to post
Share on other sites
[_task, _status, "You have the Objecive, Now get out off there!", objTaskTwo, player] call updateTask;

Earlier you were after reusable and not hardcoded solution, and now you got the script hardcoded with objTaskTwo. ;)

Share this post


Link to post
Share on other sites
I have updated it since the last posting. so being so nit picky

Are you talking about your updateTask thing? Which is basically a duplication of both commands and functions that already exist for that exact same thing?

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  

×