Jump to content
Sign in to follow this  
DarkViper98

help please with a custom function <3

Recommended Posts

Hello, everyone!

Got some problems with creating a function. So, the idea is to add little dialogue for the units i need when player comes close to them.

So, i am defining a function in my init.sqf:

function_talking = compile preprocessFile "Talking.sqf";

This code inside Talking.sqf:

private ["_unit"];
_unit = _this select 0;

waitUntil {sleep 0.5; player distance _unit < 5};

["SOLDIER", "Want my nuts?"] spawn BIS_fnc_showSubtitle;
sleep 2;
["PLAYER", "No thanks!"] spawn BIS_fnc_showSubtitle;

And this what i put in soldier's initialization field:

[this] call function_talking;

And nothing works xD what i did wrong? Having no errors it .rpt

 

Thank you for helping!

Share this post


Link to post
Share on other sites
[this] call function_talking;

Try replacing with:

nul = this spawn {waitUntil {!isNil "function_talking"}; [_this] call function_talking;};

 

Share this post


Link to post
Share on other sites
51 minutes ago, opusfmspol said:

[this] call function_talking;

Try replacing with:


nul = this spawn {waitUntil {!isNil "function_talking"}; [_this] call function_talking;};

 

thank you! Worked xD. So the problem was, because the function was called before it was even ready to be executed???

Share this post


Link to post
Share on other sites

Maybe.  The nul= and spawn are also important.  Object initialization fields run in unscheduled environment where suspension (sleep, waitUntil) is not allowed.  The function being called contained sleep and waitUntil, so it needed to be spawned, not called.  Spawn opens a new thread in scheduled environment where suspension is allowed.  The nul= catches the handle returned from the spawn, just in case the editor field requires nothing gets returned from the initialization itself.

Share this post


Link to post
Share on other sites
1 hour ago, opusfmspol said:

Maybe.  The nul= and spawn are also important.  Object initialization fields run in unscheduled environment where suspension (sleep, waitUntil) is not allowed.  The function being called contained sleep and waitUntil, so it needed to be spawned, not called.  Spawn opens a new thread in scheduled environment where suspension is allowed.  The nul= catches the handle returned from the spawn, just in case the editor field requires nothing gets returned from the initialization itself.

Alright, big thanks for help!

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  

×