Author Topic: [Solved] onDeath()  (Read 1392 times)

I have been experimenting with the function GameConnection::onDeath() and I've noticed that, when I die and I have used this function, I can't click to respawn and the game window is frozen until I press F7 to respawn. I assume that when I'm using this function it overwrites the default function for onDeath. Also, I'm new to the Blockland API so this is probably a simple fix.
« Last Edit: October 12, 2015, 02:02:29 AM by Dr.Tyler O. »

sounds like you didn't parent it (call the old version)

try putting your edit in a package and parent the function at the beginning or end of your script (whichever makes more sense)

there should be plenty of examples for you to look at in other addons

Alright, could you think of any good examples of add-ons that I could look at?


function GameConnection::onDeath(%this,%obj,%killer,%type,%area)
{
   //code before we call original functionality

   %p = parent::onDeath(%this,%obj,%killer,%type,%area);

   //code after we call original functionality

   //return the value of the original function if applicable
   return %p;
}


function GameConnection::onDeath(%this,%obj,%killer,%type,%area)
{
   //code before we call original functionality

   %p = parent::onDeath(%this,%obj,%killer,%type,%area);

   //code after we call original functionality

   //return the value of the original function if applicable
   return %p;
}


First of all, thanks for the help Elm. However, I still get the same result when I execute this code:

Code: [Select]
function GameConnection::onDeath(%this, %obj, %killer, %type, %area){
%p = parent::onDeath(%this, %obj, %killer, %type, %area);

%this.deaths++;
messageAll("", "<color:00ffff>" @ %this.getSimpleName() @ "<color:ffffff> has died <color:00ffff>" @ %this.deaths @ "<color:ffffff> time(s).");

return %p;
}

I apologize if I'm just blatantly missing the point here.

onDeath doesn't return any values though so the return statement is not necessary. Also is that the entire code or is there also a package?

Also is that the entire code or is there also a package?
Dealing with onDeath, yes that is the entirety of the code excluding a few irrelevant serverCmds. There is no package.

Something else must be conflicting with it. Try running a Trace and posting the log here.

onDeath doesn't return any values though so the return statement is not necessary. Also is that the entire code or is there also a package?

It's still good practice to include it anyway, for obvious reasons.

I took a look in the console to find that this line:
Code: [Select]
%p = parent::onDeath(%this, %obj, %killer, %type, %area);echos "Unknown command onDeath"

However, if you still require a full Trace then just say so and I will post it.
« Last Edit: October 12, 2015, 01:23:06 AM by Dr.Tyler O. »

Put it in a package.

Package packageName
{
    //Function code here
};
activatePackage(packageName);


Lol wow, I assumed it was in a package already :|

Edit: http://tsforblockland.weebly.com/packages.html

You can click next to see some examples.


package and parent the function
the package lets you overwrite the code without throwing the old code away, as you can call it with parent

basically that's how you modify a function and retain the old function's characteristics