Skript Functions

  • 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!

Is there a possibility to create a function without any arguments?
I meant I've already seen this.
Yeah, you just need to put an useless parameter, for example:
function test(test: int = 0):
      broadcast "test"
then you can call it without any parameters.
Might want to add a note that functions must be declared higher in the script than they are used. Many scripting languages do not have this limitation and no compiled language that I'm familiar with does. Some, like myself, will assume they can declare functions at the bottom to keep the most often edited code near the top. I spent several hours fighting a problem and even posted for help in the forums only for it to turn out to be this (moved the function declaration to the top under the options section and the problem went away).

Also how does this work when functions are intended to be called across scripts? Does skript load scripts in alphabetical order? I saw where someone had received the same error message when I was trying to find a solution to my problem. He was calling a function across scripts though. Given that declaration order matters seems like script load order would have to matter too in such cases. I may take time to test this later if no one knows.
[doublepost=1486729509,1486478467][/doublepost]I have taken time to test load order of scripts. Skript scripts are indeed loaded in alphabetical order with bensku's 2.2-dev23. And It does affect function declaration order.
A couple things to note:
  • You can't return something if your function has a wait
  • The code that called the function will wait for it to finish as long as it doesn't have a wait.
    If you don't want this, you can add
    wait 0 tick
    to the beginning of your function and it will return to the code that called it immediately