EventPlayer != (EventPlayer) EventPlayer.CurrentPlayer returns false and true

I’m currently getting users spawning some spheres on the map with the position of those spheres stored in a player variable, I am then looping through all living players successfully and getting there stored spheres which I then check if the player is within x distance of a sphere.

during this check

if(Event Player.BallCollisionCurrentPlayer == EventPlayer)

this sometimes returns true but still proceeds to run the code in the else statement

variables
{
player:
	3: ArrayOfPositions
	4: BallCollisionPlayerIndex
	5: BallCollisionCurrentPlayer
	6: BallCollisionSphereIndex
	7: BallCollisionCurrentSphere
	8: TargetsSphereArray
}

subroutines
{
0: CheckCollisionWithBall
}

rule("CheckCollision")
{
event
{
	Subroutine;
	CheckCollisionWithBall;
}

actions
{
	For Player Variable(Event Player, BallCollisionPlayerIndex, 0, Count Of(All Living Players(All Teams)), 1);
		Event Player.BallCollisionCurrentPlayer = All Players(All Teams)[Event Player.BallCollisionPlayerIndex];
		If(Event Player.BallCollisionCurrentPlayer == Event Player);
			Big Message(All Players(All Teams), Custom String("This **** Sucks"));
			Continue;
		Else;
			Event Player.TargetsSphereArray = Event Player.BallCollisionCurrentPlayer.ArrayOfPositions;
			For Player Variable(Event Player, BallCollisionSphereIndex, 0, Count Of(Event Player.TargetsSphereArray), 1);
				Wait(1, Ignore Condition);
				disabled Event Player.BallCollisionCurrentSphere = Event Player.BallCollisionCurrentPlayer.ArrayOfPositions[Event Player.BallCollisionSphereIndex];
				Event Player.BallCollisionCurrentSphere = Event Player.TargetsSphereArray[Event Player.BallCollisionSphereIndex];
				If(Distance Between(Position Of(Event Player), Position Of(Event Player.BallCollisionCurrentSphere)) < 1);
					Big Message(Event Player, Custom String("You: {0} Killer: {1} Equal: {2}", Event Player, Event Player.BallCollisionCurrentPlayer,
						Event Player == Event Player.BallCollisionCurrentPlayer));
					Kill(Event Player, Null);
				End;
			End;
		End;
	End;
}
}

You should better use a custom array containing all players than the “All Players(All Teams)” array, since you don’t have any control over the order of the players in the “All Players” value. The order might change, when the array is recalculated.
In a custom array you would have the full control over the order, so you can exclude “nondeterministic” behaviour here.
To get only the living players, just filter your custom all players array.

Once you’ve done this we can look into it again for further debugging.

Notice, that a logical expression is deterministic, meaning it always evaluates to the same true/false value, if the expression doesn’t change.

Okay so I tried storing all Living players in an array before doing any checks but I still end up with the same results

variables
{
player:
	3: ArrayOfPositions
	4: BallCollisionPlayerIndex
	5: BallCollisionCurrentPlayer
	6: BallCollisionSphereIndex
	7: BallCollisionCurrentSphere
	8: TargetsSphereArray
	25: AllPlayers
}

subroutines
{
0: CheckCollisionWithBall
}

rule("CheckCollision")
{
event
{
	Subroutine;
	CheckCollisionWithBall;
}

actions
{
	Event Player.AllPlayers = All Living Players(All Teams);
	For Player Variable(Event Player, BallCollisionPlayerIndex, 0, Count Of(Event Player.AllPlayers), 1);
		Event Player.BallCollisionCurrentPlayer = Event Player.AllPlayers[Event Player.BallCollisionPlayerIndex];
		If(Event Player.BallCollisionCurrentPlayer == Event Player);
			Big Message(All Players(All Teams), Custom String("This **** Sucks"));
			Continue;
		Else;
			Event Player.TargetsSphereArray = Event Player.BallCollisionCurrentPlayer.ArrayOfPositions;
			For Player Variable(Event Player, BallCollisionSphereIndex, 0, Count Of(Event Player.TargetsSphereArray), 1);
				Wait(1, Ignore Condition);
				disabled Event Player.BallCollisionCurrentSphere = Event Player.BallCollisionCurrentPlayer.ArrayOfPositions[Event Player.BallCollisionSphereIndex];
				Event Player.BallCollisionCurrentSphere = Event Player.TargetsSphereArray[Event Player.BallCollisionSphereIndex];
				If(Distance Between(Position Of(Event Player), Position Of(Event Player.BallCollisionCurrentSphere)) < 1);
					Big Message(Event Player, Custom String("You: {0} Killer: {1} Equal: {2}", Event Player, Event Player.BallCollisionCurrentPlayer,
						Event Player == Event Player.BallCollisionCurrentPlayer));
					Kill(Event Player, Null);
				End;
			End;
		End;
	End;
}
}

So far, this is the only bug I see in your code.
Event Player.BallCollisionCurrentSphere is a vector if Im right and Position Of() expects a player entity, so it will return 0 or something. Just remove the Position Of() here.

You could do some debug outputs (or watch the inspector step by step) to spot the situation where you get wrong values.

1 Like