Dear forum users! In compliance with the new European GDPR regulations, we'd just like to inform you that if you have an account, your email address is stored in our database. We do not share your information with third parties, and your email address and password are encrypted for security reasons.

New to the forum? Say hello in this topic! Also make sure to read the rules.

Script error when gibbing/removing dead corpses

Here you can find all solved gameplay problems and bugs (beginning from Pre-Alpha 1.8.8).
Forum rules
By using the forum you agree to the following rules. For this forum you also need to follow these additional rules.
Locked
User avatar
Gunter
Fighter
Fighter
Posts: 11
Joined: Fri Mar 25, 2016 2:27 am
Title: Title?
SFD Alias: Gunter
Started SFD: i think july/2015
Location: Behind you *-*
Gender:
Age: 19
Contact:

Script error when gibbing/removing dead corpses

Post by Gunter » Wed Feb 05, 2020 1:33 am

Trying to call Remove() or Gib() inside a PlayerDeathCallback listener throws an exception

Code: Select all

//Throws script exception and corpse gets removed on first try only
public void OnStartup() {
	Events.PlayerDeathCallback.Start((deadPlayer) => {
		if (deadPlayer != null ) deadPlayer.Gib();
	});
}
this is the throw exception

Code: Select all

--- Exception ---
Object reference not set to an instance of an object.
   at ScriptEngine.Sandbox.ExecuteInstanceMethodInScript.Run(Boolean debuggingScript, Action callback, MethodInfo methodInfo, Object classInstanceObject, Object[] parameters)
   at SFD.GameWorld.RunScriptCallbacks[T](Func`2 handleCallback)
template map for testing

Also, I made some extra tests to check a few things, hope it helps

Code: Select all

//Gives script exception on first try but corpses are getting removed correctly
public void OnStartup() {
	Events.PlayerDeathCallback.Start((deadPlayer) =>
		Events.UpdateCallback.Start((t) => { 
			if (deadPlayer != null) deadPlayer.Gib(); }, 100, 1)
	);
}

//This approach works
public void OnStartup() {
	Events.PlayerDeathCallback.Start((deadPlayer) => {
		if (deadPlayer != null)
			deadPlayer.SetWorldPosition(new Vector2(0, Game.GetWorldBottom()));
	});
}
1 x
Hours
Minutes
Seconds
01010011 01110100 01101111 01110000 00100000 01110111 01100001 01110011 01110100 01101001 01101110 01100111 00100000 01111001 01101111 01110101 00100000 01110100 01101001 01101101 01100101

User avatar
Gurt
Lead Programmer
Lead Programmer
Posts: 1884
Joined: Sun Feb 28, 2016 3:22 pm
Title: Lead programmer
Started SFD: Made it!
Location: Sweden
Gender:
Age: 31

Post by Gurt » Wed Feb 05, 2020 8:07 pm

Fixed after v.1.3.3.
Thanks for reaching out.
This is actually the same problem as: https://www.mythologicinteractiveforums ... =20&t=3900 which is scheduled for the next update which we will release soon!

Core problematic is that callbacks within callbacks just didn't work. Imagine that you in your PlayerDeathCallback create a player and then also kill it, this will trigger the PlayerDeathCallback recursively. IPlayer.Gib() removes a player which also triggers the PlayerDeathCallback... This will work as intended in the next version allowing the below code to work as expected:

Events.PlayerDeathCallback.Start((deadOrRemovedPlayer) => {
if (!deadOrRemovedPlayer.IsRemoved) {
deadOrRemovedPlayer.Gib();
}
});
0 x
Gurt

Locked