Jump to content
Rebitaay

Why is my random number returning "any"?

Recommended Posts

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

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.

  • Like 1

Share this post


Link to post
Share on other sites
_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

  • Like 1

Share this post


Link to post
Share on other sites
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

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×