![]() |
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.
|
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. |
Quote:
Quote:
|
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.
|
Quote:
PHP Code:
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. |
could be nice
|
Why not simply use MyFunctionsNPC.function() ?
|
Quote:
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:
|
Quote:
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. |
Bump
I would appreciate a response. |
Still seeing it as bad coding style.
|
Quote:
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. |
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 |
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())
|
Quote:
|
Quote:
Having global functions would make it easier on those who are unfamiliar with the system. Its called encapsulation and I try to practice it in just about everything I do. I'd love to be able to reorganize how something works and still have other scripts on the server work correctly because of the global functions. That is why GS1 still works, yes? And please explain how it makes things more complicated, I can't see anything complicated with adding another space to the function lookup. It seems like you're worrying about how badly newbie scripters can **** it up instead of focusing on the good and thats irritating. Having global functions easily accessible to novice scripters would just make things easier. So far I've seen bad reasons as to why a simple new feature shouldn't be added to gscript. Graal has a crapload of global functions and I suppose thats just too much for us mortal scripters to handle. |
Quote:
|
Quote:
|
Quote:
Request actual features...not just solutions for pure lazyness. Also, don't go running around calling it 'encapsulation'. Encapsulation is like the process of encapsulating a udp/tcp header/data into an ip packet. For gscript, encapsulation would be more like taking a piece of data and adding it to a self-sufficient container...which undermines the point of 'global functions'. Funilly enough, this could be more readily achieved with classes. When requesting something, try explaining what it will achieve and how the current system can't easily achieve the same effect :whatever: |
You know, I plan to go into game development/programming in my future and Graal is about the best amateur platform there is, however it makes it really hard to practice OOP principles sometimes.
Quote:
Quote:
Quote:
Encapsulation means people should be able to use my or anyone else's scripts without knowing how they work, this is the reason I want catchEvent() to work with dynamic function events. Classes add their functions to the local object, something I don't want, or else I would simply put all the functions I consider "global" and join it to everything, however that would screw up the getfunctions() and such. So instead I divide it up between classes and it becomes disorganized for simple functions such as putnpc3() that don't really fit in a category (and if that happens I just drop it because there is no simple way to make it available everywhere), it also makes it harder on new scripters to the server. I'd rather not be the sole scripter on the server that constructs the main system and if I want my systems to work with others well, encapsulation should be practiced. Quote:
Also I like sharing alot of the things I make and global functions would allow something to interface with scripts on another server easily. Its like standardization, many servers have different ways of organizing their scripts that are good or bad and having custom globals allows different things to work together easier by providing a common space for them to interact. Its irritating really, I ask for a simple single addition to the function look up and nobody can actually give a good reason why it shouldn't be included and actually explain it at the same time. |
Quote:
PHP Code:
Unless Stefan implements protected variables sometime soon (something I actually suggested a while ago), this isn't possible in gscript and global functions don't fall under the encapsulation umbrella. Encapsulation isn't referring to protecting your code from other coders :whatever:. You could achieve the same effect by having a class with private functions and make sure only you can read the class. It's making sure you follow OOP rules and only allow the local class have access to it's variables. Nothing should ever need access to everything at any point. Classes can be nicely labeled ("mud_functions", "magic_functions"), and new scripters will be able to find what they are looking for alot easier than sifting through a massive Control-NPC script. This also means that an item object can't turn a player into a duck and plants don't spit out weapons. Global functions are just messy and lazy. And yes, I realize there are hard coded global functions. I was suggesting that you could happily follow the concept of inheritance using classes to achieve the same effect...alot more cleaner as well. |
Quote:
Quote:
Quote:
Quote:
Quote:
Quote:
Quote:
Edit: These are the functions I would make global on Val Dev: PHP Code:
If you look at the Wiki, you'd see over 100 global functions that GK has added just for itself, many of which point to functions in objects in the same manor that I would do myself, obviously its not so messy if GK does it. |
Quote:
Quote:
And you're right, gscript is not like other languages which makes it confusing when you bring up OOP programming concepts like, "encapsulation" and even quote them then try to relate it to different concepts :rolleyes:. Pretty sure the burden is on you to prove why these updates are necessary: not the other way around. |
Quote:
Quote:
Quote:
Quote:
Please tell me why GK is allowed to have global functions pointing to object functions yet we're not? When they're certainly possible dynamically as Stefan has said. I'm going to be honest and say absolutely nothing will convince me why Global functions shouldn't be allowed until this is explained. |
All times are GMT +2. The time now is 01:20 PM. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.