Jump to content

Recommended Posts

Hi.

 

I want to write a small function, spawning a soldier at a marker (just an understanding thing, I know it's way more easy to do this in a different way).

 

params
[
	["_class","",[""]],
	["_wp","",[""]]
];

_posStart = getMarkerPos _wp;

_grp01 = createGroup east;
_unit01 = _grp01 createUnit [_class, _posStart, [], 0, "CAN COLLIDE"];

It's working, when called with

 

_spawnUnit = ["O_G_Soldier_F","marker1"] call TACP_fnc_Test_spawnSoldier;

 

Given class is spawning at the marker. But I always got the failure message

"'call{_spawnUnit |#|= ["O_G_Soldier_F","marker1"] call TACP_fnc..." Error Generic error in expression."

 

What am I doing wrong?

 

*confused*

 

Share this post


Link to post
Share on other sites

The reason for this is that u r assigning a value to a variable but the function call returns no value. This is fixed with kks solution by adding a return value to Ur function.

Another solution would be to use spawn instead of call then the return value would be a script handle but not the created object.

sent from mobile using Tapatalk

Share this post


Link to post
Share on other sites

Argh. Thank you guys! Functions have to return a value. :yikes:

Sometimes it's all too obvious ... but my brain was script-fried.

 

 

Share this post


Link to post
Share on other sites
21 hours ago, tacplay said:

Argh. Thank you guys! Functions have to return a value. :yikes:

Sometimes it's all too obvious ... but my brain was script-fried.

 

 

 

I believe it's a good habit to always return some sort of value, for example a bool.

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

×