Rebitaay 13 Posted May 18, 2017 Hi all, need some help here, I'm stumped. I've got a (weighted) random number being used as a sort of cooldown in a mission I'm making. For some reason, it returns "any" in the specific script, but the same code works fine in the debug console. _timer = floor random [15,60,120]; // Cooldown timer _plane = createVehicle [_getPlane, _spawnCoords, [], 0, "FLY"]; // Create enemy plane _plane addEventHandler ["killed", {sleep _timer; execVM "Scripts\SpawnHostiles.sqf"}]; // When that plane is killed, start the cooldown and then spawn another When the enemy plane is destroyed, another one instantly spawns. I discovered that _timer is returning "any", but I'm not sure why. Any help is greatly appreciated! Share this post Link to post Share on other sites
R3vo 2654 Posted May 18, 2017 You cannot use a private variable inside a event handler which was defined outside of the eh's scope. missionNamespace setVariable ["rebitaay_timer",floor random [15,60,120],true]; _plane = createVehicle [_getPlane, _spawnCoords, [], 0, "FLY"]; // Create enemy plane _plane addEventHandler [ "killed", { _timer = missionNamespace getVariable ["rebitaay_timer",60]; sleep _timer; execVM "Scripts\SpawnHostiles.sqf" } ]; // When that plane is killed, start the cooldown and then spawn another That should work. 1 Share this post Link to post Share on other sites
Lucullus 71 Posted May 18, 2017 _plane = createVehicle [_getPlane, _spawnCoords, [], 0, "FLY"]; // Create enemy plane _plane addEventHandler ["killed", {sleep (floor random [15,60,120]); execVM "Scripts\SpawnHostiles.sqf"}]; _timer not defined in EH too late 1 Share this post Link to post Share on other sites
Grumpy Old Man 3549 Posted May 18, 2017 Sleeping inside an eventHandler isn't possible unless using spawn. Cheers 2 Share this post Link to post Share on other sites
Rebitaay 13 Posted May 18, 2017 26 minutes ago, R3vo said: You cannot use a private variable inside a event handler which was defined outside of the eh's scope. 11 minutes ago, Grumpy Old Man said: Sleeping inside an eventHandler isn't possible unless using spawn. Thank you both, I got it working now. This is what I came up with based on you two's advice: _plane = createVehicle [_getPlane, _spawnCoords, [], 0, "FLY"]; _plane addEventHandler [ "killed", { [] spawn { _timer = floor random [15,60,120]; sleep _timer; execVM "Scripts\SpawnHostiles.sqf"; }; } ]; 25 minutes ago, Lucullus said: _timer not defined in EH too late Thanks anyways :P Share this post Link to post Share on other sites