Jump to content

Recommended Posts

Hello, 

 

I'm trying to get the side of AI using "side _this" but i'm only getting an error.

On respawn i execVM a file with the expectations of get the side of the AI and then execVM another file depending on side.

 

if (side _this == west) then {_this execVM "unitMoveWest.sqf"};

Why is not working?

 

Thanks!

Share this post


Link to post
Share on other sites

"_this" is supposed to be the current unit, i used to execVM and doMove, etc and works.

How i can reffer to the unit AI then?

Share this post


Link to post
Share on other sites
15 minutes ago, SnowmaneYT said:

"_this" is supposed to be

 

But maybe it isn't. So, how are you defining it? Show your code, we can't see your screen from here.

Share this post


Link to post
Share on other sites

init.sqf

 

{_respawns = _x addMPEventHandler ["MPRespawn", {
    _moveLoop = _this execVM "unitMove.sqf";
    }];
} foreach allUnits;

unitMove.sqf (here is caused the "_this" error

 

if (side _this == west) then {_this execVM "unitMoveWest.sqf"};
if (side _this == east) then {_this execVM "unitMoveEast.sqf"};
if (side _this == independent) then {_this execVM "unitMoveIndi.sqf"};

 

Share this post


Link to post
Share on other sites

https://community.bistudio.com/wiki/Arma_3:_Event_Handlers#MPRespawn

 

Default:

this addMPEventHandler ["MPRespawn", {
	params ["_unit", "_corpse"];
}];

 

We can see that when adding the EH, the new unit would be referred to as _this select 0 or _this#0, or by the built-in param _unit. So let's do!

 

{_respawns = _x addMPEventHandler ["MPRespawn", {
	params ["_unit", "_corpse"];
	_moveLoop = _unit execVM "unitMove.sqf";
	}];
} foreach allUnits;

 

Now unitMove.sqf  should work, but it's always a good idea to define variables/params at the top:

 

params ["_this"];

if (side _this == west) then {_this execVM "unitMoveWest.sqf"};
if (side _this == east) then {_this execVM "unitMoveEast.sqf"};
if (side _this == independent) then {_this execVM "unitMoveIndi.sqf"};

 

I would change "_this" to "_unit" for a bit more clarity, but that's personal preference.

 

params ["_unit"];

if (side _unit == west) then {_units execVM "unitMoveWest.sqf"};
if (side _unit == east) then {_unit execVM "unitMoveEast.sqf"};
if (side _unit == independent) then {_unit execVM "unitMoveIndi.sqf"};

 

  • Like 2
  • Thanks 1

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

×