Scripting vs "Scripting" #184
Replies: 3 comments 14 replies
-
Off: I was going to suggest allowing NPCs made in JavaScript for
I suppose we would need to dynamically resolve namespace Imports? Or how would it work? In your snippet, there are no imports but multiple classes are being used.
I would prefer having Plugins being pre-compiled. Since their complexity is way bigger than possibly of a simple NPC... Imagine if we chose a route of all features being Plugin-based as we discussed before... That would create a bigger load during the runtime of the Emulator. There's yet another big caveat of doing JIT with C#, users would need to install .NET SDK instead of just having .NET-RE (.NET Runtime)
I definitely would love to Sandbox the scripts. Users might just download a "NiceBeautifulMarketLady.cs" and it actually formats the computer or installs Malware. That's why I would prefer not to allow the CS script to load namespaces, and have direct Class calls, and during the Bootstrap we inject/import the classes that should actually be available. It is important to mention (IMHO) that there are several routes of reading the CS Plugin/NPCs code:
My conclusion: I'd love to take this route. But it needs to be carefully done since it is dangerous. (With great powers comes great responsibilities). |
Beta Was this translation helpful? Give feedback.
-
It seems like we have one vote for C# right now and one for Lua, with myself being somewhere in between. But the discussion about safety made me think that maybe we should stick with Lua. While a Lua script will never have the power of a C# script, there also won't be any concerns about safety. Additionally, Lua scripts are way easier to understand by less experienced users and are more flexible in several ways. And if we add a plugin system at some point, maybe via C# scripts, plugin developers will gain the powers they lacked before. |
Beta Was this translation helpful? Give feedback.
-
Then again, what do I care about my babbling from 2001? C# it is! Yes, Lua is safe and simple, but I just can't ignore how much more powerful and flexible C# is =/ NPCs might become a tiny bit more verbose and not quite as easy to grasp at a glance for beginners, but I'm also thinking about how rarely we will write simple NPCs in the future. Once we have a solid base, we will primarily see utility scripts being written, and those benefit heavily from full access to the core and more language features. With that I'm going to close this discussion for now, until 2 years from now, when I change my mind again =) |
Beta Was this translation helpful? Give feedback.
-
When we started work on Melia, I immediately jumped at the chance to finally use a real scripting language for a server, like Lua. The reason was that, having used Ragnarok server emulators for years, I always had a soft spot for such languages. But this was an entirely subjective and kind of random choice. Lua is simple, it's fast, and designed from the ground up to be used from a host application, but I really just wanted Melia to feel a little bit more like eAthena, for nostalgia's sake. On all my other servers, I actually went a different route though.
If we are to use a scripting language, Lua is a fine choice. However, you don't necessarily need a scripting language. With .NET in particular, it's very simple to compile source code and load the assemblies at run-time. This means that you can store .cs-files in your script folder, and when the server starts, you compile them, load the assemblies, pick out the script classes, like maybe all instances of
NpcScript
, and then execute them, so they can do their thing. That might be setting up NPCs, creating quests, all the things you usually do in scripts.I have done this over multiple projects, over many years, and it works great. There is a big advantage in going this route, that has several interesting side effects: It's C#.
But of course there are also disadvantages.
print("Hello, World!")
, and you're done.I've seen users grow accustomed to C# scripting, who then went on to contributing to the core, which is pretty neat, even if the learning curve for scripting is a little higher. And it's so nice to be able to use everything that is already available in the core. Pass around characters, use core events, etc. The disadvantage of scripts not being safe could potentially be a concern, but only if Melia were to grow to a size where complete newbies might get random scripts from others and run them without a care in the world.
To me it's largely a stylistic choice. A scripting language has a certain appeal to me, and even though it means more work, I would probably keep using Lua, just because I like it. I still wanted to bring up this discussion, however, because I do think that it warrants one. There are definite advantages in using C# scripts, especially for the developers. I'm curious to hear your opinions on this topic.
Beta Was this translation helpful? Give feedback.
All reactions