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!

  2. LOOKING FOR A VERSION OF SKRIPT?

    You can always check out our Wiki for downloads and any other information about Skript!

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

command to run any function

Discussion in 'Skript' started by cheatchki, Jul 27, 2017.

Thread Status:
Not open for further replies.
  1. cheatchki

    Supporter ++

    Joined:
    Jun 26, 2017
    Messages:
    49
    Likes Received:
    1
    So there is probably a SUPER easy way to do this but I want to be able to run a function in a command, this is pretty much so I can do some dev testing with a plugin I have in the works, now I know I could do like

    Code (Skript):
    1. function test(player: player):
    2.     message "example function" to {_player}
    3.  
    4. command /function <text>:
    5.     if arg-1 is "test":
    6.         test(player)
    now what I want differs from the above code in two ways

    the first,
    I want it so it will allow you to plug in the variable as well so if you were to do /function test(cheatchki) It would run the function like that

    and second,
    I want it so I don't have to define the function within the command as well so

    Code (Skript):
    1. function test(player: player):
    2.     message "example function" to {_player}
    3.  
    4. command /function <text>:
    5.     run arg-1 as a proper function?
     
  2. ShaneBee

    Moderator Resource Staff Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,184
    Likes Received:
    220
    I'm not certain this is possible. In my testing the blocking point seems to bet the function name itself. I can get it to load properly if I specify the function to be executed, but it doesn't understand the function as a variable the player can choose with the command:
    Code (Skript):
    1. function testFunction(n: number, b: text, p: player):
    2.     send "%{_n}%" to {_p}
    3.     send "%{_b}%" to {_p}
    4.  
    5. #command would look like /function testFunction 1,banana,Wynnevir              
    6. command /function <text> <text>:
    7.     trigger:
    8.         set {_functionname} to arg 1
    9.         set {_ArgumentGiven} to arg 2
    10.         set {_ArgumentList::*} to {_ArgumentGiven} split at ","
    11.         set {_size} to size of {_ArgumentList::*}
    12.         if {_size} = 3:
    13. #The problem is here with the function name variable. the argument variables
    14. #work but it can't understand a variable where the function name should be
    15.             {_functionname}({_ArgumentList::1}, {_ArgumentList::2}, {_ArgumentList::3})
    16. #Putting it in parenthesis, quotes etc also does not work
    This however will load, but defeats the point of your goal
    Code (Skript):
    1. testFunction({_ArgumentList::1}, {_ArgumentList::2}, {_ArgumentList::3})
     
  3. ShaneBee

    Moderator Resource Staff Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,184
    Likes Received:
    220
    Perhaps using MundoSK's codeblock expressions may be of use. I personally don't know much about them myself.

    Code (Skript):
    1.  
    2. function test(p: player, t: text) :: text:
    3.     message "%{_t}%" to {_p}
    4.  
    5. command /function <text> <player> <text>:
    6.     trigger:
    7.         set {_function} to codeblock of function "%arg 1%"
    8.         run codeblock {_function} with arg 2, arg 3
    9.  
     
Thread Status:
Not open for further replies.

Share This Page

Loading...