Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   Future Improvements (https://forums.graalonline.com/forums/forumdisplay.php?f=10)
-   -   Global Functions (https://forums.graalonline.com/forums/showthread.php?t=76774)

Inverness 09-14-2007 12:10 AM

Global Functions
 
Why haven't they been implemented yet? We even have function objects now but no global functions yet, its not that hard to do I'm sure. Don't like using classes for things that should be global anyways.

Skyld 09-14-2007 12:34 AM

I am not sure how you magically expect global functions to work internally in the script engine.

Just use classes. :/ They aren't that inconvenient.

Inverness 09-14-2007 01:09 AM

Quote:

Originally Posted by Skyld (Post 1347611)
I am not sure how you magically expect global functions to work internally in the script engine.

We have dynamic global variables and objects, why not functions? I doubt it would take that much of an adjustment. Just make the function lookup look at something else between the local functions and the globals. Perhaps the Control-NPC? I had originally thought functions in there should be global by default but was rather disappointed.
Quote:

Originally Posted by Skyld (Post 1347611)
Just use classes. :/ They aren't that inconvenient.

Class functions show up in getVarNames() and getFunctions(), icky. Global functions are just easier since you don't need to remember what class the thing is in or maintain classes so they match up to a system as you update it.

Admins 09-14-2007 10:18 AM

Global functions are techincally possible, but they make programming actually much harder. It is making it even harder to find where the function is declared. We already have global variables, and we should not repeat that mess with global functions. It is much cleaner to put the functions in an npc and call NPCName.function(), or put it in a class.

Inverness 09-14-2007 04:13 PM

Quote:

Originally Posted by Stefan (Post 1347665)
Global functions are techincally possible, but they make programming actually much harder. It is making it even harder to find where the function is declared. We already have global variables, and we should not repeat that mess with global functions. It is much cleaner to put the functions in an npc and call NPCName.function(), or put it in a class.

I suggested only functions in Control-NPC would be only ones qualifying as global, it would not be difficult at all to find out where they're declared if that is the case.
PHP Code:

// Script
function onCreated() {
  
addItem("sword"1);
}
// Control-NPC
public function addItem(archcount) {
  
player.mud.addItem(archcount);


Simple enough.

I'm not suggesting global functions be declared the same way that global variables are (since that would be a horror as you're saying), just that when the Control-NPC is compiled its functions added to the global list or something.

So basically, for the function lookup, if there is no prefix it would look at:
Local Object (this.) -> Control-NPC -> Static Globals.

Chompy 09-14-2007 04:38 PM

could be nice

Admins 09-14-2007 10:32 PM

Why not simply use MyFunctionsNPC.function() ?

Chompy 09-14-2007 10:40 PM

Quote:

Originally Posted by Stefan (Post 1347759)
Why not simply use MyFunctionsNPC.function() ?

Scripter's are lazy, and classes is just a hazzle when there's alot of them

It could be nice with global functions that would make it so you couldn't make more functions with the same name, for example when you make another onCreated() event or make two functions with the same name, it will cause an error

PHP Code:

Mud.additem("sword"1);
additem("sword"1);
player.mud.additem("sword"1);
Mud_Object_Player_Chompy.additem("sword"1); 

etc.. in the end you get confused, but that was kinda a bad example, but if you could create global function it would help for example the main systems of the server, for example the mudlib that servers lately are interested in.

Inverness 09-14-2007 11:00 PM

Quote:

Originally Posted by Stefan (Post 1347759)
Why not simply use MyFunctionsNPC.function() ?

Yes it works and I do use it in the cases where I need to, but its not preferred when you have lots of different groups of functions in different weapons/objects or classes. And it just looks bad next to the globals that Graal has :(

For the classes, rather than having to join small utility classes to everything that uses it you can just join it to the Control-NPC and then everything can use it, including the random LAT with little knowledge of scripting.

Having globals puts everything on the same plate and would make it easier for people unfamiliar with the system. I don't think its asking much to make public functions in the Control-NPC global (and those with a global_ prefix in the function name only?). Since they would only work in the Control-NPC it would the massive chaos of someone not knowing where the global function is declared.

Inverness 09-22-2007 01:19 PM

Bump

I would appreciate a response.

Admins 09-22-2007 06:17 PM

Still seeing it as bad coding style.

Inverness 09-22-2007 10:41 PM

Quote:

Originally Posted by Stefan (Post 1349161)
Still seeing it as bad coding style.

The negatives you stated in first post are invalidated by using the Control-NPC for global functions only.

I don't see how its bad coding style to have a single additional location in the function-lookup process.

Local Object -> Control-NPC -> Static Globals

There is nothing confusing about that. It puts all the globals in one bag so you can't miss them.

Kyranki 09-24-2007 02:44 AM

I mean, they would only be placed in the Control Npc so that it won't be a hard to find the functions when necessary.

I completely agree with this as it would be a nice addition to servers period

coreys 09-24-2007 04:26 AM

I don't think Stefan should honestly have to go through that just to save yourself from having to join a class or putting a weapon name in front of the function. (i.e. "FunctionsWeapon".doThingy())

Skyld 09-24-2007 09:17 AM

Quote:

Originally Posted by Kyranki (Post 1349362)
I mean, they would only be placed in the Control Npc so that it won't be a hard to find the functions when necessary.

I completely agree with this as it would be a nice addition to servers period

There's no point. It takes almost no effort to type (@ "Control-NPC").functionname(); or this.join("classname");, and adding things like this just promotes laziness and makes things more complicated. :/


All times are GMT +2. The time now is 03:27 PM.

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