Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   Bug Report (https://forums.graalonline.com/forums/forumdisplay.php?f=193)
-   -   Object method declaration in joined classes. (https://forums.graalonline.com/forums/showthread.php?t=80392)

DrakilorP2P 07-06-2008 10:37 PM

Object method declaration in joined classes.
 
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:
PHP Code:

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:
PHP Code:

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


Output:
Quote:

secondFunctionCollision
function_1
secondFunctionCollision
function_1
I assume this is supposed to output:
Quote:

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 01:15 PM

I helped to debug this, somewhat, and I can confirm the error.

Admins 07-07-2008 11:27 PM

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 01: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 04:44 AM

I've encountered a similar issue.

PHP Code:

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)...
PHP Code:

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

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


I get this error message on RC instead:
PHP Code:

Script: Function unknown_object.funcTwo not found at line 71 in script of DEBUG (in level onlinestartlocal.nw at pos (30.530)) 


xXziroXx 08-10-2008 07: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 09:36 PM

I tried this:

PHP Code:

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-10-2008 11:57 PM

Quote:

Originally Posted by Chompy (Post 1413220)
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 12: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 02:01 PM

Quote:

Originally Posted by Stefan (Post 1413322)
Fixed the problem

Thank you! :)

Quote:

Originally Posted by Stefan (Post 1413322)
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 06: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 08:14 PM

Quote:

Originally Posted by Stefan (Post 1413667)
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


All times are GMT +2. The time now is 09:53 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.