DarkViper98 1 Posted April 9, 2020 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
opusfmspol 282 Posted April 9, 2020 [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
DarkViper98 1 Posted April 9, 2020 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
opusfmspol 282 Posted April 9, 2020 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
DarkViper98 1 Posted April 9, 2020 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