Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   Future Improvements (https://forums.graalonline.com/forums/forumdisplay.php?f=10)
-   -   default class (https://forums.graalonline.com/forums/showthread.php?t=85565)

DustyPorViva 05-14-2009 04:30 AM

default class
 
I've heard it suggested before to release the default stuff to servers so they can edit it... but I'm not sure if we'll ever see that.

So what I suggest is a class called default that is created with the server. All functions created in this class are ran BEFORE the default functions. This way, we can overwrite default functions ourselves, to maybe make custom systems more backwards compatible.

For example, if I make the function:

function say2(txt) {
player.chat = txt;
}

in the default class, all say2 functions will instead set the player's chat to the text rather than open a sign. I'm not sure how possible this is, or what kind of security risks there are, but just thought I'd see what others thought.

Skyld 05-14-2009 12:52 PM

This sorta makes everything complicated, because then scripters have to learn to expect different functionality for what should be "built-in functions" across different servers. It is also probably way too easy to break a lot of existing code very quickly also by making a mistake in such a class. Built-in functions should be kept the way they are.

Inverness 05-14-2009 02:30 PM

Quote:

Originally Posted by Skyld (Post 1491438)
This sorta makes everything complicated, because then scripters have to learn to expect different functionality for what should be "built-in functions" across different servers.

Which is not a problem if they're documented well, as they should be.
Quote:

Originally Posted by Skyld (Post 1491438)
It is also probably way too easy to break a lot of existing code very quickly also by making a mistake in such a class.

You don't get anywhere without taking risks.

I'm against it simply because of the way GScript is. In a fully object oriented situation, you'd have something like:
PHP Code:

// C# pseudocode
public class TValServerNPCTServerNPC {
  public 
override void ToWeapons() {
    throw new 
NotImplementedException("LOL NOPE");
  }


And then have all your scripted stuff subclass TValServerNPC.

Something similar would just be odd with how GS2 is now.

Loriel 05-14-2009 03:14 PM

I do not really see what you are gaining there. It is not like C where you want to override standard library functions used by other libraries, you could just always go and edit scripts to call mySay2() which will do whatever you want anyway. :\

There is probably going to be a performance cost here that does not seem worth the gain.

Admins 05-14-2009 05:53 PM

Such a global class is partially a problem because of how function pointers are working. Such a global class could become quite large, seeing the size of some Control-NPCs. In my opinion it's better if the object is joining the needed classes at the beginning or end of the script so that you can easily see where functions are borrowed from. This is of course some problem when using existing levels where you would have to patch each single npc to use the new function.

Crow 05-14-2009 06:37 PM

Quote:

Originally Posted by Stefan (Post 1491464)
This is of course some problem when using existing levels where you would have to patch each single npc to use the new function.

Can just write a script which runs over these levels and corrects whatever has to be corrected.

Inverness 05-15-2009 01:45 AM

Quote:

Originally Posted by Crow (Post 1491470)
Can just write a script which runs over these levels and corrects whatever has to be corrected.

In that case you can write a script to replace all instance of say2() with your own function.


All times are GMT +2. The time now is 11:20 AM.

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