Author Topic: Difference between returning a parent and calling then returning a parent?  (Read 685 times)

/title

I seem to get different results when I return a parent than when I call the parent then return. What is the difference?

You mean the difference between
Code: [Select]
%r = parent::thing;
return %r;
and
Code: [Select]
return parent::thing;?

What exact parent are you doing

You mean the difference between
Code: [Select]
%r = parent::thing;
return %r;
and
Code: [Select]
return parent::thing;?

What exact parent are you doing
I'm trying to update my flashlight energy script to work with Chrono's LoopHandler and I keep getting two different results when I try this:
Code: [Select]
Parent::serverCmdLight(%client);
return;

and

Code: [Select]
%p = Parent::serverCmdLight(%client);
return %p;

It's needed if you need to have the function happen before you do something in the code, but when the function also has something to return.

Server commands aren't really supposed to return anything.

Let's say you're trying to debug a crash, and you think it's a file being saved that causes it. It's a function that returns a status of the file saving, so you'll need to call the parent and return that result.

You need to echo something before the parent call as a marker. You need to echo something after it as a check that the game didn't crash at that point yet.

Code: [Select]
    function fileSavingFunction(%q)
    {
echo("before data saved to file");
%p = parent::fileSavingFunction(%q);

echo("if you hear this, it's not the file saving that is crashing the game!");

return %p;
    }

Return sends data outside of the function, to whatever function was calling it.
Returning the parent sends the parent data outside of the function.

For example, vectorAdd("1 1 1", "1 1 2"); would, if you replaced all variables with their values, look like this at the end:
return "2 2 3";

If you packaged vectorAdd, it's not going to be able to send that "2 2 3" unless you also return it's value.

Ah, that makes sense. Thanks for the help!