Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update fnc_taskPatrol func header #360

Merged
merged 4 commits into from
Jun 6, 2016

Conversation

Wired-Tiger
Copy link
Contributor

I noticed that an error is thrown from fnc_addWaypoint if the position and radius wasn't passed so they would not be optional.

Also, could someone explain to me the point of line 49: private _this += _this;
I've been trying to understand the point of it, but I've removed it and the function works the same with or without it from what I can tell. Is it left over code by chance?

@nicolasbadano
Copy link
Contributor

_this += _this creates a copy of the parameters array, so the final element can be deleted without afecting the original data. This is important because arrays are always passed as reference to functions.

@Wired-Tiger
Copy link
Contributor Author

@esteldunedain Thank you for the explanation. I think what is throwing me off is the scope of _this. I was thinking that _this was equal to [1,2,3,1,2,3,4] instead of [1,2,4] for every instance after that particular code block.... Looking over this I realized that sqf doesn't have a "+=" command for adding like other languages. Sorry about that.

@Killswitch00
Copy link
Contributor

Killswitch00 commented Jun 4, 2016

The position and radius parameters are optional and there is no need to change the function header for that reason. Changing the default radius from 100 to 50 in the example call could be useful for the understanding of the function.

@Wired-Tiger
Copy link
Contributor Author

I figured out where it is going wrong. If all that is passed to the function is the group then _this = [group]. Even though the params defines the other arguments they don't get passed into _this, and because of it CBA_fnc_addWaypoint throws an error, specifically:

`20:15:34 Error position: <addWaypoint [_position, _radius];

_wayp>
20:15:34 Error 0 elements provided, 3 expected
20:15:34 File x\cba\addons\ai\fnc_addWaypoint.sqf, line 20`

Now, when [group, position] are passed the same thing happens, but no error is thrown because CBA_fnc_addWaypoint defaults the radius to 0 so the group ends up standing in place.

Would it be best to leave the code the way it is and just change the func header as I proposed, or change the code to allow for only passing a group?

@Killswitch00
Copy link
Contributor

The function header represents how the function is supposed to (and AFAIK has, at some point in time) work(ed), so the way forward here is to fix the now broken function.

@Killswitch00 Killswitch00 added this to the 2.4.1 milestone Jun 6, 2016
@@ -47,6 +47,11 @@ _position = _position call CBA_fnc_getPos;
[_group] call CBA_fnc_clearWaypoints;

private _this =+ _this;
switch (count _this) do {
case 1 : {_this append [_position, _radius]};
case 2 : {_this pushback _radius};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pushBack (camelCase)

@Killswitch00 Killswitch00 merged commit 5498c7f into CBATeam:master Jun 6, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants