1. Welcome to skUnity!

    Welcome to skUnity! This is a forum where members of the Skript community can communicate and interact. Skript Resource Creators can post their Resources for all to see and use.

    If you haven't done so already, feel free to join our official Discord server to expand your level of interaction with the comminuty!

    Now, what are you waiting for? Join the community now!

Dismiss Notice
This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

[Concept] Addonless Object-Oriented Skript

Discussion in 'General' started by Rezz, Feb 16, 2017.

  1. Rezz

    Addon Developer

    Joined:
    Jan 24, 2017
    Messages:
    80
    Likes Received:
    37
    Medals:
    "Addonless" is only partially true, but the point is: Object-Oriented Programming is 100% possible in Skript without an addon dedicated for it. All that's required is tedious manual scripting or a Skript compiler, which is what I'm currently working on. :emoji_wink:

    My plan is to have this code:
    Code (Skript):
    1. class Test:
    2.  
    3.     method constructor():
    4.         set [this]->count to 6
    5.  
    6.     method hello(to):
    7.         send "Hello!!!" to [to]
    8.  
    9.     method count():
    10.         add 1 to [this]->count
    11.         return [this]->count
    12.  
    13. command /test:
    14.     trigger:
    15.         debug "Creating a new Test object and calling a method."
    16.  
    17.         set [object] to new Test()
    18.         [object]->hello(sender)
    19.  
    20.         loop 3 times:
    21.             set [number] to [object]->count()
    22.             set [number-variable] to [object]->count
    23.  
    24.             send "The counter has counted: %[number]% and stored it as: %[number-variable]%"
    compile into:
    Code (Skript):
    1. on script load:
    2.     registerNewClass("Test")
    3.     registerClassMethod("Test", "constructor", 0)
    4.     registerClassMethod("Test", "hello", 1)
    5.     registerClassMethod("Test", "count", 0)
    6.  
    7. sub "Test:constructor":
    8.     set {_this} to parameter 1
    9.  
    10.     set {->%{_this}%::count} to 6
    11.  
    12. sub "Test:hello":
    13.     set {_this} to parameter 1
    14.     set {_return} to parameter 2
    15.     set {_args} to parameter 3
    16.  
    17.     set {_to} to {->%{_args}%::1}
    18.  
    19.     send "Hello!!!" to {_to}
    20.  
    21. sub "Test:count":
    22.     set {_this} to parameter 1
    23.     set {_return} to parameter 2
    24.  
    25.     add 1 to {->%{_this}%::count}
    26.     set {->%{_return}%} to {->%{_this}%::count}
    27.  
    28. command /test:
    29.     trigger:
    30.         invoke "debug" from script and "Creating a new Test object and calling several methods."
    31.  
    32.         set {_object} to newInstance("Test")
    33.         invoke "Skim:Framework:construct" from {_object}
    34.      
    35.         set {_return$1} to newTemporaryAddress()
    36.         invoke "Skim:Framework:call-method" from {_object} and "hello" and {_return$1} and sender
    37.         delete({_return$1})
    38.      
    39.         loop 3 times:
    40.             set {_return$2} to newTemporaryAddress()
    41.             invoke "Skim:Framework:call-method" from {_object} and "count" and {_return$2}
    42.             set {_number} to {->%{_return$2}%}
    43.             delete({_return$2})
    44.          
    45.             set {_number-variable} to {->%{_object}%::count}
    46.          
    47.             send "The counter has counted: %{_number}% and stored it as: %{_number-variable}%"
    The "compiled" version (it was written manually :emoji_cry:) currently works as expected, but I still have to complete the compiler.

    [​IMG]

    Now, the "compiled" results look a bit funky, but let me explain.

    I've implemented a way to pass by reference (like Java) instead of pass by value (how Skript normally behaves) using global-yet-effectively-temporary variables that get deleted often. I'm abusing the fact that all Skript variables names are keys in a giant map, so I pass around variable names instead of values.

    In order to create dynamic functions, I use SkQuery subroutines. Subroutines don't offer a way to return a value, but that's quite easy to achieve: I simply pass a variable name that the subroutine should set and immediately delete it after use.
     
    #1 Rezz, Feb 16, 2017
    Last edited: Feb 16, 2017
  2. mathhulk

    mathhulk Member

    Joined:
    Jan 29, 2017
    Messages:
    55
    Likes Received:
    15
    Sadly, Skript was meant to be easily understood. Because of this, it uses very basic, almost English, syntax, which makes it impossible to create certain extensions and features. Looking at your methods and syntax, it seems that Skript is growing farther and farther away from the simplicity that it was made to be.

    Thus, I would find it harder for users to understand these methods, which is why you would need to make the syntax easily read.
     
  3. BaeFell

    BaeFell I'm Poppy
    Admin Supporter

    Joined:
    Nov 27, 2016
    Messages:
    906
    Likes Received:
    228
    I wonder if this had anything to do with my Umbaska Class idea :emoji_thinking:
     
  4. Rezz

    Addon Developer

    Joined:
    Jan 24, 2017
    Messages:
    80
    Likes Received:
    37
    Medals:
    Do you find syntax like {_this::sort::%of%::thing::*} difficult? If not, then the syntax I'm creating isn't that hard to understand.
    These are advanced features for advanced users. ¯\_(ツ)_/¯

    Nope. The oldest file in my project is from last Saturday. :emoji_stuck_out_tongue:
     
  5. mathhulk

    mathhulk Member

    Joined:
    Jan 29, 2017
    Messages:
    55
    Likes Received:
    15
    Even if they are for advanced users it loses the point for what Skript was created, modify your server without learning Java nor an IDE and what you've done here isn't even near to the Skript "style".
     
    • Agree Agree x 1
  6. Rezz

    Addon Developer

    Joined:
    Jan 24, 2017
    Messages:
    80
    Likes Received:
    37
    Medals:
    You can make that same argument for quite a few addons. Yet we still use them because they're useful tools. And you won't need an IDE for what I've created.

    I'm really surprised by how many of you are opposed to this...
    What exactly is so terribly not-skript-like about what I've done here?
     
  7. mathhulk

    mathhulk Member

    Joined:
    Jan 29, 2017
    Messages:
    55
    Likes Received:
    15
    You're growing away from what Skript is meant to be. You said above that these were advanced features for advanced users, while Skript is supposed to be for everyone. Although you are trying to make certain functions easier, you are actually creating more confusion on what Skript actually is. It isn't supposed to be a programming language or have full-on syntax, it is supposed to be literally English.
     
  8. Rezz

    Addon Developer

    Joined:
    Jan 24, 2017
    Messages:
    80
    Likes Received:
    37
    Medals:
    Skript is meant to be a scripting language for easier server customization.

    What you're failing to realize is that by creating my class syntax, I'm making something that's already possible in Skript easier for everyone. That's why this thread is called "addonless object-oriented skript" - it's 100% possible to do this right now (not with my pretty syntax yet, of course).

    What. That's just wrong.

    It's supposed to be whatever users/devs make of it. Skript is simply a tool, after all.

    Most things in Skript are English phrases, but there are also plenty of exceptions. Just look at the command syntax:
    Code (Skript):
    1. command /something <player> [<text>]
    That is not an English sentence.

    I mean, if users can handle functions...
    Code (Skript):
    1. function something(totally-not-a-sentence: text="some text") :: boolean:
    2.     return true
    ... then they can easily handle my class syntax too. :emoji_wink:
     
    #8 Rezz, Feb 18, 2017
    Last edited: Feb 18, 2017
  9. mathhulk

    mathhulk Member

    Joined:
    Jan 29, 2017
    Messages:
    55
    Likes Received:
    15
    You're just not understand my view, and I totally get that.
    I mean, it's not like my opinion is going to stop you from doing what you're doing, as it is only an opinion.
    Thanks for taking the time to make this anyways.
     
  10. Rezz

    Addon Developer

    Joined:
    Jan 24, 2017
    Messages:
    80
    Likes Received:
    37
    Medals:
    Well, I'm trying to create a syntax reader to start off with. It's really confusing and I'm only doing it for fun though...
     
  11. Rezz

    Addon Developer

    Joined:
    Jan 24, 2017
    Messages:
    80
    Likes Received:
    37
    Medals:
    Here's a tiny update on this project so far: https://gist.github.com/RezzedUp/e75847a72152871619eeec31f5700db2

    With the following files:

    [​IMG]

    projects/Test/project.yml
    Code (YAML):
    1. project:
    2.     main: main
    projects/Test/src/main.sk
    Code (Skript):
    1. #@ This comment will be removed.
    2.  
    3. @include "opposite"
    4. @include "included/hello"
    5.  
    6. #@ Content within a raw section will not be modified.
    7.  
    8. @start "raw"
    9.  
    10. on skript load:
    11.  
    12.     send "Unmodified." to console
    13.     #@ This comment will be included.
    14.  
    15. @end "raw"
    16.  
    17. command /hi:
    18.     executable by: players
    19.     permission: can.hello
    20.     trigger:
    21.         hello(sender)
    22.  
    23. command /opposite <boolean>:
    24.     trigger:
    25.         debug "Checking the opposite of '%arg-1%'"
    26.         send "%opposite(arg-1)%"
    projects/Test/src/opposite.sk
    Code (Skript):
    1. @include "okay"
    2.  
    3. function opposite(bool: boolean) :: boolean:
    4.  
    5.     if [bool]:
    6.         return false
    7.     else:
    8.         return true
    projects/Test/src/okay.sk
    Code (Skript):
    1. function okay_no_args() :: text: #include this comment #@ but exclude this one
    2.  
    3.     return "This function has no arguments. &3Okay."
    4.  
    5. on script load:
    6.  
    7.     send "%okay_no_args()%" to console
    projects/Test/src/included/hello.sk
    Code (Skript):
    1. function hello(player: player):
    2.  
    3.     send "Hello!" to {_player}

    Running /compile Test will produce:

    [​IMG]

    Code (Skript):
    1. # Test v1.0.0 compiled with Skim Compiler
    2. #@: --> start 'plugins/Skript/projects/Test/src/main.sk' @ 0
    3.  
    4. #@: --> start 'plugins/Skript/projects/Test/src/opposite.sk' @ 0
    5. #@: --> start 'plugins/Skript/projects/Test/src/okay.sk' @ 0
    6. function okay_no_args(~: boolean=true) :: text: #include this comment
    7.  
    8.     return "This function has no arguments. &3Okay."
    9.  
    10. on script load:
    11.  
    12.     send "%okay_no_args()%" to console
    13. #@: --> end 'plugins/Skript/projects/Test/src/okay.sk'
    14. #@: --> resume 'plugins/Skript/projects/Test/src/opposite.sk' @ 1
    15.  
    16. function opposite(bool: boolean) :: boolean:
    17.  
    18.     if {_bool}:
    19.         return false
    20.     else:
    21.         return true
    22. #@: --> end 'plugins/Skript/projects/Test/src/opposite.sk'
    23. #@: --> resume 'plugins/Skript/projects/Test/src/main.sk' @ 3
    24. #@: --> start 'plugins/Skript/projects/Test/src/included/hello.sk' @ 0
    25. function hello(player: player):
    26.  
    27.     send "Hello!" to {_player}
    28. #@: --> end 'plugins/Skript/projects/Test/src/included/hello.sk'
    29. #@: --> resume 'plugins/Skript/projects/Test/src/main.sk' @ 4
    30.  
    31.  
    32.  
    33. on skript load:
    34.  
    35.     send "Unmodified." to console
    36.     #@ This comment will be included.
    37.  
    38.  
    39. command /hi:
    40.     executable by: players
    41.     permission: can.hello
    42.     trigger:
    43.         hello(sender)
    44.  
    45. command /opposite <boolean>:
    46.     trigger:
    47.         send "%opposite(arg-1)%"
    48. #@: --> end 'plugins/Skript/projects/Test/src/main.sk'
    49.  

    And here's a sample of what an error looks like:
    (even though the preview above doesn't contain any)

    [​IMG]
     
    #11 Rezz, Mar 9, 2017
    Last edited: Mar 9, 2017
  12. mathhulk

    mathhulk Member

    Joined:
    Jan 29, 2017
    Messages:
    55
    Likes Received:
    15
    Wow. Isn't there some problems with debug. I mean - in Skript you debug only scripts you need but here will it going to load then unload whole class?
     
  13. MeHow

    MeHow Active Member

    Joined:
    Feb 6, 2017
    Messages:
    140
    Likes Received:
    13
    Is this project abonded?
     

Share This Page

Loading...