Author Topic: calling parent twice?  (Read 1069 times)

i've seen it numerous times, but only today just realized it was calling the parent twice:
Code: [Select]
package blah
{
function derp()
{
%parent = parent::derp();
//code here
return %parent;
}
};
activatepackage(blah);

seriously - why would you call the parent twice? i don't get it. what purpose would this serve?
« Last Edit: August 23, 2012, 04:27:55 PM by Lugnut »

i've seen it numerous times, but only today just realized it was calling the parent twice:
Code: [Select]
package blah
{
function derp()
{
%parent = parent::derp();
//code here
return %parent;
}
};
activatepackage(blah);

seriously - why would you call the parent twice? i don't get it. what purpose would this serve?
He doesn't call it twice
he calls the parent and sets %parent to what the parent returned
Then returns %parent

YOu need to do this is you want to call the parent first and the function returns something

Mold is right up til the end. You do this when you want to call the parent before your code but it's crucial for the parent to return something

Mold is right up til the end. You do this when you want to call the parent before your code but it's crucial for the parent to return something
that's basically what he said

He was unclear when he said "and the function returns something"

What does it do if you use parents out of a package?

I have never really tried it.

Yeah, to give a good example that I actually forgeted up with earlier, GameConnection::autoAdminCheck.

This is a good function to package for when the client joins, I use it all the time. But if your code depends on if they're admin or not, you need to have it go through it's normal code first to make them admin. But, the function needs to return something. So you set the return of the parent to a variable and return the variable.

Another example is fxDTSBrick::Plant. It returns an error # for if it can plant or not. You need to return this number or it'll break everything. But, if your code depends on whether or not the brick was planted, you need to access this so you can't stick it at the end. Set it to a variable, return the variable later.

What does it do if you use parents out of a package?

I have never really tried it.
Nothing. It just won't work, or it'll syntax error.
Not true.

For example, calling Parent::onFire inside GunImage::onFire outside of a package will call WeaponImage::onFire

However, the parent class needs to exist and have that function otherwise it'll complain about the function not being found. If it's not a class-based function such as serverCmdLight, then calling parent will just say there's no function.
« Last Edit: August 24, 2012, 12:29:27 AM by TripNick »

Yeah, to give a good example that I actually forgeted up with earlier, GameConnection::autoAdminCheck.

This is a good function to package for when the client joins, I use it all the time. But if your code depends on if they're admin or not, you need to have it go through it's normal code first to make them admin. But, the function needs to return something. So you set the return of the parent to a variable and return the variable.
Or you make your own admin check

oh duh - it calls the parent once and defines a variable with the result, but after that you have to return the result - not calling the parent again

silly me

Or you make your own admin check
Why would you do that?

Why would you do that?

To earn more respect in the streets dog.

Why would you do that?
I don't think theres a reason that actually makes sense
maybe if you want to have more than 2 admin levels for no reason

I don't think theres a reason that actually makes sense
maybe if you want to have more than 2 admin levels for no reason
no, you can still use the default one for that...


Code: [Select]
function vectorScale(%v,%s)
{
    return getWord(%v,0) * %s SPC getWord(%v,1) * %s SPC getWord(%v,2) * % s;
}
Hey guys check it out I made my own vectorScale function! Look how useful it is!

There's a lot of things that you can rewrite in torque, but there's absolutely no use in doing so.

Nothing. It just won't work, or it'll syntax error.
Not true.

For example, calling Parent::onFire inside GunImage::onFire outside of a package will call WeaponImage::onFire

However, the parent class needs to exist and have that function otherwise it'll complain about the function not being found. If it's not a class-based function such as serverCmdLight, then calling parent will just say there's no function.