PDA

View Full Version : Object method declaration in joined classes.


DrakilorP2P
07-06-2008, 11:37 PM
I think this is the correct forum this time.
Following is a description of what I assume is a bug. I managed to rule out any human factor.

My stuff behaved like it was magic for a while until I succeeded in isolating the problem.

It seems like functions in a joined class isn't fully aware of what is happening in the real script. The following scripts creates two TStaticVars and assigns anonymous functions to them, one in a joined class-function and one native. The functions both end up with the same identifier, function_1, and whichever function was defined first is overwritten.

A DBNPC:
function onCreated()
{
join("some_class");
temp.foo = createNewTStaticVarFromAnotherClass();

temp.foo.forkFunctionCollision();
echo(temp.foo.forkFunctionCollision);

temp.bar = new TStaticVar();
temp.bar.secondFunctionCollision = function() {
echo("secondFunctionCollision");
};

temp.bar.secondFunctionCollision();
echo(temp.bar.secondFunctionCollision);
}

some_class:
function createNewTStaticVarFromAnotherClass()
{
temp.crux = new TStaticVar();
temp.crux.forkFunctionCollision = function() {
echo("forkFunctionCollision");
};

return temp.crux;
}

Output:
secondFunctionCollision
function_1
secondFunctionCollision
function_1

I assume this is supposed to output:
forkFunctionCollision
function_1
secondFunctionCollision
function_2


Oh, hello mister inappropriate censorship; I think I'll rename firstFunctionCollision() to something else.
That's word censor evasion 101 by the way.

xXziroXx
07-07-2008, 02:15 PM
I helped to debug this, somewhat, and I can confirm the error.

Admins
07-08-2008, 12:27 AM
It's correct that they are both function_1 because the numeration depends on the position of the function in the script, but it should of course call the good one, so I will need to check it.

xXziroXx
07-26-2008, 02:16 AM
*bump*

Would love to get this fixed, it's not nice forcing us to do hackish ways around it.

xXziroXx
07-26-2008, 05:44 AM
I've encountered a similar issue.


function onCreated()
{
funcOne();
}

public function funcOne()
{
temp.foo = new TStaticVar();
temp.foo.funcTwo = function() {
echo("bar");
};
temp.foo.funcTwo();
}

Echoes "bar" successfully.

However, if I want to trigger the function in this NPC on another object using with (obj)...

function onCreated()
{
// Replace 'obj' with one of the following:
// findPlayer("accountname")
// findNPC("npcname")
with (obj) funcOne();
}

public function funcOne()
{
temp.foo = new TStaticVar();
temp.foo.funcTwo = function() {
echo("bar");
};
temp.foo.funcTwo();
}

I get this error message on RC instead:
Script: Function unknown_object.funcTwo not found at line 71 in script of DEBUG (in level onlinestartlocal.nw at pos (30.5, 30))

xXziroXx
08-10-2008, 08:49 PM
Yeah, bump, etcetera. Also, look into the edit reason on my last post while you're at it please. :)

Chompy
08-10-2008, 10:36 PM
I tried this:


function onCreated()
{
// Replace 'obj' with one of the following:
// findPlayer("accountname")
// findNPC("npcname")
with(findplayer("Chompy")) funcOne();
}

public function funcOne()
{
temp.foo = new TStaticVar();
temp.foo.funcTwo = function() {
echo("bar");
};
temp.foo.funcTwo();
}


worked fine for me? o.o

xXziroXx
08-11-2008, 12:57 AM
worked fine for me? o.o

That's odd, try with a NPC? Also, the main concern in this thread is the first issue posted by Drakilor.

Admins
08-11-2008, 01:04 PM
Fixed the problem by also adding the script id to the function name. A side effect is that when you update the class script then the original function object is not linking to the new function and is displaying an error, previously it was probably calling a function of the new script which might not be the same.
The fix will be in the next npcserver update, not sure when that will be because it will also require gserver restart.

xXziroXx
08-11-2008, 03:01 PM
Fixed the problem

Thank you! :)

The fix will be in the next npcserver update, not sure when that will be because it will also require gserver restart.

I'm not entirely sure how those thing work, but I don't suppose you could do it manually for Mythic Legends as soon as possible? We've been forced to make hackish workarounds for the bug for ages now ^^

Admins
08-12-2008, 07:20 PM
There was a problem with the npcserver on Mythic Legends today (taking a lot of memory), so I've taken the chance to restart all hosted and private playerworlds today.

xXziroXx
08-12-2008, 09:14 PM
There was a problem with the npcserver on Mythic Legends today (taking a lot of memory), so I've taken the chance to restart all hosted and private playerworlds today.

Hahaha.... yeeeaaah, that was a script I was playing with that ended up crashing the server. :cool:

Anyways, that means the error we posted about isn't an error anymore? :D